简体   繁体   中英

Submit form wont submit data to database

I've been trying all night to get this done and have no luck whatsoever. For some reason the form submits, but the data doesn't get sent to the database. Heres the PHP portion

<?php 

mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");
if ( isset ( $_POST['Submit'] ) ) //If submit is hit
{
   $name = $_POST['name'];  
   $category = $_POST['category'];  
   $class = $_POST['class'];  
   $level = $_POST['level'];  
   $bind = $_POST['bind'];  
   $tier = $_POST['tier'];  
   $trade = $_POST['trade'];  
   $ilvl = $_POST['ilvl'];  
   $amod = $_POST['amod'];  
   $xdmg = $_POST['xdmg'];  
   $description = $_POST['description'];  
   $description2 = $_POST['description2'];  
   $description3 = $_POST['description3'];  
   $sprice = $_POST['sprice'];  
   $bprice = $_POST['bprice'];  
   $percent = $_POST['percent'];  
   $source = $_POST['source'];  
   $tnail = $_POST['tnail'];  
   $result=MYSQL_QUERY("INSERT INTO items (name, category, class, level, bind, tier, trade, ilvl, amod, xdmg, description, description2, description3, sprice, bprice, percent, source, tnail)".
   "VALUES ( '$name', '$category', '$class', '$level', '$bind', '$tier', '$trade', '$ilvl', '$amod', '$xdmg', '$description', '$description2', '$description3', '$sprice', '$bprice', '$percent', '$source', '$tnail' )")or die( "<p><span style=\"color: red;\">Unable to select table</span></p>");
   mysql_close();
   //confirm
   echo "<p><span style=\"color: red;\">Thank You; the items have been entered in the database. DO NOT REFRESH THE PAGE or data will be sent again.</span></p>"; 
}
else
{
   // close php so we can put in our code
?>

Any help?

尝试关闭您的字段名称,例如(`name`,`category` ...等。

Place the following code anywhere after calling mysql_query() .

echo mysql_error();

It will show you if anything is wrong with your query or database credentials.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM