By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,890 Members | 1,039 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,890 IT Pros & Developers. It's quick & easy.

Problem with insert

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.