griffinwebnet
10-11-2011, 04:53 AM
Hi all,
Im about ready to pull out my hair because ive been trying for days to fix this error without sucess. i have a password change script for my program and if you submit the form with all fields blank it should send you to an error page, but insted it ignores the if statement that controls that, and simply makes the password "".
Here is my code. the post info comes from an html form on another page
<?php
session_start();
$host="localhost"; // Host name
$username="xxxxxxxxxxxxxxxxxx"; // Mysql username
$password="xxxxxxxxxxxxxxxxxx"; // Mysql password
$db_name="xxxxxxxxxxxxxxxxxx"; // Database name
$tbl_name="users"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$username = $_SESSION["username"];
$newpassword = $_POST['newpassword'];
$repeatnewpassword = $_POST['repeatnewpassword'];
if (empty($newpassword)){
header("location:admin.pwd-change2.php");
}
if (empty($repeatnewpassword)){
header("location:admin.pwd-change2.php");
}
$result = mysql_query("SELECT password FROM $tbl_name WHERE username='$username'");
if(!$result)
{
header("location:admin.pwd-change2.php");
}
if ($row = mysql_fetch_assoc($result))
{
header("location:admin.pwd-change2.php");
}
if($newpassword==$repeatnewpassword)
$sql=mysql_query("UPDATE $tbl_name SET password='$newpassword' where username='$username'");
if($sql)
{
header("location:admin.pwd-change1.php");
}
else
{
header("location:admin.pwd-change2.php");
}
?>
Any help would be appreciated,
server is apache2 and php5.
Thanks In Advance,
-JL Griffin
Im about ready to pull out my hair because ive been trying for days to fix this error without sucess. i have a password change script for my program and if you submit the form with all fields blank it should send you to an error page, but insted it ignores the if statement that controls that, and simply makes the password "".
Here is my code. the post info comes from an html form on another page
<?php
session_start();
$host="localhost"; // Host name
$username="xxxxxxxxxxxxxxxxxx"; // Mysql username
$password="xxxxxxxxxxxxxxxxxx"; // Mysql password
$db_name="xxxxxxxxxxxxxxxxxx"; // Database name
$tbl_name="users"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$username = $_SESSION["username"];
$newpassword = $_POST['newpassword'];
$repeatnewpassword = $_POST['repeatnewpassword'];
if (empty($newpassword)){
header("location:admin.pwd-change2.php");
}
if (empty($repeatnewpassword)){
header("location:admin.pwd-change2.php");
}
$result = mysql_query("SELECT password FROM $tbl_name WHERE username='$username'");
if(!$result)
{
header("location:admin.pwd-change2.php");
}
if ($row = mysql_fetch_assoc($result))
{
header("location:admin.pwd-change2.php");
}
if($newpassword==$repeatnewpassword)
$sql=mysql_query("UPDATE $tbl_name SET password='$newpassword' where username='$username'");
if($sql)
{
header("location:admin.pwd-change1.php");
}
else
{
header("location:admin.pwd-change2.php");
}
?>
Any help would be appreciated,
server is apache2 and php5.
Thanks In Advance,
-JL Griffin