spluskhan Posted March 6, 2013 Share Posted March 6, 2013 Parse error: syntax error, unexpected '.', expecting ']' in /home/pk.co.pk/uk.pko/insert.php on line 125 ++++++++++ inser.php +++++++++ <?php $con=mysqli_connect("exapmle.com","user","pass","d atabase"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql="INSERT INTO Products (name, available_conditions, v.good, good, poor, faulty) VALUES ('$_POST[name]','$_POST[available_conditions]','$_POST[v.good]','$_POST[good]','$_POST[poor]','$_POST[faulty]')"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error()); } echo "1 record added"; mysqli_close($con); ?> ++++++++++++++++++++++++++++++++++++++ And Here is the form: +++++++++++++++++++++++++++++++++++++++ <div id="wb_Form1" style="position:absolute;width:361px;height:270px;"> <form name="Add_New_Items" method="post" action="insert.php" enctype="text/plain" id="Form1"> <div id="wb_Text1" style="position:absolute;left:10px;top:15px;width:121px;height:16px;z-index:30;text-align:left;"> <span style="color:#000000;font-family:Arial;font-size:13px;">name:</span></div> <input type="text" id="Editbox1" style="position:absolute;left:141px;top:15px;width:198px;height:23px;line-height:23px;z-index:31;" name="Editbox1" value=""> <div id="wb_Text2" style="position:absolute;left:10px;top:45px;width:121px;height:32px;z-index:32;text-align:left;"> <span style="color:#000000;font-family:Arial;font-size:13px;">available_conditions:</span></div> <input type="text" id="Editbox2" style="position:absolute;left:141px;top:45px;width:198px;height:23px;line-height:23px;z-index:33;" name="Editbox2" value=""> <div id="wb_Text3" style="position:absolute;left:10px;top:75px;width:121px;height:16px;z-index:34;text-align:left;"> <span style="color:#000000;font-family:Arial;font-size:13px;">v.good:</span></div> <input type="text" id="Editbox3" style="position:absolute;left:141px;top:75px;width:198px;height:23px;line-height:23px;z-index:35;" name="Editbox3" value=""> <div id="wb_Text4" style="position:absolute;left:10px;top:105px;width:121px;height:16px;z-index:36;text-align:left;"> <span style="color:#000000;font-family:Arial;font-size:13px;">good:</span></div> <input type="text" id="Editbox4" style="position:absolute;left:141px;top:105px;width:198px;height:23px;line-height:23px;z-index:37;" name="Editbox4" value=""> <div id="wb_Text5" style="position:absolute;left:10px;top:135px;width:121px;height:16px;z-index:38;text-align:left;"> <span style="color:#000000;font-family:Arial;font-size:13px;">poor:</span></div> <input type="text" id="Editbox5" style="position:absolute;left:141px;top:135px;width:198px;height:23px;line-height:23px;z-index:39;" name="Editbox5" value=""> <div id="wb_Text7" style="position:absolute;left:10px;top:165px;width:121px;height:16px;z-index:40;text-align:left;"> <span style="color:#000000;font-family:Arial;font-size:13px;">faulty:</span></div> <input type="text" id="Editbox6" style="position:absolute;left:141px;top:165px;width:198px;height:23px;line-height:23px;z-index:41;" name="Editbox6" value=""> <input type="submit" id="Button1" name="" value="Submit" style="position:absolute;left:141px;top:195px;width:96px;height:25px;z-index:42;"> <input type="reset" id="Button2" name="" value="Reset" style="position:absolute;left:141px;top:225px;width:96px;height:25px;z-index:43;"> </form> </div> Quote Link to comment https://forums.phpfreaks.com/topic/275324-i-have-a-an-error-on-this-script/ Share on other sites More sharing options...
rgopal101 Posted March 6, 2013 Share Posted March 6, 2013 send complete inser.php Quote Link to comment https://forums.phpfreaks.com/topic/275324-i-have-a-an-error-on-this-script/#findComment-1416959 Share on other sites More sharing options...
spluskhan Posted March 6, 2013 Author Share Posted March 6, 2013 <?php $con=mysqli_connect("exapmle.com","user","pass","d atabase"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql="INSERT INTO Products (name, available_conditions, v.good, good, poor, faulty) VALUES ('$_POST[name]','$_POST[available_conditions]','$_POST[v.good]','$_POST[good]','$_POST[poor]','$_POST[faulty]')"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error()); } echo "1 record added"; mysqli_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/275324-i-have-a-an-error-on-this-script/#findComment-1416968 Share on other sites More sharing options...
Jessica Posted March 6, 2013 Share Posted March 6, 2013 You shouldn't use . within a column name. You also can't use it as part of a string without quoting your strings. All of those array keys should be strings with quotes. Quote Link to comment https://forums.phpfreaks.com/topic/275324-i-have-a-an-error-on-this-script/#findComment-1416982 Share on other sites More sharing options...
spluskhan Posted March 7, 2013 Author Share Posted March 7, 2013 Give me example Quote Link to comment https://forums.phpfreaks.com/topic/275324-i-have-a-an-error-on-this-script/#findComment-1417129 Share on other sites More sharing options...
cyberRobot Posted March 7, 2013 Share Posted March 7, 2013 If an identifier contains special characters or is a reserved word, you must quote it whenever you refer to it. Note that the dot being used in some of the column names (v.good) is a special character. More information can be found here: http://dev.mysql.com/doc/refman/5.0/en/identifiers.html Quote Link to comment https://forums.phpfreaks.com/topic/275324-i-have-a-an-error-on-this-script/#findComment-1417218 Share on other sites More sharing options...
Jessica Posted March 7, 2013 Share Posted March 7, 2013 You also need to learn about sanitizing user input. Quote Link to comment https://forums.phpfreaks.com/topic/275324-i-have-a-an-error-on-this-script/#findComment-1417223 Share on other sites More sharing options...
DavidAM Posted March 7, 2013 Share Posted March 7, 2013 turn on error reporting, you're getting notices about those unquoted array keys error_reporting(~0); ini_set('display_errors', true); Quote Link to comment https://forums.phpfreaks.com/topic/275324-i-have-a-an-error-on-this-script/#findComment-1417246 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.