Welcome to WebmasterWorld Guest from 23.20.147.6

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Mysql INSERT not working

INSERT query to database not working

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

New User

joined:June 18, 2014
posts: 4
votes: 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.

[code]<?php
mysql_connect('SERVER','USER NAME','PASSWORD');
mysql_select_db('pumas');

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

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

echo mysql_error($query);

?>[/code]

Any help or input will be appreciated :).
2:08 pm on June 18, 2014 (gmt 0)

Senior Member

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2006
posts: 3123
votes: 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:
'Andreas'
2:17 pm on June 18, 2014 (gmt 0)

New User

joined:June 18, 2014
posts: 4
votes: 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 June 18, 2014 (gmt 0)

Senior Member

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2006
posts: 3123
votes: 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 June 18, 2014 (gmt 0)

New User

joined:June 18, 2014
posts: 4
votes: 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 June 18, 2014 (gmt 0)

Senior Member

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2006
posts: 3123
votes: 0


Do you have INSERT perms on the table in question?

Perhaps you can repost your current/corrected code snippet?
9:34 am on June 19, 2014 (gmt 0)

New User

joined:June 18, 2014
posts: 4
votes: 0


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

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members