So here's my problem in a nut shell:
I'm trying to get the info that is in my HTML form to my phpmyadmin database.The criteria to do so is to send the form values to a javascript function which collects the values and sends it to my php file.
As it stands right now, with my HTML I can call the Javascript function that form validates and that loads my php page. So far I've only been able to add empty values into my database. Everything gets added fine if I just do a form action that sends right to my php.
So I'm wondering if anyone knows what I can do to make this javascript function work?
Heres my HTML form:
My Javascript function etc.(not working with the top variables and xml load) as is:
My PHP:
I'm trying to get the info that is in my HTML form to my phpmyadmin database.The criteria to do so is to send the form values to a javascript function which collects the values and sends it to my php file.
As it stands right now, with my HTML I can call the Javascript function that form validates and that loads my php page. So far I've only been able to add empty values into my database. Everything gets added fine if I just do a form action that sends right to my php.
So I'm wondering if anyone knows what I can do to make this javascript function work?
Heres my HTML form:
HTML:
<form method="post" name="addcard" >
<p><b>Name:</b>
<input type="text" name="name" id="name"/>
</p>
<p>
<b>Brand:</b>
<select name="brand" id="brand">
<option value="1">Donruss</option>
<option value="2">O'Pee-Chee</option>
<option value="3">Topps</option>
<option value="4">Fleer</option>
<option value="5">Upperdeck</option>
<option value="6">Pacific</option>
<option value="7">Parkhurst</option>
</select>
</p>
<p><b>Year:</b>
<select name="year" id="year">
<option value="1">1988</option>
<option value="2">1989</option>
<option value="3">1990</option>
<option value="4">1991</option>
<option value="5">1992</option>
<option value="6">1993</option>
<option value="7">1994</option>
<option value="8">1995</option>
<option value="9">1996</option>
</select>
</p>
<b>Stock:</b>
<input type="text" name="stock" id="stock"/>
<p>
<input type="submit" value="Add Card" onclick="add_card()"/>
</p>
</form>
My Javascript function etc.(not working with the top variables and xml load) as is:
Code:
var name = document.getElementById("name").value;
var brand = document.getElementById("brand").value;
var year = document.getElementById("year").value;
var stock = document.getElementById("stock").value;
function add_card(name,brand,year,stock)
{
var player_name = document.addcard.name;
var card_brand = document.addcard.brand;
var card_year = document.addcard.year;
var card_stock = document.addcard.stock;
if (player_name.value == "")
{
window.alert("Please enter a Name.");
name.focus();
return false;
}
if (card_brand.value == "")
{
brand.focus();
return false;
}
if (card_year.value == "")
{
year.focus();
return false;
}
if (card_stock.value == "")
{
window.alert("Please provide a Stock number.");
stock.focus();
return false;
}
else
{
xmlDoc.load("insert.php?name="+name+"&brand="+brand+"&year="+year+"&stock="+stock);
return true;
}
}
My PHP:
Code:
<?php
mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("all_Pro");
$select="INSERT INTO card (name, brand_id_fk, year_id_fk)
VALUES
('$_POST[name]','$_POST[brand]','$_POST[year]')
";
$stock="INSERT INTO stocks (stock_num)
VALUES
('$_POST[stock]')
";
$result_card = mysql_query($select) or die(mysql_error());
$result_stock = mysql_query($stock) or die(mysql_error());
?>