Jump to content

Upserts


elindithas

Recommended Posts

hiya again, I have a form set to upload info to my database, all laid out working well etc, I know basically how to do an upsert but im getting lost on actually where to punch in the code, also this script is giving me an error on submit, even tho its updating my info

 

what i want is if the name is the same to update the stock value +whatever they add for stock, instead of making a new entry to just update the row

 

<?php

$Name = $_POST['Name'];
$Color = $_POST['Color'];
$Type = $_POST['Type'];
$Rarity = $_POST['Rarity'];
$Price = $_POST['Price'];
$Stock = $_POST['Stock'];
$Added = $_POST['Added'];
$Added = $_POST['Foil'];
$Added = $_POST['Buy'];
$Added = $_POST['Buyprice'];
$submit = $_POST['submit'];

mysql_connect ("localhost", "jmartens", "jason23") or die ('Error: ' . mysql_error());
mysql_select_db ("mtgshack");


$query="INSERT INTO m10 (ID, Name, Color, Type, Rarity, Price, Stock, Added, Foil, Buy, Buyprice)VALUES ('NULL', '".$Name."', '".$Color."', '".$Type."', '".$Rarity."', '".$Price."', '".$Stock."', '".$Added."', '".$Foil."', '".$Buy."', '".$Buyprice."')";


mysql_query($query) or die ('Error updating database');

echo "Database Updated With " .$Name. " " .$Color. " " .$Type. " " .$Rarity. " " .$Price. " " .$Stock. " " .$Added. " " .$Foil. " " .$Buy. " " .$Buyprice ;

?>

 

 

the error im getting is

 

Notice: Undefined index: submit in C:\wamp\www\website\update.php on line 13

 

Notice: Undefined variable: Foil in C:\wamp\www\website\update.php on line 19

 

Notice: Undefined variable: Buy in C:\wamp\www\website\update.php on line 19

 

Notice: Undefined variable: Buyprice in C:\wamp\www\website\update.php on line 19

 

Notice: Undefined variable: Foil in C:\wamp\www\website\update.php on line 24

 

Notice: Undefined variable: Buy in C:\wamp\www\website\update.php on line 24

 

Notice: Undefined variable: Buyprice in C:\wamp\www\website\update.php on line 24

 

is it my php setup? or am i missing something?

Link to comment
https://forums.phpfreaks.com/topic/168643-upserts/
Share on other sites

You're assigning the same variable to 4 different $_POSTs.

 

$Added = $_POST['Added'];
$Added = $_POST['Foil'];
$Added = $_POST['Buy'];
$Added = $_POST['Buyprice'];

 

Should be:

 

$Added = $_POST['Added'];
$Foil = $_POST['Foil'];
$Buy = $_POST['Buy'];
$Buyprice = $_POST['Buyprice'];

Link to comment
https://forums.phpfreaks.com/topic/168643-upserts/#findComment-889646
Share on other sites

oops, that was a stupid mistake

 

the one ive been getting all along is

 

Notice: Undefined index: submit in C:\wamp\www\website\update.php on line 13

 

 

nm, fixed that too, was a capital S somwhere

 

just need to work out this update thing now

 

actually i need it to check the name and the foil status, and if its the same to update the stock for the difference

Link to comment
https://forums.phpfreaks.com/topic/168643-upserts/#findComment-889672
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.