Forum Moderators: coopster
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')";
?>
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.
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.