Warning: mysql_affected_rows(): supplied argument is not a v

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Warning: mysql_affected_rows(): supplied argument is not a v

Post by a94060 »

i could swear that it probably looks like im smapping the forum but,i get this error:
Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in C:\xampplite\htdocs\admin\do.php on line 29

Code: Select all

<?PHP
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<?PHP
if($_SESSION['in'] != '1' ) {
echo '<font color=red>You are not logged in,please go <a href="../admin">Here</a> to login.</font>';
}
else {
/*the action page.all actions of the admin will be redirected here.
That is all*/
include("../includes/sql.php");
$act = $_GET['act'];
$entry = $_GET['entry'];//the id of the entry
	if($act == 'approve') {
	$query = "SELECT * FROM poffers WHERE id=$entry";
	$result = mysql_query($query);
	$data = mysql_fetch_array($result,MYSQL_ASSOC);
	$sql2 = "INSERT INTO coffers (username,offer_name,offer_type) VALUES ('{$data['username']}', '{$data['offer_name']}', '{$data['offer_type']})'"; 
	$sql2run = mysql_query($sql2);//inserts the offer to completed table.
	//remove it from the old table
	$put = mysql_affected_rows($sql2run);
		if($put == 1) {
		$delete = "DELETE FROM poffers WHERE id=$entry LIMIT 1";
		$delrun = mysql_query($delete);
		$hits = mysql_num_rows($delrun);
			if($hits == '1') {
			echo 'The offer' .$entry.'has been removed from pending offers and has been moved to completed offers.';
			}
			else{
			echo 'The entry was not added.';
			}
		}
	}
}
if($act == 'offer_add') {
$offer = $_GET['offer'];
$type = $_GET['select'];//tells what type of offer it is

$sql = "INSERT INTO offers ('offer_name' , 'offer_type') VALUES (" .$offer. " , " .$type.")";
$query = mysql_query($sql);
if(mysql_num_rows($query) != 1) {
echo "Your add was not successful,please go back and try again.";
}
else {
echo "Your Offer was sucessfully added to the database.";
}
}
?>
</body>
</html>
User avatar
ambivalent
Forum Contributor
Posts: 173
Joined: Thu Apr 14, 2005 8:58 pm
Location: Toronto, ON

Post by ambivalent »

PHP is complaining about an invalid MySQL link resource. You should make sure you're passing it the resource it expects
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

i send a link like http://localhost/admin/do.php?act=approve&entry=1 That should work assumming that i am logged in right?
User avatar
ambivalent
Forum Contributor
Posts: 173
Joined: Thu Apr 14, 2005 8:58 pm
Location: Toronto, ON

Post by ambivalent »

Did you read the manual page? Hint: under the "Parameters" heading.
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

so that means that i would neeed to assign a var to my sql connection right? BEcaus i have it set up in there as mysql_affected_rows($sql) wont work right?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

I don't count lines. Which line has the problem?

Code: Select all

$result = mysql_query($query);
        $data = mysql_fetch_array($result,MYSQL_ASSOC);
(#10850)
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

right around here:

Code: Select all

$sql2 = "INSERT INTO coffers (username,offer_name,offer_type) VALUES ('{$data['username']}', '{$data['offer_name']}', '{$data['offer_type']})'";
        $sql2run = mysql_query($sql2);//inserts the offer to completed table.
        //remove it from the old table
        $put = mysql_affected_rows($sql2run);
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

So on which of those three lines does the error occur?
(#10850)
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in C:\xampplite\htdocs\admin\do.php on line 29
I think that it might just wanna happon the the line with mysql affected rows. Thats just my opinion though....[/quote]
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

I don't see any error checking code between the mysql_query() line and the mysql_affected_rows() line. Add some code to check mysql_error() and see what the problem is. Every query should be followed by an error check.
(#10850)
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

hint: the trailing apostrophe is in the wrong place.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

a94060 wrote:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
When I have an error in my SQL syntax I do:

Code: Select all

echo $sql2;
to find the problem.
(#10850)
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

ok,ill check it out tommorow cuz i dont want to go turn on my laptop.
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

feyd wrote:hint: the trailing apostrophe is in the wrong place.

Code: Select all

$sql2 = "INSERT INTO coffers (username,offer_name,offer_type) VALUES ('{$data['username']}', '{$data['offer_name']}', '{$data['offer_type']}')";
        $sql2run = mysql_query($sql2);//inserts the offer to completed table.
        //remove it from the old table
        $put = mysql_affected_rows($sql2run);
something like that?
Post Reply