Jump to content

Recommended Posts

Hi,

 

I made a simple script where users can change their username and password. When they click submit the data will be changed. It gives me a confirmation that it has been updated but it doesn't! Here's the code:

<?php 


include('config2.php'); 
$nusername = $_POST['username'];
$npassword = $_POST['password'];
$id = $_REQUEST['id'];

$sql = mysql_query("UPDATE painlessdesigns_users SET username='$nusername',password='$npassword' WHERE id='$id'") or die(mysql_error());
echo "Page has been successfully changed! Please <a href='login.php'>log in</a> with your new user details "; 

    mysql_close(); 


?> 

 

And here is the form:

<?php
session_start();
if($_SESSION['auth'] == true) {

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

	<form action="accchange.php" method="POST">
	Type your new username:  <input type="text" value="<?= $_SESSION['username'] ?>" name="username" /><br />
	Type your new password:  <input type="password" name="password" /><br />
	<input type="submit" value="submit" name="submit" />
	</form>


<?php 
} else {
echo "You're not logged in. Make sure you're logged in.";
}
?>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/69921-solved-update-data-doesnt-get-updated/
Share on other sites

Your not actually running the query

 

Replace:

 

$sql = mysql_query("UPDATE painlessdesigns_users SET username='$nusername',password='$npassword' WHERE id='$id'") or die(mysql_error());

 

with

 

$sql = "UPDATE painlessdesigns_users SET username='$nusername',password='$npassword' WHERE id='$id'"
mysql_query($sql) or die(mysql_error());

 

Hope that helps ;D

 

~ Chocopi

Your not actually running the query

 

Replace:

 

$sql = mysql_query("UPDATE painlessdesigns_users SET username='$nusername',password='$npassword' WHERE id='$id'") or die(mysql_error());

 

with

 

$sql = "UPDATE painlessdesigns_users SET username='$nusername',password='$npassword' WHERE id='$id'"
mysql_query($sql) or die(mysql_error());

 

Hope that helps ;D

 

~ Chocopi

 

They are both the same thing.. he is running the query

 

 

$nusername

$nupassword

$id

 

 

echo all three of these out, and make sure there is something stored in them.

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.