Hello Friends,I need little help with Xampp.I had updated Xampp but when I worked with PHP & Mysql with Xampp then it shows error.Like I had created 1 form which will insert data in Database but it shows : "Error: 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 'div, stan) VALUES ('sonu','1','A','12')' at line 1 " I don't know why this error are seen.I had already worked on Xampp & also create a same form insert into DB successfully but when I formatted my pc it is suddenly showing this error. <?php $con = mysql_connect("localhost","root","root123"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("main", $con); $sql="INSERT INTO infos (name, rollno, div, stan) VALUES ('$_POST[name]','$_POST[rollno]','$_POST[div]','$_POST[stan]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con) ?> PHP: Please Help me....
Your problem is here: $sql="INSERT INTO infos (name, rollno, div, stan) VALUES ('$_POST[name]','$_POST[rollno]','$_POST[div]','$_POST[stan]')"; PHP: Replace this with this one and try again: $sql="INSERT INTO infos (name, rollno, div, stan) VALUES ('".$_POST["name"]."','".$_POST["rollno"]."','".$_POST["div"]".','".$_POST["stan"]."')"; PHP:
Chances are you use reserved words in your table or field names, maybe div or name Try to change your table names OR use the ` (<- don't know its name) "INSERT INTO `infos` (`name`, `rollno`, `div`, `stan`) VALUES ($_POST['name'], $_POST['rollno'], $_POST['div'], $_POST['stan'])" PS: NEVER EVER use an input directly in a query. Google SQL injection to learn more about it.
Thanks,but it shows error. "Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING" Thanks for help...