Have a problem that I'm not sure how to tackle yet.
So here is the dilemma: I'm inserting hockey cards into my database. What I want to do for example is say I enter 'Wayne' 'Gretzky' '1986' and my stock number is '4'.Then I enter it again but change the stock number to '6', I don't want it to insert a duplicate card. I want it to just keep one card and have the stock number change to 6.
So heres my form:
Then the form goes to my Javascript function:
Then the values go to my php:
So here is the dilemma: I'm inserting hockey cards into my database. What I want to do for example is say I enter 'Wayne' 'Gretzky' '1986' and my stock number is '4'.Then I enter it again but change the stock number to '6', I don't want it to insert a duplicate card. I want it to just keep one card and have the stock number change to 6.
So heres my form:
HTML:
<body>
<div id="add_back">
<blockquote>
<blockquote>
<p> </p>
<p> </p>
</blockquote>
</blockquote>
<form method="post" name="addcard" >
<blockquote>
<blockquote>
<p><b>First Name:</b>
<input type="text" name="name" id="name"/>
</p>
<p><b>Last Name:</b>
<input type="text" name="name2" id="name2"/>
</p>
<p>
<b>Brand:</b>
<select name="brand" id="brand">
<option value="0">Pick a Brand</option>
<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">Upper-Deck</option>
<option value="6">Pacific</option>
<option value="7">Parkhurst</option>
</select>
</p>
<p><b>Year:</b>
<input type="text" name="year" id="year"/>
</p>
<p><b>Stock:</b>
<input type="text" name="stock" id="stock"/>
</p>
<p>
<input type="submit" value="Add Card" onclick="add_card()"/>
</p>
</blockquote>
</blockquote>
</form>
</div>
</body>
Then the form goes to my Javascript function:
Code:
function add_card(new_card,new_added)
{
var first_name = document.addcard.name;
var last_name = document.addcard.name2;
var card_brand = document.addcard.brand;
var card_year = document.addcard.year;
var card_stock = document.addcard.stock;
if (first_name.value == "")
{
window.alert("Please enter a First Name.");
first_name.focus();
return false;
}
if (last_name.value == "")
{
window.alert("Please enter a Last Name.");
last_name.focus();
return false;
}
if (card_brand.value == 0)
{
window.alert("Please provide a Brand.");
brand.focus();
return false;
}
if (card_year.value == "")
{
window.alert("Please provide a Year.");
year.focus();
return false;
}
if (card_stock.value == "")
{
window.alert("Please provide a Stock number.");
stock.focus();
return false;
}
else
{
if(new_card == new_added)
{
var name = document.getElementById("name").value;
var name2 = document.getElementById("name2").value;
var brand = document.getElementById("brand").value;
var year = document.getElementById("year").value;
var stock = document.getElementById("stock").value;
if(new_card == new_added)
{
xmlDoc.load("scripts/insert.php?name="+name+"&name2="+name2+"&brand="+brand+"&year="+year+"&stock="+stock);
alert("New Card Added");
}
}
}
}
Then the values go to my php:
Code:
$select="INSERT INTO card (first_name,last_name,brand_id_fk,year)
VALUES
('$_GET[name]','$_GET[name2]','$_GET[brand]','$_GET[year]')
";
$result_card = mysql_query($select) or die(mysql_error());
$id= mysql_insert_id();
$stock="INSERT INTO stocks (card_id_fk,stock_num)
VALUES
($id,'$_GET[stock]')
";
$result_stock = mysql_query($stock) or die(mysql_error());