Welcome to WebmasterWorld Guest from 54.224.13.210

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP and mySQL Insert problem

     
3:05 pm on May 31, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Dec 6, 2001
posts:2213
votes: 0


Hello

I know i am connecting to the DB, as i have run a script to check.

On one page a pass form variables to another page. The variable pass ok as i
print them out to make sure. I have an SQL instert which I cannot get to
work. Any ideas appreciated.

CODE

<?php
$sql = "INSERT INTO MMUser (UserPrivilege,
UserUsername,
UserPassword,
UserName,
UserEmail,
UserPhone)
VALUES ('$UserPrivilege',
'$UserUsername',
'$UserPassword',
'$UserName',
'$UserEmail',
'$UserPhone')";
?>

4:11 pm on May 31, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Feb 4, 2002
posts:5044
votes: 0


Try this:
$sql = "INSERT INTO MMUser VALUES(UserPrivilege,
UserUsername, etc

Nick

4:16 pm on May 31, 2002 (gmt 0)

Senior Member from US 

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

joined:Mar 31, 2002
posts:7575
votes: 0


Make sure your the letter case of the field names in your query match those in your db.
4:30 pm on May 31, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 6, 2002
posts:1092
votes: 0


Did you figure it out? Must be letter case because your query is well formatted.
5:49 pm on May 31, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Dec 6, 2001
posts:2213
votes: 0


Thanks for the answers.

Unfortunately I will be unable to try it out for 10 days as i got a holiday. Still sad enough to check if I have any responses from home though.
:-)

Cheers

7:02 pm on May 31, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Feb 4, 2002
posts:5044
votes: 0


I think I speak for everyone when I say:

Sheeeeeeesh!

:(:(:(:(:(:(:(:(

9:03 am on June 1, 2002 (gmt 0)

Junior Member

10+ Year Member

joined:Dec 28, 2001
posts:97
votes: 0


ukgimp,

Do you have the error message from the mysql function call? Usually the error messages are quite verbose, and they help the development quite a lot.

Another cause I can think of is escaping the invalid characters in the SQL statement, since you basically put the variables straight into the SQL statement. Some character, especially the single quote (') should not be used because it is in conflict with the single quote around the string. You might need to replace it with two single quotes ('') to escape it. I'll suggest you to consider using PEAR or ADODB, which supports parameters in the SQL statement, and that really makes things easier and more portable.

4:55 pm on June 1, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Dec 6, 2001
posts:2213
votes: 0


Scotty

I dont actually get an error. The parameters are passed ok, but are just not inserted.

I will look into the " and ''s and inform on my findings.

Nick - Sorry mate, what can I say or do. :-)

6:12 pm on June 1, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Feb 4, 2002
posts:5044
votes: 0


hehe, don't worry I'm just a grumpy old bugger.

Try running that query from the command line in MySQL

Nick

7:10 pm on June 1, 2002 (gmt 0)

Senior Member from US 

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

joined:Mar 31, 2002
posts:7575
votes: 0


I dont actually get an error.

You won't see the error without asking for it - unless it's a fatal error. Put this code immediately following your query.

echo "the db error is: ".mysql_error($sql);

This will return any error the SQL statement incurred while executing so you can see them. I put some text before the error "the db error is..." just so I know the command executed fine.

8:51 am on June 10, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Dec 6, 2001
posts:2213
votes: 0


THE SOLUTION

It appears i missed out a couple of bits of code

<$pResult=mysql_query( $sql , $db_connection );>
Which I am reliably informed sends the query to MySQL.

There was also a numerical auto increment field that was messing things up during my insert script.

Thanks all for your help.

Richard

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members