467,198 Members | 1,207 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,198 developers. It's quick & easy.

Problem with insert

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

Feb 11 '07 #1
  • viewed: 981
Share:
2 Replies
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.
js*******@attglobal.net
==================
Feb 11 '07 #2
On Sun, 11 Feb 2007 05:53:51 -0800, zek2005 wrote:
$result=mysql_db_query($database,$query,$link);
From the manual:
This function is deprecated, do not use this function. Use
mysql_select_db() and mysql_query() instead.

http://www.php.net/manual/en/functio...l-db-query.php

Or, if you insist on using a deprecated function, please check for
warnings: "If by chance no connection is found or established, an
E_WARNING level warning is generated." My guess is a username/password
mismatch...

--
Regards/mvh Joachim Mæland

If everything seems under control, you're just not going fast enough.
-Mario Andretti.

Feb 11 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by newbie_mw | last post: by
5 posts views Thread by Juho Saarikko | last post: by
2 posts views Thread by Gunnar Vyenli | last post: by
3 posts views Thread by DarthMacgyver | last post: by
4 posts views Thread by Bradley Burton | last post: by
1 post views Thread by Net Virtual Mailing Lists | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.