validate check?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • up2trouble

    #1

    validate check?

    Currently, it checks to see if id is in db. If it is, it takes the
    user to the survey. If not it takes the user to a page to try re-
    entering code. I want to add another option. I want it to check and
    see if the classid field in the db is empty if it is not empty, I want
    it to go to a page saying survey has already been taken. How do I do
    this? I tried a compunf if statement but it didn't work.

    <?PHP
    $FAIL = "surveyfailed.p hp";
    $FAIL2 = "surveyfailed2. php";
    $TRY = "surveyq.ph p";

    if(isset($_POST['entersurvey']))
    {
    $id = $_POST['id'];
    $class = $_POST['course'];

    $sql = "SELECT * FROM $db_table10 WHERE id = '$id'";
    $result = mysql_query ($sql, $connect) or die('Query 4 failed: ' .
    mysql_error());
    $num = mysql_num_rows( $result);

    if ($num == 0)
    {
    echo "<meta http-equiv='Refresh' content='1;url= $FAIL'>";
    }
    else
    {
    $passid = $id;
    $passcid = $class;
    $_SESSION['passid'] = $passid;
    $_SESSION['passcid'] = $passcid;
    echo "<meta http-equiv='Refresh' content='1;url= $TRY'>";
    }
    }
    ?>
  • Rik Wasmus

    #2
    Re: validate check?

    On Thu, 15 May 2008 05:37:52 +0200, up2trouble <lynettesmith@g mail.com
    wrote:
    Currently, it checks to see if id is in db. If it is, it takes the
    user to the survey. If not it takes the user to a page to try re-
    entering code. I want to add another option. I want it to check and
    see if the classid field in the db is empty if it is not empty, I want
    it to go to a page saying survey has already been taken. How do I do
    this? I tried a compunf if statement but it didn't work.
    >
    <?PHP
    $FAIL = "surveyfailed.p hp";
    $FAIL2 = "surveyfailed2. php";
    $TRY = "surveyq.ph p";
    >
    if(isset($_POST['entersurvey']))
    {
    $id = $_POST['id'];
    $id = isset($_POST['id']) ? mysql_real_esca pe_string($_POS T['id']) : '';
    $class = $_POST['course'];
    >$sql = "SELECT * FROM $db_table10 WHERE id = '$id'";
    $sql = "SELECT classid FROM $db_table10 WHERE id = '$id'"
    $result = mysql_query ($sql, $connect) or die('Query 4 failed: ' .
    mysql_error());
    Don't die() with an internal error (mysql_error()) in production, provide
    a nice 'something went wrong and we're sorry'-page.
    $num = mysql_num_rows( $result);
    if ($num == 0)
    {
    echo "<meta http-equiv='Refresh' content='1;url= $FAIL'>";
    header() redirects are more reliable & better overall.
    header('Locatio n: http://'.$_SERVER['HTTP_HOST'].'/'.$FAIL);
    }
    else
    $row = mysql_fetch_ass oc($result);
    if(empty($row['classid'])){
    header('Locatio n: http://'.$_SERVER['HTTP_HOST'].'/'.$FAIL2);
    exit;
    } else {
    $_SESSION['passid'] = $id;
    $_SESSION['passcid'] = $class;
    session_write_c lose();
    header('Locatio n: http://'.$_SERVER['HTTP_HOST'].'/'.$TRY);
    exit;
    }
    }
    {
    $passid = $id;
    $passcid = $class;
    $_SESSION['passid'] = $passid;
    $_SESSION['passcid'] = $passcid;
    echo "<meta http-equiv='Refresh' content='1;url= $TRY'>";
    }
    }
    ?>


    --
    Rik Wasmus
    [SPAM] Now temporarily looking for some smaller PHP/MySQL projects/work to
    fund a self developed bigger project, mail me at rik at rwasmus.nl. [/SPAM]

    Comment

    Working...