Reputation: 21
I would like to create page that if someone has already entered their data it redirect them to a page where it says 'sorry you have already made your selection'. The easiest field would be attendance1 where the value is either a 'Yes' or a 'No' so if it is either one of these values it will redirect to the page i want. Code for my page is here: http://pastebin.com/1D6PrmBv
Upvotes: 1
Views: 258
Reputation: 427
include('connect.inc');
if (isset($rows['food'])) {
header(location: mypagelocation.html');
exit;
}
else{
// $rows['food'] is not set
}
Upvotes: 2
Reputation: 1512
Full Code:
<?php
session_start();
require_once("connect.inc");
if(!isset($_SESSION['username'])){
header('Location: connect.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: redirect_page.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 gender= '" . mysql_real_escape_string($_POST['gender']) . "' WHERE username = '" . mysql_real_escape_string($_SESSION['username']) . "'";
mysql_query($sql) or die("Error in SQL: " . mysql_error());
header("Location: index.html", true, 303); // Look up "303: See Other"
exit;
}
?>
Upvotes: 0
Reputation: 6180
Try this.
include('connect.inc');
if (( $rows['food'] == "yes" ) || ( $rows['food'] == "no" )) {
header('location: mypagelocation.html');
exit;
}
or you can write it this way too.
include('connect.inc');
if (in_array($rows['food'], array("yes","no"))) {
header('location: mypagelocation.html');
exit;
}
Upvotes: 2
Reputation: 37711
include('connect.inc');
if ( $rows['food'] == "yes" OR $rows['food'] == "no" ) {
header('location: mypagelocation.html');
}
Make sure there is no output before that.
Upvotes: 1