tags:

views:

107

answers:

3
if (!empty($_POST)){

    $email_to=$_POST['email_to'];
    $email_to=mysql_real_escape_string($_POST['email_to']);

    $sql = "UPDATE `cosmos`.`members` SET `conf` = '2' WHERE `members`.`email` = '$email_to';";
    $result=mysql_query($sql) or trigger_error(mysql_error().$sql);

    $count=mysql_affected_rows($result);                  // line 20
    if($count==1){

    $rows=mysql_fetch_array($result);
    $unique=$rows['u_code'];
    $name=$rows['username'];
    // ---------------- SEND MAIL FORM ---------------- 
    $to=$email_to; 
    $subject="Your Account Password Request! - Cosmos"; 
    $header="from: Tayal's/Cosmos <[email protected]>"; 
    $messages= "Hey $name ,\r\n";
    $messages.="You recently requested a new password";
    $messages.="<br /><a href='confirm.php?uid" . $unique . "'>Confirmation Link</a> \r\n";
    $sentmail = mail($to,$subject,$messages,$header); 
    echo $messages; 
    }   else {
    echo "Not found your email in our database";
    }


}

Warning: mysql_affected_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\a\l\forget.php on line 20

A: 
$result=mysql_query($sql);

to

$result=mysql_query($sql) or trigger_error(mysql_error().$sql);

and run it again

and then

$email_to=$_POST['email_to'];

to

$email_to=mysql_real_escape_string($_POST['email_to']);

oh yes, and there is also quotes

Col. Shrapnel
Notice: 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 '\'2\' WHERE `members`.`email` = '[email protected]'' at line 1UPDATE `cosmos`.`members` SET `conf` = \'2\' WHERE `members`.`email` = '[email protected]';
tunetosuraj
@tunetosuraj it seems you were added \ to ' around 2 somehow. it should be just conf = '2'
Col. Shrapnel
the above one is fixed but not `Warning: mysql_affected_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\a\l\forget.php`
tunetosuraj
@tunetosuraj what variable do you pass to this function? can you post new code, from `$email_to=` to `mysql_affected_rows`?
Col. Shrapnel
@Col. Shrapnel - code is updated above
tunetosuraj
@tunetosuraj do you get any error beside `mysql_affected_rows()` one?
Col. Shrapnel
@Col. Shrapnel - No, but I guess its so because it does not reach the `If (count==1)` part only
tunetosuraj
@tunetosuraj but it does. btw, you can't fetch any data after UPDATE query. You have to rewrite your code seriously
Col. Shrapnel
@Col. Shrapnel - its two days that I am stuck on this code and seriously I also want to change the code but no other alternate code available,....would be glad if you could help!
tunetosuraj
@tunetosuraj to help you, one should know what this code should actually do.
Col. Shrapnel
@Col. Shrapnel http://stackoverflow.com/questions/3742604/forget-password-page-using-php-mysql
tunetosuraj
@tunetosuraj look, make it select, not update. It will both check email existence and give you info for email. and after select you can execute update as well.
Col. Shrapnel
A: 

The SQL you performed was not a SELECT, so no rows are returned!

fredley
+1. Instead, what the OP needs is [mysql_affected_rows](http://www.php.net/manual/en/function.mysql-affected-rows.php).
casablanca
correct. but it's not the only problem, its stil boolean, not resource
Col. Shrapnel
Indeed, thanks for the tip.
fredley
@Col. Shrapnel: mysql_affected_rows() takes no parameter.
fredley
@fredley He meant to say that's not's what is causing the error.
NullUserException
fredley but num_rows one says it's not a resource.
Col. Shrapnel
+1  A: 

$result is false because your query is invalid (has a syntax error). Use:

$sql = "UPDATE members SET conf=2 WHERE email = '$email_to';"

(note the quotes surrounding $email_to)

Also mysql_num_rows() should be used for SELECT queries only. For UPDATE, INSERT and DELETE, use mysql_affected_rows() instead.

Finally, for future reference, if your query doesn't work, print the error and the SQL query used (something like what's on Col Shrapnel's answer). It will help you know what's wrong.

NullUserException
hey, the sql part worked but not the `mysql_affected_rows()`
tunetosuraj
@tune What doesn't work?
NullUserException
still getting `Warning: mysql_affected_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\a\l\forget.php` focussing on `mysql_affected_rows()`
tunetosuraj
@tune That means the query failed. Please post your new code
NullUserException
@NullUser updated! the code
tunetosuraj
@tune try the new query I posted.
NullUserException
@NullUser - still the same error
tunetosuraj
@tune Instead of executing the query, try to print it (eg: `echo $sql`), and execute it manually (eg: via phpMyAdmin) and see what happens
NullUserException
@NULLUSER - `UPDATE members SET conf=2 WHERE email = '[email protected]';`
tunetosuraj
@tuneto What happens when you execute that query manually?
NullUserException
nothing...just closing this post! I better make new code (see at:http://stackoverflow.com/questions/3742604/forget-password-page-using-php-mysql)
tunetosuraj