I cannot add data to a database This is the code im using <?php $con = mysql_connect("localhost","db","pass"); if (!$con) { die('Could not connect: ' . mysql_error()); echo "could not connect"; } else { echo "connected"; } @mysql_select_db("db", $con); mysql_query("INSERT INTO Prods (Product_ID, Department, Name, Prod_code, Description, Picture, Price, Stock, Prod_Type) VALUES (null, varA, varB, varC, varD, varE, varF, VarG, varH);"); mysql_close($con); ?> Any ideas? Thanks
what is varA, B, C, etc.? even if they're variables they should be $varA, $varB. and if they're text they should be in single quotes.
ya your right thanks they are variables but even with $ in front of them,nothing is entering the database and no errors are showing either
Take out the semicolon in the query and do this: $sql = "INSERT INTO Prods (Product_ID, Department, Name, Prod_code, Description, Picture, Price, Stock, Prod_Type) VALUES (null, '". $varA ."', '". $varB ."', '". $varC ."', '". $varD ."', '". $varE ."', '". $varF ."', '". $VarG ."', '". $varH ."')"; echo $sql; mysql_query($sql); Code (markup): Then see what it echos
mysql_query("INSERT INTO Prods (`Product_ID`,` Department`, `Name`, `Prod_code`, `Description`, `Picture`, `Price`, `Stock`, `Prod_Type`) VALUES (null, 'varA', 'varB', 'varC', 'varD', 'varE', 'varF', 'VarG', 'varH')"); Try This