Jump to content

Recommended Posts

The Error reads as:

Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in /home/themepar/public_html/changepass.php on line 20

You have not entered all the fields

Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in /home/themepar/public_html/changepass.php on line 35

Sorry You failed to enter the correct old password

The Code is as:

<?php
session_start();
if (!isset($_SESSION['s_username'])) {
    header("Location: login.php");
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Change Pass</title>
</head>
<body>
<?php
// Mysql
include ('mysql_connect.php');
// 
$oldpass=$_POST['oldpass'];
$newpass=$_POST['newpass'];
$cnewpass=$_POST['cnewpass'];
$numrows = mysql_affected_rows($res);
//
if (($oldpass==NULL)||( $newpass==NULL)||( $cnewpass==NULL)) {
echo "You have not entered all the fields";
}else{
exit();
}
//
if($newpass!=$cnewpass) {
echo "Passwords do not match";
} else {
}
//
$sql = "UPDATE users SET password = '".md5($newpass)."' WHERE username = '".$_SESSION['s_username']."' AND password = '".md5($oldpass)."' ";
$res = mysql_query($sql,$dbc) or die (mysql_error());
$numrows = mysql_affected_rows($res);
if ($numrows >0) {
echo "your password has been changed ";
} else {
echo "Sorry You failed to enter the correct old password";
}
mysql_query($sql,$dbc) or die (mysql_error());
?>

Could Someone help please?

Link to comment
https://forums.phpfreaks.com/topic/54907-php-error-help-please/
Share on other sites

You have code

$numrows = mysql_affected_rows($res);

there twice.

 

Let me show you

 

$cnewpass=$_POST['cnewpass'];
[b]$numrows = mysql_affected_rows($res);[/b]
//
if (($oldpass==NULL)||( $newpass==NULL)||( $cnewpass==NULL)) {
echo "You have not entered all the fields";
}else{
exit();
}
//
if($newpass!=$cnewpass) {
echo "Passwords do not match";
} else {
}
//
$sql = "UPDATE users SET password = '".md5($newpass)."' WHERE username = '".$_SESSION['s_username']."' AND password = '".md5($oldpass)."' ";
$res = mysql_query($sql,$dbc) or die (mysql_error());
[b]$numrows = mysql_affected_rows($res);[/b]
if ($numrows >0) {

 

The first time, you hadn't even defined $res.  So, delete the first one and it should work.

Link to comment
https://forums.phpfreaks.com/topic/54907-php-error-help-please/#findComment-271552
Share on other sites

Still has not worked i am afraid,

I now have:

You have not entered all the fields

Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in /home/themepar/public_html/changepass.php on line 34

Sorry You failed to enter the correct old password

Link to comment
https://forums.phpfreaks.com/topic/54907-php-error-help-please/#findComment-271553
Share on other sites

if (($oldpass==NULL)||( $newpass==NULL)||( $cnewpass==NULL)) {
echo "You have not entered all the fields";
}else{
exit();
}
//
if($newpass!=$cnewpass) {
echo "Passwords do not match";
} else {
}

 

In each of those if/else statements you don't set any rules for the 'else' part. What they are saying is IF these don't match echo the error but IF they do match then do...... ?

Link to comment
https://forums.phpfreaks.com/topic/54907-php-error-help-please/#findComment-271568
Share on other sites

In the first one:

 

if (($oldpass==NULL)||( $newpass==NULL)||( $cnewpass==NULL)) {
echo "You have not entered all the fields";
}else{
exit();
}

 

you're telling it to check that those have been set or 'not empty' basically. But, IF they ARE set you're telling the script to 'exit'.

 

In the 2nd one:

 

//
if($newpass!=$cnewpass) {
echo "Passwords do not match";
} else {
}

 

you're saying that IF the DON'T match then echo the error but IF THEY DO MATCH you're telling it to do nothing. That 2nd curly bracket should be below all the code you want to execute IF they DO MATCH.

Link to comment
https://forums.phpfreaks.com/topic/54907-php-error-help-please/#findComment-271579
Share on other sites

You've got the right idea but just need to carry forward what happens if everything checks out. I doubt seriously if you want to exit the script if, indeed, the fields match properly. You might try it like this:

 

$errors = array();

if (empty($_POST['oldpass']) || empty($_POST['newpass']) || empty($_POST['cnewpass']))
    {
       $errors[] = "You did not complete all the password fields. Please try again.";
     } else {
     $newpass = $_POST['newpass'];
     $cnewpass = $_POST['cnewpass'];
     if ($newpass != $cnewpass) {
     $errors[] = "The new password and confirm password fields do not match. Please try again";
      } else {
     //execute all your good code here since it's passed all the tests
     }
}

 

For the errors, you want those to display somewhere in the page probably above the form. So, you'd insert this code in there:

 

<?
// Loop through all errors
if(!empty($errors))
{
?>
<ul>
<?
foreach($errors as $message)
{
?>
<li id='errorMess'><?= @$message ?></li>
<?
}
?>
</ul>
<?
}
?>

 

You don't have to stretch it out quite like that but I was feeling lazy. This will loop through the $errors array and display the error messages.

 

The basic principal of the if/else is IF this condition IS NOT met then DO THIS. :)

Link to comment
https://forums.phpfreaks.com/topic/54907-php-error-help-please/#findComment-271592
Share on other sites

Hey, Well theres no errors, But for some reason when I press submit it does nothing,

<?php
// Mysql
include ('mysql_connect.php');
// 
$oldpass=$_POST['oldpass'];
$newpass=$_POST['newpass'];
$cnewpass=$_POST['cnewpass'];
//
$errors = array();

if (empty($_POST['oldpass']) || empty($_POST['newpass']) || empty($_POST['cnewpass']))
    {
       $errors[] = "You did not complete all the password fields. Please try again.";
     } else {
     $newpass = $_POST['newpass'];
     $cnewpass = $_POST['cnewpass'];
     if ($newpass != $cnewpass) {
     $errors[] = "The new password and confirm password fields do not match. Please try again";
      } else {
     //execute all your good code here since it's passed all the tests
 $sql = "UPDATE users SET password = '".md5($newpass)."' WHERE username = '".$_SESSION['s_username']."' AND password = '".md5($oldpass)."' ";
$res = mysql_query($sql,$dbc) or die (mysql_error());
$numrows = mysql_affected_rows($dbc);
if ($numrows >0) {
echo "your password has been changed ";
} else {
}
echo "Sorry You failed to enter the correct old password";
}
mysql_query($sql,$dbc) or die (mysql_error());
}

//

?>

Codes that now, Btw.

Link to comment
https://forums.phpfreaks.com/topic/54907-php-error-help-please/#findComment-271594
Share on other sites

Whole Code:

Can other people help please?

<?php
session_start();
if (!isset($_SESSION['s_username'])) {
header("Location: login.php");
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Change Pass</title>
</head>
<body>
<?php
// Mysql
include ('mysql_connect.php');
// 
$oldpass=$_POST['oldpass'];
$newpass=$_POST['newpass'];
$cnewpass=$_POST['cnewpass'];
//
$errors = array();

if (empty($_POST['oldpass']) || empty($_POST['newpass']) || empty($_POST['cnewpass']))
    {
       $errors[] = "You did not complete all the password fields. Please try again.";
     } else {
     $newpass = $_POST['newpass'];
     $cnewpass = $_POST['cnewpass'];
     if ($newpass != $cnewpass) {
     $errors[] = "The new password and confirm password fields do not match. Please try again";
      } else {
     //execute all your good code here since it's passed all the tests
 $sql = "UPDATE users SET password = '".md5($newpass)."' WHERE username = '".$_SESSION['s_username']."' AND password = '".md5($oldpass)."' ";
$res = mysql_query($sql,$dbc) or die (mysql_error());
$numrows = mysql_affected_rows($dbc);
if ($numrows >0) {
echo "your password has been changed ";
} else {
}
echo "Sorry You failed to enter the correct old password";
}
mysql_query($sql,$dbc) or die (mysql_error());
}

//

?>
<div align="center">
  <table width="326" height="124" border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td width="143"><div align="center">Change Your Pass: </div></td>
    </tr>
    <tr>
      <td><div align="right">Old Password:
          <input name="oldpass" type="password" id="oldpass" value="">
</div></td>
    </tr>
    <tr>
      <td><div align="right">New Password:
          <input name="newpass" type="password" id="newpass">
      </div></td>
    </tr>
    <tr>
      <td><div align="right">Confirm New Password:
        <input name="cnewpass" type="password" id="cnewpass">
</div></td>
    </tr>
    <tr>
      <td><div align="center">
        <input name="submit" type="submit" id="submit" value="Submit">
      </div></td>
    </tr>
    <tr>
      <td><?
// Loop through all errors
if(!empty($errors))
{
?>
<ul>
<?
foreach($errors as $message)
{
?>
<li id='errorMess'><?= @$message ?></li>
<?
}
?>
</ul>
<?
}
?> </td>
    </tr>
  </table>
  <form name="form1" method="post">
  </form>
</div>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/54907-php-error-help-please/#findComment-271698
Share on other sites

Sorry to double post, But I sorted that error, I just realised that the Form was not around the feilds, Now for some reason i9 have this at the bottom:

You did not complete all the password fields. Please try again.

When I have not even entered anything yet,

And When I do everything correct it changes the password but comes up with this at the top:

your password has been changed Sorry You failed to enter the correct old password

 

Can Someone Help Please?

 

Code:

<?php
session_start();
if (!isset($_SESSION['s_username'])) {
header("Location: login.php");
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Change Pass</title>
</head>
<body>
<?php
// Mysql
include ('mysql_connect.php');
// 
$oldpass=$_POST['oldpass'];
$newpass=$_POST['newpass'];
$cnewpass=$_POST['cnewpass'];
//
$errors = array();

if (empty($_POST['oldpass']) || empty($_POST['newpass']) || empty($_POST['cnewpass']))
    {
       $errors[] = "You did not complete all the password fields. Please try again.";
     } else {
     $newpass = $_POST['newpass'];
     $cnewpass = $_POST['cnewpass'];
     if ($newpass != $cnewpass) {
     $errors[] = "The new password and confirm password fields do not match. Please try again";
      } else {
     //execute all your good code here since it's passed all the tests
 $sql = "UPDATE users SET password = '".md5($newpass)."' WHERE username = '".$_SESSION['s_username']."' AND password = '".md5($oldpass)."' ";
$res = mysql_query($sql,$dbc) or die (mysql_error());
$numrows = mysql_affected_rows($dbc);
if ($numrows >0) {
echo "your password has been changed ";
} else {
}
echo "Sorry You failed to enter the correct old password";
}
mysql_query($sql,$dbc) or die (mysql_error());
}

//

?>
<div align="center">
  <form name="form1" method="post">
    <table width="326" height="124" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="143"><div align="center">Change Your Pass: </div></td>
      </tr>
      <tr>
        <td><div align="right">Old Password:
          <input name="oldpass" type="password" id="oldpass" value="">
        </div></td>
      </tr>
      <tr>
        <td><div align="right">New Password:
          <input name="newpass" type="password" id="newpass">
        </div></td>
      </tr>
      <tr>
        <td><div align="right">Confirm New Password:
          <input name="cnewpass" type="password" id="cnewpass">
        </div></td>
      </tr>
      <tr>
        <td><div align="center">
            <input name="submit" type="submit" id="submit" value="Submit">
        </div></td>
      </tr>
      <tr>
        <td><?
// Loop through all errors
if(!empty($errors))
{
?>
            <ul>
              <?
foreach($errors as $message)
{
?>
              <li id='errorMess'>
                <?= @$message ?>
              </li>
              <?
}
?>
            </ul>
          <?
}
?>
           </td>
      </tr>
    </table>
  </form>
</div>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/54907-php-error-help-please/#findComment-271704
Share on other sites

1st of all ur code is ready for sql injections, so try these for preventing injections.

$oldpass=mysql_real_escape_string($_POST['oldpass']);
$newpass=mysql_real_escape_string($_POST['newpass']);
$cnewpass=mysql_real_escape_string($_POST['cnewpass']);

 

other u define ur variables from form twice may i know why:

Here..

else {
    $newpass = $_POST['newpass'];
    $cnewpass = $_POST['cnewpass'];
    if ($newpass != $cnewpass) {

These varaibles u define already above.

 

Other there is no else statement to insert record to db.

Look at ur this code:

session_start();
if (!isset($_SESSION['s_username'])) {
header("Location: login.php");
}

After that i did not see any else statement to do the job.

Ok try this:

session_start();
if (!isset($_SESSION['s_username'])) {
header("Location: login.php");
}else {

rest of the code...

echo "Sorry You failed to enter the correct old password";
}
mysql_query($sql,$dbc) or die (mysql_error());
}
}
//

?>

 

Hope this will help u.

Link to comment
https://forums.phpfreaks.com/topic/54907-php-error-help-please/#findComment-271705
Share on other sites

Why is there a random echo in it?

I don't know why I have to do that,

BTW:

I have this error comeing up above the forms:

your password has been changed Sorry You failed to enter the correct old password

When it should only be Your Password has been changed,

Please take a look:

<?php
session_start();
if (!isset($_SESSION['s_username'])) {
header("Location: login.php");
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Change Pass</title>
</head>
<body>
<?php
// Mysql
include ('mysql_connect.php');
// 
$oldpass=mysql_real_escape_string($_POST['oldpass']);
$newpass=mysql_real_escape_string($_POST['newpass']);
$cnewpass=mysql_real_escape_string($_POST['cnewpass']);
//
$errors = array();

if (!isset($_POST['oldpass']) || !isset($_POST['newpass']) || !isset($_POST['cnewpass']))
    {
       $errors[] = "You did not complete all the password fields. Please try again.";
     } else {  
     if ($newpass != $cnewpass) {
     $errors[] = "The new password and confirm password fields do not match. Please try again";
      } else {
     //execute all your good code here since it's passed all the tests
 $sql = "UPDATE users SET password = '".md5($newpass)."' WHERE username = '".$_SESSION['s_username']."' AND password = '".md5($oldpass)."' ";
$res = mysql_query($sql,$dbc) or die (mysql_error());
$numrows = mysql_affected_rows($dbc);
if ($numrows >0) {
echo "your password has been changed ";
} else {
}
echo "Sorry You failed to enter the correct old password";
}
mysql_query($sql,$dbc) or die (mysql_error());
}

//

?>
<div align="center">
  <form name="form1" method="post">
    <table width="326" height="124" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="143"><div align="center">Change Your Pass: </div></td>
      </tr>
      <tr>
        <td><div align="right">Old Password:
          <input name="oldpass" type="password" id="oldpass" value="">
        </div></td>
      </tr>
      <tr>
        <td><div align="right">New Password:
          <input name="newpass" type="password" id="newpass">
        </div></td>
      </tr>
      <tr>
        <td><div align="right">Confirm New Password:
          <input name="cnewpass" type="password" id="cnewpass">
        </div></td>
      </tr>
      <tr>
        <td><div align="center">
            <input name="submit" type="submit" id="submit" value="Submit">
        </div></td>
      </tr>
      <tr>
        <td><?
// Loop through all errors
if(!empty($errors))
{
?>
            <ul>
              <?
foreach($errors as $message)
{
?>
              <li id='errorMess'>
                <?= @$message ?>
              </li>
              <?
}
?>
            </ul>
          <?
}
?>
           </td>
      </tr>
    </table>
  </form>
</div>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/54907-php-error-help-please/#findComment-271710
Share on other sites

Change this:

	 $sql = "UPDATE users SET password = '".md5($newpass)."' WHERE username = '".$_SESSION['s_username']."' AND password = '".md5($oldpass)."' ";
$res = mysql_query($sql,$dbc) or die (mysql_error());
$numrows = mysql_affected_rows($dbc);
if ($numrows >0) {
echo "your password has been changed ";
} else {
}
echo "Sorry You failed to enter the correct old password";
}
mysql_query($sql,$dbc) or die (mysql_error());
}

 

To this:

	 $sql = "UPDATE users SET password = '".md5($newpass)."' WHERE username = '".$_SESSION['s_username']."' AND password = '".md5($oldpass)."' ";
$res = mysql_query($sql,$dbc) or die (mysql_error());
$numrows = mysql_affected_rows($dbc);
if ($numrows >0) {
echo "your password has been changed ";
} else {
echo "Sorry You failed to enter the correct old password";
}
mysql_query($sql,$dbc) or die (mysql_error());
}

Link to comment
https://forums.phpfreaks.com/topic/54907-php-error-help-please/#findComment-271715
Share on other sites

That particular error is caused because you have an unclosed loop - somewhere you're missing a closing curly brace }

 

If you can't find that error, I think it would be a really good idea to post the present version of your code as it appears to have undergone major surgery in this thread.

Link to comment
https://forums.phpfreaks.com/topic/54907-php-error-help-please/#findComment-271765
Share on other sites

I cannot find the open bracket, So here is the full code:

<?php
session_start();
if (!isset($_SESSION['s_username'])) {
header("Location: login.php");
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Change Pass</title>
</head>
<body>
<?php
// Mysql
include ('mysql_connect.php');
// 
$oldpass=mysql_real_escape_string($_POST['oldpass']);
$newpass=mysql_real_escape_string($_POST['newpass']);
$cnewpass=mysql_real_escape_string($_POST['cnewpass']);
//
$errors = array();

if (!isset($_POST['oldpass']) || !isset($_POST['newpass']) || !isset($_POST['cnewpass']))
    {
       $errors[] = "You did not complete all the password fields. Please try again.";
     } else {  
     if ($newpass != $cnewpass) {
     $errors[] = "The new password and confirm password fields do not match. Please try again";
      } else {
     //execute all your good code here since it's passed all the tests
$sql = "UPDATE users SET password = '".md5($newpass)."' WHERE username = '".$_SESSION['s_username']."' AND password = '".md5($oldpass)."' ";
$res = mysql_query($sql,$dbc) or die (mysql_error());
$numrows = mysql_affected_rows($dbc);
if ($numrows >0) {
echo "your password has been changed ";
} else {
echo "Sorry You failed to enter the correct old password";
}
mysql_query($sql,$dbc) or die (mysql_error());
}

//

?>
<div align="center">
  <form name="form1" method="post">
    <table width="326" height="124" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="143"><div align="center">Change Your Pass: </div></td>
      </tr>
      <tr>
        <td><div align="right">Old Password:
          <input name="oldpass" type="password" id="oldpass" value="">
        </div></td>
      </tr>
      <tr>
        <td><div align="right">New Password:
          <input name="newpass" type="password" id="newpass">
        </div></td>
      </tr>
      <tr>
        <td><div align="right">Confirm New Password:
          <input name="cnewpass" type="password" id="cnewpass">
        </div></td>
      </tr>
      <tr>
        <td><div align="center">
            <input name="submit" type="submit" id="submit" value="Submit">
        </div></td>
      </tr>
      <tr>
        <td><?
// Loop through all errors
if(!empty($errors))
{
?>
            <ul>
              <?
foreach($errors as $message)
{
?>
              <li id='errorMess'>
                <?= @$message ?>
              </li>
              <?
}
?>
            </ul>
          <?
}
?>
           </td>
      </tr>
    </table>
  </form>
</div>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/54907-php-error-help-please/#findComment-271769
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.