Jump to content

Problem in a query


ballouta

Recommended Posts

I have code that should change a password.

 

if i enter a wrong current password in the previous form or if the new password is less than 6 charcaters or if it is empty, the errror line appears perfect for both

line 10 prints the old and new password correctly.

 

BUT line 25 does NOT print the password fields!! it only and the update query is not working

 

where is the problem?

 

thank you

 

 

<?php
	include ('global.inc.php');

$user = $_SESSION['username'];
$old = $_POST['password_old'];
$new = $_POST['password_new'];



if  (strlen ($new) <6 || $new ='' || $old == '')
	{
	echo "Error: The New Password is less than SIX characters, or the old password is empty <a href='settings.php'>try again</a>";
	}
//echo "working $old / $new / $user"; line 10
else {
//check if the password entered is correct
$sql="SELECT * FROM `administrators` WHERE `username` COLLATE latin1_bin ='$user' AND `password` COLLATE latin1_bin ='$old'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);

if($count==1){

echo "working $old / $new / $user"; //line 25
$sql = "UPDATE `administrators` SET `password` = '$new' WHERE `username` = '$user' AND `password` = '$old' "; 
$result = mysql_query($sql);

		}
	else
	{
	echo "wrong info";
	}

		}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/154340-problem-in-a-query/
Share on other sites

Your line #10 doesn't make sense don't put code between } and else. Move it after the { or before the if.

 

And your line #25 may not be executed because this if

if  (strlen ($new) <6 || $new ='' || $old == '')

OR your SQL SELECT don't work

OR your SQL SELECT return any or more than 1 results ($commit == 1)

 

Add this on the begining of your php

 

<?php
ini_set ("display_errors", "1");
error_reporting(E_ALL);
?>

 

then add this after each mysql_query()

 

<?php
...
if (!$result) {
    die('Invalid query: ' . $sql. ' mysql_error : '. mysql_error());
}
...
?>

 

You will be able to see error message and see where it don't work.

Link to comment
https://forums.phpfreaks.com/topic/154340-problem-in-a-query/#findComment-811403
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.