|
Posted by Tim Martin on 04/18/06 11:45
Anthony wrote:
> Hello Everyone,
>
> I have been working with a piece of code for the past few hours that I
> just can't seem to get working. I'm hoping someone here can help me
> find the bug. Basically, the code is supposed to take all the data
> entered into a forms fields, stripslashes() it then insert it into the
> database. Pretty straightforward. The only thing that is unique is
> that I am checking if a particular field is blank then allowing the
> program to auto-assign a number to the field if it is. Still. pretty
> straightforward.
>
> What's happening, however, is that the information is never being
> entered into the database. When I echo the sql statement being
> constructed back it looks right. But I am sure there is a problem
> somewhere. Can anyone help me find it? I will pay you $10 via paypal if
> you can help me here. The code is below.
> $sql = "INSERT INTO clients(' ', '$fname', '$minit', '$lname',
> '$ssn', '$phone', '$cdate', '$cnum'";
I can't see a matching close bracket on that statement.
Also, you should be doing either
INSERT INTO clients (field1, field2, field3, ...) VALUES (' ', '$fname',
'$minit', ...)
or
INSERT INTO clients VALUES (' ', '$fname', '$minit', ...)
i.e. the values want to go in a list after the VALUES keyword.
> echo $sql;
> //exit;
> mysql_query($sql);
> echo "<font size=\"+1\"><b>ACCOUNT CREATED</b></font><br>";
> echo "The new account for ".$fname." ".$minit." ".$lname." has been
> successfully created.";
> exit;
Note that you're ignoring the error status here. Check the return value
of mysql_query() to determine whether an error occurred, and if so echo
the result of mysql_error(). Had you done this you'd probably have
realised you had a syntax error in your SQL.
Tim
[Back to original message]
|