Page 1 of 1

changing a field

Posted: Thu Jan 22, 2004 3:21 pm
by dull1554
heres my code

Code: Select all

if(!isset($_POST['submit'])){
Print <<< EOT

<form method="POST" action="index.php?l=admin.php&admin=usertype">
User name: &nbsp;<input type="text" name="user"><br>
User type: &nbsp; <select name=type>
<option value=user>USER</option>
<option value=mod>MOD</option>
<option value=admin>ADMIN</option>
<option value=frozen>FROZEN</option>
</select>
<input type="submit" value="Submit" name="submit">

</form>

EOT;
}
else{
$user = $_POST['user'];
$type = $_POST['type'];
$sql = mysql_query("INSERT INTO user (type)
		VALUES('$type') WHERE user='$user'");
if($sql){
    echo $user." was changed to or has become:  ".$type;
}
elseif(!$sql){
    echo $user." was not changed";
}
else{
    echo "Problem executing the script!";
}

}
in case you cant tell i want to change the "type" field where "user" is equal to $user, i don't think what i have is right....or if it is i got some problems

does anybody know how to do this?

Posted: Thu Jan 22, 2004 3:22 pm
by markl999
UPDATE user SET type='$type' WHERE user='$user'

Posted: Thu Jan 22, 2004 3:25 pm
by DuFF
Instead of INSERT you want to use UPDATE, try this out:

Code: Select all

<?php
$sql = mysql_query("UPDATE user SET type='$type' WHERE user='$user'");
?>
Edit:
Damn you Mark :P

Posted: Thu Jan 22, 2004 3:29 pm
by dull1554
now my script is this

Code: Select all

if(!isset($_POST['submit'])){
Print <<< EOT

<form method="POST" action="index.php?l=admin.php&admin=usertype">
User name: &nbsp;<input type="text" name="user"><br>
User type: &nbsp; <select name=type>
<option value=user>USER</option>
<option value=mod>MOD</option>
<option value=admin>ADMIN</option>
<option value=frozen>FROZEN</option>
</select>
<input type="submit" value="Submit" name="submit">

</form>

EOT;
}
else{
$user = $_POST['user'];
$type = $_POST['type'];
$sql = mysql_query("UPDATE users SET type='$type' WHERE user='$user'");
if($sql){
    echo $user." was changed to or has become:  ".$type;
}
elseif(!$sql){
    echo $user." was not changed";
}
else{
    echo "Problem executing the script!";
}

}
but it still returns user type not changed, and i checked my database and nothing has changed

Posted: Thu Jan 22, 2004 3:31 pm
by markl999
$sql = mysql_query("UPDATE users SET type='$type' WHERE user='$user'") or die(mysql_error());

Posted: Thu Jan 22, 2004 3:31 pm
by DuFF
Hmm, try seeing what the MySQL error is:

Code: Select all

<?php
$sql = mysql_query("UPDATE users SET type='$type' WHERE user='$user'") or die("Query error: mysql_error()");
?>
Edit:
AGAIN! Grrr :twisted:

Posted: Thu Jan 22, 2004 3:34 pm
by markl999
:?

Posted: Thu Jan 22, 2004 3:40 pm
by dull1554
i swear i need to sleep, it returned unknown colum name, so i checked the database, when i created the database rether the "user" i had "usr"

so it works super now.....thanks a mill guys