Jump to content

Need Help With Edit/delete Mysql Records


Recommended Posts

If i hit Edit button i got these error before i click Submiterror.png




if ($_GET['do'] == 'test2') {

$id = ($_POST['id']);
$username = cleanuserinput($_POST['username']);
$password = cleanuserinput($_POST['password']);
$rpassword = cleanuserinput($_POST['rpassword']);
$pass = md5($_POST['password']);
mysql_query("delete from admin where id='".$id."'");
 print '<center><font color=black>Admin has been deleted!</font><br>';


//Make sure username isn't blank
if (!$username){
$error .= '<font color=red>Sorry, the username was empty.</font><br>';
//Make sure password isn't blank
if (!$password){
$error .= '<font color=red>Sorry, your password was empty.</font><br>';
//Make sure both passwords match
if ($password != $rpassword) {
$error .= '<font color=red>Passwords Doesn\'t Match!</font><br>';
 //Check username length
if (!ctype_alnum($username) || strlen($username) < 4 || strlen($username) > 15) {
$error .= '<font color=red>Username must be between 4-15 characters!</font><br>';
//Check password length
 if (!ctype_alnum($password) || strlen($password) < 4 || strlen($password) > 15) {
$error .= '<font color=red>Password must be between 4-15 characters.</font><br>';

if (!$error){
$sql_update = "UPDATE admin set username = '$username', password= '$pass' where id='".$id."'";
	 $result = mysql_query ($sql_update) or die(mysql_error());
print "<center><font color=black>User ". $_POST['username'] ." Has been edited.</font><br>";

$get_admin = mysql_query("select * from admin where id='".$id."'");
$admin = mysql_fetch_array($get_admin);

echo $error . "<form action='?do=test2' method='post'>
<tr><th colspan=20>Edit Admin</th></tr>
<tr><td><b>Username<font color=red>*</font></b></td><td><div><small>[ 4-15 characters ]</small></div><input name='username' type='text' maxlength='50' size='25' tabindex='1' value='".$admin['username']."'></td></tr>
<tr><td><b>Password<font color=red>*</font></b></td><td><div><small>[ 4-15 characters ]</small></div><input name='password' type='text' maxlength='50' size='25' tabindex='2' value=''></td></tr>
<tr><td><b>Password 2<font color=red>*</font></b></td><td><input name='rpassword' type='text' maxlength='50' size='25' tabindex='3' value=''></td></tr>


	 <input type=hidden name=id value='".$admin['id']."'>
	 <div align='center'><br><input type='submit' name='submit' tabindex='4' value='Submit'></div>

} else {
print" <table width=90%>
<tr><th colspan=20>Current Admin</th></tr>
<td>Admin Name</td>
<td>Added Date</td>
<td align=center>Action</td>";

$get_admin = mysql_query("select * from admin ");
while ($row = mysql_fetch_array($get_admin)){

print " <tr>
<td>". $row['username'] ."</td>
<td>". $row['date'] ."</td>
<td align=center>
<form method=POST>
<input name=id type=hidden value='".$row['id']."'>
<input type=submit name=edit value='Edit'>
		 <input type=submit name=delete value='Delete'>

print "</table>";
} else {

Link to comment
Share on other sites

Code is run from top to bottom. You're checking if a password and username have been set and telling it to echo that before anyone gets a chance to enter any data.


What? the OP has the error code inside of a condition that waits for the edit button to be clicked.


davidolson, the code is doing exactly what you have coded it to do, what are you expecting it to do?

Link to comment
Share on other sites

What? the OP has the error code inside of a condition that waits for the edit button to be clicked.


davidolson, the code is doing exactly what you have coded it to do, what are you expecting it to do?


I skimmed the code over too quickly, it seems. Just saw that he said it's displaying those errors before they even submit everything.

Link to comment
Share on other sites

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.

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.