Jump to content

cant insert into mysql with php


ala888

Recommended Posts

$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

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

$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

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

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 by ala888
Link to comment
Share on other sites

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 right

It 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...