Welcome to WebmasterWorld Guest from 54.196.144.100

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Mysql INSERT not working

INSERT query to database not working

     

Shorty

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.

[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 :).

penders

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

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



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'

Shorty

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.

penders

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

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



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.

Shorty

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 ?

penders

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

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



Do you have INSERT perms on the table in question?

Perhaps you can repost your current/corrected code snippet?

Shorty

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 !