- retieve data from mysql and display in form
- <?php
- session_start();
- require_once("config.php");
- if(!isset($_SESSION['username'])){
- header('Location: login.php');
- exit;
- }else{
- $sql = "SELECT attendance1 FROM user WHERE username = '".mysql_real_escape_string($_SESSION['username'])."'";
- $res = mysql_query($sql);
- $row = mysql_fetch_array($res);
- if(($row[0] == "Yes") || ($row[0] == "No")){
- header("Location: errorsubmit.html");
- exit;
- }
- }
- if(isset($_POST['submit'])){
- $sql = "UPDATE user SET attendance1 = '" . mysql_real_escape_string($_POST['attendance1']) . "' WHERE username = '" . mysql_real_escape_string($_SESSION['username']) . "'";
- mysql_query($sql) or die("Error in SQL: " . mysql_error());
- $sql = "UPDATE user SET colour1= '" . mysql_real_escape_string($_POST['colour1']) . "' WHERE username = '" . mysql_real_escape_string($_SESSION['username']) . "'";
- mysql_query($sql) or die("Error in SQL: " . mysql_error());
- $sql = "UPDATE user SET shade1= '" . mysql_real_escape_string($_POST['shade1']) . "' WHERE username = '" . mysql_real_escape_string($_SESSION['username']) . "'";
- mysql_query($sql) or die("Error in SQL: " . mysql_error());
- header("Location: thanks.html", true, 303);
- }
- ?>
- <form>
- <input name="attendance1" type="radio" id="Yes" value="Yes" checked="checked"/>Yes
- <br />
- <input name="attendance1" type="radio" id="No" value="No" />No
- </h3></td>
- <td>
- <select name="colour1" id="colour1" >
- <option selected="selected">Please Select</option>
- <option>Red</option>
- <option>White</option>
- <option>Green</option>
- </select>
- </td>
- <td><h3>
- <select name="shade1" id="shade1" >
- <option selected="selected">Please Select</option>
- <option>light</option>
- <option>heavy</option>
- </select>
- <td> </td>
- <td><label>
- <input type="submit" name="submit" id="button" value="Submit" />
- </label></td>
- </tr>
- </table>
- <select name="shade1" id="shade1" >
- <option>Please Select</option>
- <option value="light" <?php if($val=='light') echo 'selected'; ?>>light</option>
- <option value="heavy"<?php if($val=='heavy') echo 'selected'; ?>>heavy</option>
- </select>
- <option value="light" >light</option>
- <option value="heavy">heavy</option>
- <option <?php if($row["column_name"] == "light") echo "selected="true""; ?>>light</option>