Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

small UPDATE execution error

Status
Not open for further replies.

DaSe

Programmer
Feb 14, 2008
149
GB
Hello PHP guys,
Could anyone tell please why it ends with an error saying "Warning: mysql_query() expects parameter 2 to be resource, string given in C:\xampp\htdocs\david1.php on line 7" ? Here is the small script :


----------------------


<?php
$connection = mysql_connect("localhost" , "root" , "myPassword") or die(mysql_error());
$database = mysql_select_db("david") or die(mysql_error());

$david = "SELECT actor FROM film";
$update = "UPDATE film SET actor='Jim' WHERE actor='John'";
$result = mysql_query($update,$david) or die (mysql_error());
while ($row = mysql_fetch_array($result))
{ echo $row['actor']; }
//$movie_name = $row['actor']; }


?>
--------------------------------
Regards.
 
You are passing 2 strings to mysql_query.

Mysql_query expects one of the parameters to be a resource handle. A value returned by mysql_connect, not a string containing another query.


In your case $david would have to be $connection.

Code:
$result = mysql_query($update,[red]$david[/red]) or die (mysql_error());

PHP Online Manual entry for mysql_query()


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top