Forum Moderators: coopster

Message Too Old, No Replies

Simply Edit and Update Script

         

m4tt

8:55 am on Jul 6, 2005 (gmt 0)

10+ Year Member



Can anyone provide a simple edit/update script. I have only one field that requires updating and the structure is as follows:

user_id = username
User_password = password
url = redirection url

I would like to have th option to edit these three fields and I have tried everything. Can anyone help with a simple script?

mcibor

10:22 am on Jul 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Some file, eg. form.html:
<form action="bla.php" method="post">
(This can be automated and type="hidden". )Old usename<input type="text" name="ouser"><br>
Insert new username:<input type="text" name="nuser"><br>
Old password:<input type="password" name="opass"><br>
New password:<input type="password" name="npass"><br>
Repeat new pass:<input type="password" name="npass2"><br>
Change url:<input type="text" name="url"><br>
<input type="submit" name="action" value="Submit"></form>

bla.php:

<?php
$error = "Click <a href=\"form.html\">here</a> to try again.";
if($_POST["action"]!= "Submit") die("Form not submitted.<br>$error");
if(empty(trim($_POST["ouser"]))) die("Missing old username.<br>$error");
$query = mysql_query("SELECT User_password FROM table WHERE user_id='$ouser'") or die("Error: ".mysql_error().$error);
$row = mysql_fetch_assoc($query);
if($_POST["npass"]!= $row["User_password"]) die("Wrong password.<br>$error");
if($_POST["npass"]!= $_POST["npass2"]) die("Both passwords must be the same.<br>$error");
//here validation of url if you wish
mysql_query("UPDATE table SET user_id='".mysql_real_escape_string($_POST["nuser"])."', User_password='".mysql_real_escape_string($_POST["npass"])."', url='".mysql_real_escape_string($_POST["url"]."' WHERE user_id = '".mysql_real_escape_string($_POST["ouser"]."'") or die("Error: ".mysql_error().$error);
Echo "Success!";?>

Hope this helps
Michal CIbor