homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Mysql INSERT not working
INSERT query to database not working

 6:34 am on Jun 18, 2014 (gmt 0)
Hi All

Im having a problem when trying to submit data using MySQL INSERT Query to my Database. I have tried using mysql_error() to determine the problem but it returns empty.
First I thought it was a Database connection problem but I'm having no trouble getting the Data from the Database on the server.

Here is the code that im using to test.

mysql_connect('SERVER','USER NAME','PASSWORD');

$query = mysqli_query("INSERT INTO `test`(`name`) VALUES (Andreas)");

if($query){echo 'INSERT Working';} else { echo 'INSERT Not Working';}

echo mysql_error($query);


Any help or input will be appreciated :).



 2:08 pm on Jun 18, 2014 (gmt 0)

You are mixing two different PHP database exentions... mysql (deprecated) and mysqli (note the extra "i" for "improved"). You should be using mysqli throughout.

You are also missing single quotes around your string value:

 2:17 pm on Jun 18, 2014 (gmt 0)

TNX , I have changed all the extensions to mysqli and added the single quotes to input value. I dont know if this might be the issue but the server is still running an old window server 2008.


 2:46 pm on Jun 18, 2014 (gmt 0)

Note also that mysqli_query() requires the link identifier as the first argument. (This is different to the old mysql_query() function).

The fact you are running Windows Server 2008 shouldn't make any difference. It's the version of PHP and MySQL that matter.


 4:52 pm on Jun 18, 2014 (gmt 0)

I have tried all the other Queries from CREATING a new table using mysql to SELECTING data from the Database and that all seems to be working fine its is really just the INSERT Query that is not working like it should be and I have tried using mysqli and mysql and still no progress, don't know if it is just me then is really bad at this or could it be something out of the ordinary ?


 9:13 pm on Jun 18, 2014 (gmt 0)

Do you have INSERT perms on the table in question?

Perhaps you can repost your current/corrected code snippet?


 9:34 am on Jun 19, 2014 (gmt 0)

Victory :) Thanks Penders it did end up as a INSERT permissions issue and all is working now. Thanks again for all your help !

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved