ala888 Posted July 10, 2014 Share Posted July 10, 2014 $con = mysqli_connect("localhost","root","123456","test");$SQL = "INSERT INTO info (PATH, TITLE, DESC)VALUES ('HI','HELLO','HAI')";$con->query($SQL) or die("ERRORRRRRRR");//dies every time idk WHAT Im doing wrong. tried every method of troubleshooting. HELP! Link to comment Share on other sites More sharing options...
Don Jajo Posted July 10, 2014 Share Posted July 10, 2014 Because you initiated MySQL connection with MySQLi procedural method and you tried executing the query with OOP method that is why it keeps dying Let your $con be <?php $con = new MySQLi('db_host','db_dbuser','db_pwd','db_name');?> or let your query execution be procedural <?phpmysqli_query($con,$SQL) or die('error');?> Link to comment Share on other sites More sharing options...
ala888 Posted July 10, 2014 Author Share Posted July 10, 2014 $con = mysqli_connect("localhost","root","asdsasds","test"); $SQL = " INSERT INTO info (PATH, TITLE, DESC) VALUES ('HI','HELLO','HAI') "; mysqli_query($con,$SQL) or die("######"); NURP, STILL DISPLAYING THEM ERROR MESSAGES Link to comment Share on other sites More sharing options...
justsomeguy Posted July 10, 2014 Share Posted July 10, 2014 If mysqli_query is returning false, then use mysqli_error to figure out why.http://www.php.net/manual/en/mysqli.error.phpYou're also not checking if mysqli_connect succeeded, you should do that also. The manual has examples.In this case, it looks to me like you're using keywords as field names. Look at the error message from MySQL to figure out which ones. Link to comment Share on other sites More sharing options...
ala888 Posted July 10, 2014 Author Share Posted July 10, 2014 (edited) connect already succeeded 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 'DESC) VALUES ('HI','HELLO','HAI')' at line 1 what does this mean? pretty sure syntax is right Edited July 10, 2014 by ala888 Link to comment Share on other sites More sharing options...
justsomeguy Posted July 10, 2014 Share Posted July 10, 2014 How do you know it succeeded unless you're checking for errors? Note the examples.http://www.php.net/manual/en/mysqli.construct.phpAssuming that things are working doesn't help when you're trying to debug. what does this mean? pretty sure syntax is rightIt shows the error at the word "desc". Desc is a reserved word in MySQL. If you want to use reserved words as table or field names then you need to surround them with backticks.http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now