am writing an sql statement that can change the username and password but it is not working this is the code on line 19


$sql = "UPDATE login SET
username= newusername('$_POST'),password=newpassword('$_POST)
WHERE username = '$_POST',password='$_POST";

this is the error

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\wamp\www\ELIZA\passchange.php on line 19

assit to troubleshot.

What is

newusername('$_POST['newusername']');

is it a function?

Ok try this.

$username = $_POST['username'];
$password = $_POST['password'];
$newusername = $_POST['newusername'];
$newpassword = $_POST['newpassword'];
$sql = "UPDATE login SET
username= '$newusername', password='$newpassword' 
WHERE username = '$username', password='$password'";

thanks the error is gone but once the form for changing username and password is submitted a blank page results

this is the full code.

<?php


$con = mysql_connect("localhost","root","");
if (!$con)
{ 
die ('could not connect: '.mysql_error());
}

mysql_select_db("narok", $con);

$username= $_POST['username'];
$password=$_POST['password'];
$newusername= $_POST['newusername'];
$newpassword=$_POST['newpassword'];

//updates the table with the new password               
$username = $_POST['username'];
$password = $_POST['password'];
$newusername = $_POST['newusername'];
$newpassword = $_POST['newpassword'];
$sql = "UPDATE login SET
username= '$newusername', password='$newpassword'
WHERE username = '$username', password='$password'"; 
    $result = @mysql_query($sql, $connection) or die(mysql_error());

//sends the user to their redirect to
    header("Location:changepassword.php");
    exit;
?>

what could be missing

I think blank page results because there is nothing to print on this page. You can do something like:

if($result)
{
echo "success";
}
else
{
echo "failure";
}

otherwise on changepassword.php check if something mentioned.

What you can do is:
header("Location:changepassword.php?msg=$msg");

where $msg=success or failure.

So, it would be like:

if($result)
{
$msg= "success";
}
else
{
$msg= "failure";
}

header("Location:changepassword.php?msg=$msg");

On changepassword.php page,
get the msg value and print it.

thank you very much its working.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.