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.

Dani AI

Generated

A quick recap and some practical next steps.

The original parse error came from malformed string/quote usage when building the UPDATE from POST data; 's move to assign each posted field to a variable and build the query corrected that syntax problem. After the parse error disappears, a blank page is a different symptom and usually means a runtime error was hidden or the script immediately redirected to an empty page.

Troubleshooting checklist to find the real cause:

  • Turn on error reporting while debugging: error_reporting(E_ALL); ini_set('display_errors', 1);
  • Remove any error-suppression so PHP will show failures.
  • Check the webserver/PHP error log for fatal errors.
  • Verify the database call actually ran: confirm the connection handle you pass to the query is the same one you opened and inspect the query result / affected rows.
  • If a redirect happens, inspect the destination page (it might be empty) or use browser dev tools / curl to view the response.

Security and maintainability notes:

  • Move away from obsolete APIs and use mysqli or PDO with prepared statements to prevent SQL injection.
  • Never store passwords in plain text — use secure hashing (e.g., password_hash / password_verify).
  • Validate and sanitize all input, and run such scripts only over HTTPS in production.

Final short checklist: enable errors, check logs, verify connection/handle and query result before redirecting, surface a clear success/failure message (or use a session "flash"), and migrate to prepared statements + hashed passwords for production. Thanks to for the variable approach and to for the messaging suggestion — those are the right directions to make the fix robust.

Recommended Answers

All 4 Replies

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.