|
Posted by Jerry Stuckle on 02/11/07 14:20
zek2005 wrote:
> I have a problem with an insert. The connection to DB works fine and I
> receive an OK when the PHP process but nothing is inserted in the DB.
> I added an echo of mysql_affected_rows and the result is -1. That's
> why I get an OK?
>
> $query="INSERT INTO preguntas (pregunta, id_usuario, fecha) VALUES
> ('$pregunta','$id',current_date)";
> $result=mysql_db_query($database,$query,$link);
> if(mysql_affected_rows($link))
> {
> echo "OK";
> }
> else
> {
> echo "Nothing inserted";
> }
>
> Thanks for your help
>
> Ezequiel
>
First of all, mysql_db_query was deprecated in PHP Version 4.0.5 and
should not be used. See the doc for more info.
And, just like in your previous question, you aren't checking the result
of the query. Did it work or not? You'll either get a resource back or
FALSE. In the former case it worked. In the latter case it didn't.
ALWAYS check the result of a MySQL call. If it fails, use mysql_error()
to display the error message.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
[Back to original message]
|