Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jul 18th, 2011  |  syntax: PHP  |  size: 1.12 KB  |  views: 63  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.         $con = mysql_connect("localhost","myuser","mypass");
  3. if (!$con)
  4.   {
  5.   die('Could not connect: ' . mysql_error());
  6.   }
  7.  
  8.     mysql_select_db("mydb", $con);
  9.     if(!isset($_POST['submit'])){
  10.         $q = "SELECT * FROM person WHERE id = $_GET[id]";
  11.         $result = mysql_query($q) or die(mysql_error());
  12.         $person = mysql_fetch_array($result);
  13.         }
  14. ?>
  15.  
  16. <h1>You are Modifying A Record</h1>
  17.   <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  18.         Name:<input type="text" name="myname" id="myname" value ="<?php echo $person['name']; ?>" /> <br />
  19.         Description: <input type="text" name="mydescription" id="mydescription" value ="<?php echo $person['description']; ?>" /> <br />
  20.         <input type="hidden" name="id" value="<?php echo $_GET['id']; ?>" />
  21.         <input type="submit" name="submit" value="Modify" />
  22.  
  23. </form>
  24.  
  25. <?php
  26.   if(isset($_POST['submit'])){
  27.         $q = "UPDATE person SET `name`='$_POST[myname]', `description`='$_POST[mydescription]' WHERE id = $_POST[id]";
  28.          mysql_query($q) or die(mysql_error());
  29.      //header('Location: select.php');
  30.          echo 'User has been modified successfully!';
  31.      }else{
  32.  
  33.      }
  34. ?>