Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 26th, 2012  |  syntax: None  |  size: 2.47 KB  |  hits: 15  |  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. retieve data from mysql and display in form
  2. <?php
  3. session_start();
  4. require_once("config.php");
  5. if(!isset($_SESSION['username'])){
  6.    header('Location: login.php');
  7.    exit;
  8. }else{
  9.     $sql = "SELECT attendance1 FROM user WHERE username = '".mysql_real_escape_string($_SESSION['username'])."'";
  10.     $res = mysql_query($sql);
  11.     $row = mysql_fetch_array($res);
  12.     if(($row[0] == "Yes") || ($row[0] == "No")){
  13.         header("Location: errorsubmit.html");
  14.         exit;
  15.     }
  16. }
  17. if(isset($_POST['submit'])){        
  18.      $sql = "UPDATE user SET attendance1 = '" . mysql_real_escape_string($_POST['attendance1']) . "' WHERE username = '" .  mysql_real_escape_string($_SESSION['username']) . "'";
  19. mysql_query($sql) or die("Error in SQL: " . mysql_error());  
  20.  
  21.    $sql = "UPDATE user SET colour1= '" . mysql_real_escape_string($_POST['colour1']) . "' WHERE username = '" . mysql_real_escape_string($_SESSION['username']) . "'";
  22. mysql_query($sql) or die("Error in SQL: " . mysql_error());  
  23.  
  24.    $sql = "UPDATE user SET shade1= '" . mysql_real_escape_string($_POST['shade1']) . "' WHERE username = '" . mysql_real_escape_string($_SESSION['username']) . "'";
  25. mysql_query($sql) or die("Error in SQL: " . mysql_error());  
  26.  
  27.    header("Location: thanks.html", true, 303);
  28. }
  29. ?>
  30.        
  31. <form>
  32.          <input name="attendance1" type="radio" id="Yes" value="Yes" checked="checked"/>Yes
  33.          <br />
  34. <input name="attendance1" type="radio" id="No" value="No" />No
  35.        </h3></td>
  36.        <td>
  37.               <select name="colour1" id="colour1" >
  38.            <option selected="selected">Please Select</option>
  39.            <option>Red</option>
  40.            <option>White</option>
  41.            <option>Green</option>
  42.          </select>
  43.        </td>
  44.        <td><h3>
  45.                  <select name="shade1" id="shade1" >
  46.            <option selected="selected">Please Select</option>
  47.            <option>light</option>
  48.            <option>heavy</option>
  49.          </select>
  50.        <td>&nbsp;</td>
  51.        <td><label>
  52.          <input type="submit" name="submit" id="button" value="Submit" />
  53.        </label></td>
  54.      </tr>
  55.    </table>
  56.        
  57. <select name="shade1" id="shade1" >
  58.   <option>Please Select</option>
  59.   <option value="light" <?php if($val=='light') echo 'selected'; ?>>light</option>
  60.   <option value="heavy"<?php if($val=='heavy') echo 'selected'; ?>>heavy</option>
  61. </select>
  62.        
  63. <option value="light" >light</option>
  64. <option value="heavy">heavy</option>
  65.        
  66. <option <?php if($row["column_name"] == "light") echo "selected="true""; ?>>light</option>