I am trying to add new records into my database via php but I can not get it to work. I Triple checked all my values, the correct table/row names but still not working. Perhaps a second pair of eyes can see my issue.
Here is my form...
<form action="" method="POST">
<table cellpadding="5" cellspacing="2" border="0">
<?php
echo '<textarea name="addname" cols="20" rows="1">Enter new name</textarea>';
echo '<textarea name="adddescription" cols="110" rows="5">Enter new Description</textarea>';
echo '<textarea name="addpagetitle" cols="100" rows="3">Enter new Page Title</textarea>';
echo '<textarea name="addpagetags" cols="100" rows="2">Enter new Page Tags</textarea>';
echo '<textarea name="addmetadescription" cols="100" rows="5">Enter new Meta Description</textarea>';
?>
</table>
</form>
Here us my button...
<input type="hidden" name="addedit" value="" />
<input type="submit" value="add" name="add" style="background:#e5f9bb; cursor:pointer; cursor:hand;" />
Here is my function for adding new record.
if (isset($_POST['add'])){
$newname = $_POST['addname'];
$newdescription = $_POST['adddescription'];
$newpagetitle = $_POST['addpagetitle'];
$newmetakey = $_POST['addpagetags'];
$newmetadescription = $_POST['addmetadescription'];
//adds new destination and info...
mysql_query("INSERT INTO destination(name, description, page_title, page_tags, page_description_tag) VALUES ('$newname',' $newdescription','$newpagetitle','$newmetakey','$newmetadescription')");
}
Also I wanted to double check that If when added, does sql assign the new record a primary key which in my case would be IDDestination. Or do I need to code that in myself? which could be my problem. Thanks!
Try change your query to this:
mysql_query("INSERT INTO destination(name, description, page_title, page_tags, page_description_tag) VALUES ('". $newname ."','". $newdescription ."','". $newpagetitle ."','". $newmetakey ."','". $newmetadescription ."')");
For your primary key you can use auto increment (sorry, may be I bad understand your last question)
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.