Jump to content


Photo

Updating Table with a PHP Form...


  • Please log in to reply
3 replies to this topic

#1 Jaymz

Jaymz

    Retired P2L Staff

  • Members
  • PipPipPipPip
  • 4,104 posts

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....

<?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(); 

?>


#2 Jamie Huskisson

Jamie Huskisson

    Retired P2L Staff

  • Members
  • PipPipPipPip
  • 3,648 posts
  • Gender:Male
  • Location:Nottingham, UK

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 Blitz

Blitz

    Jedi In Training

  • Twodded Staff
  • PipPip
  • 307 posts
  • Location:California
  • Interests:Php, html, css, etc, band, trumpet, anime, my dog, TV, computers, video games, sleeping, marching band, sleeping, jazz, sleeping, metal, sleeping, classic rock, sleeping, music, jazz band, did I mention sleeping?, kicking the hell out of kids that won't take the time to spell or use proper grammar, my website, etc.

Posted 29 September 2004 - 08:39 PM

Right here:

  $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 Jaymz

Jaymz

    Retired P2L Staff

  • Members
  • PipPipPipPip
  • 4,104 posts

Posted 30 September 2004 - 05:19 PM

Thanks everyone, that solved the problem :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users