<?PHP
include("dbinfo.php");
if($_POST['save'])
{ // Checks if the users submitted
$db = @mysql_connect($dbhost, $dbuser, $dbpasswd); // Connects to the Database
@mysql_select_db($dbname, $db) or die("mysql_error()"); // Selects the Database stored in the variable $dbname
$query = @mysql_query("UPDATE `studiojaymz_staff` SET `staffid` = " . $_POST['staffrank'] . ", `job` = " . $_POST['job'] . ", `bio` = " . $_POST['bio'] . " WHERE `username` = " . $_POST['username'] . " LIMIT 1;");
if($query){echo"<font color='00cc00' />Success!</font>";}else{echo"<font color='cc0000' />Failure</font>";}
print"<br>Username: $username";
print"<br>DB Identifyer: $db";
print"<br>Staff Rank: $staffrank";
print"<br>Job: $job";
print"<br>Bio: $bio";
// Update Function
} else { // If the the user just opened it, execute the commands bellow
print("
<form action='test.php' method='post'>
<table width='100%' border='0' cellspacing='2' cellpadding='2'>
<tr>
<td>Username:</td>
<td><select name='username' size='1' value='username'>
<option value='Jaymz' selected>Jaymz</option>
<option value='Aklix'>Aklix</option>
<option value='Raimundo'>Raimundo</option>
</select></td>
</tr>
<tr>
<td>Staff Rank:</td>
<td><input name='staffrank' type='text' id='staffrank' size='3'></td>
</tr>
<tr>
<td>Job:</td>
<td><input name='job' type='text' id='job'></td>
</tr>
<tr>
<td width='10%'>Bio:</td>
<td width='90%'><textarea name='bio' cols='50' rows='5' wrap='VIRTUAL'></textarea></td>
</tr>
</table>
<p align='center'>
<input type='submit' name='save' value='Submit'>
<input type='reset' name='clear' value='Clear'>
</p>
</form> ");
} // End If
mysql_close();
?>
Updating Table with a PHP Form...
Started by Jaymz, Sep 29 2004 05:05 PM
3 replies to this topic
#1
Posted 29 September 2004 - 05:05 PM
This script just won't work for me... it was written by my site's coder who also can't figure it out... Basically I want it to change the staff stuff... you can see the script in action at http://www.studiojaymz.com/test.php go ahead submit something it won't work anyways....
#2
Posted 29 September 2004 - 05:42 PM
looks like an you've executed your query incorrectly, try a while statement instead, its much easier
#3
Posted 29 September 2004 - 08:39 PM
Right here:
I'd just change it to:
I just find it easier with the variables. That's what I do for my site. It should work... Try it and post the error if it doesn't work or I missed something.
$query = @mysql_query("UPDATE `studiojaymz_staff` SET `staffid` = " . $_POST['staffrank'] . ", `job` = " . $_POST['job'] . ", `bio` = " . $_POST['bio'] . " WHERE `username` = " . $_POST['username'] . " LIMIT 1;");
I'd just change it to:
$job = $_POST['job'];
$staffrank = $_POST['staffrank'];
$bio = $_POST['bio'];
$username = $_POST['username'];
$query = mysql_query("UPDATE `studiojaymz_staff` SET `staffid` = '$staffrank', `job` = '$job', `bio` = '$bio' WHERE `username` = '$username' LIMIT 1;") or die(mysql_error());
I just find it easier with the variables. That's what I do for my site. It should work... Try it and post the error if it doesn't work or I missed something.
#4
Posted 30 September 2004 - 05:19 PM
Thanks everyone, that solved the problem
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
