this question is in relation to an earlier question about an "undefined index error message". Here is the link to the first question:
http://www.devnetwork.net/viewtopic.php ... 2ab8768cfe
This is my original code:
Code: Select all
<?php
if (count($_POST)>0 && isset($_POST['sname']) && isset($_POST['fname'])) {
// FORM WAS SUBMITTED
$SQL = 'INSERT INTO `Contracts` (`Surname`,`Firstname`) VALUES (';
$SQL .= '"'.mysql_real_escape_string($_POST['sname']).'",';
$SQL .= '"'.mysql_real_escape_string($_POST['fname']).'")';
mysql_query($SQL)
or die ('ERR: Could not write data. '.mysql_error());
}
Code: Select all
if (count($_POST)>0 && isset($_POST['sname']) && isset($_POST['fname']) && isset($_POST['nname'])) {
// FORM WAS SUBMITTED
$SQL = 'INSERT INTO `Contracts` (`Surname`,`Firstname`, `Nickname`) VALUES (';
$SQL .= '"'.mysql_real_escape_string($_POST['sname']).'",';
$SQL .= '"'.mysql_real_escape_string($_POST['fname']).'")';
$SQL .= '"'.mysql_real_escape_string($_POST['nname']).'")';
mysql_query($SQL)
or die ('ERR: Could not write data. '.mysql_error());
}
where the above "sss" is the field from my form with "nname". Please note, in my table, the field Nickname is a VARCHAR just like sname and fname.ERR: Could not write data. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"sss")' at line 1
2) Why is it that on some tutorials online, sometimes, this:
Code: Select all
INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)
Code: Select all
INSERT INTO 'table_name' ('column1', 'column2', 'column3')
VALUES ('value1', 'value2', 'value3')