473,386 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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.php";
$FAIL2 = "surveyfailed2.php";
$TRY = "surveyq.php";

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'>";
}
}
?>
Jun 2 '08 #1
1 1135
On Thu, 15 May 2008 05:37:52 +0200, up2trouble <ly**********@gmail.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.php";
$FAIL2 = "surveyfailed2.php";
$TRY = "surveyq.php";

if(isset($_POST['entersurvey']))
{
$id = $_POST['id'];
$id = isset($_POST['id']) ? mysql_real_escape_string($_POST['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('Location: http://'.$_SERVER['HTTP_HOST'].'/'.$FAIL);
}
else
$row = mysql_fetch_assoc($result);
if(empty($row['classid'])){
header('Location: http://'.$_SERVER['HTTP_HOST'].'/'.$FAIL2);
exit;
} else {
$_SESSION['passid'] = $id;
$_SESSION['passcid'] = $class;
session_write_close();
header('Location: 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]
Jun 2 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jim Heavey | last post by:
When should you use the Page.Validate() method? I thought you would use this method if you have some Server side validation (CustomControl's) you wanted to use and this would cause them to be...
4
by: Wysiwyg | last post by:
I need to validate a form to ensure that all of the fields add up correctly. I can't do this while the user is entering data since validation needs to be done after the entry is completed. What's...
8
by: tshad | last post by:
I get the following message from one of my buttons where I have CauseValidation=false. Page.IsValid cannot be called before validation has taken place In my routine I need to do: if Not...
24
by: Mike Hofer | last post by:
Please forgive the cross-post to multiple forums. I did it intentionally, but I *think* it was appropriate given the nature of my question. I'm working on an open source code library to help...
24
by: Mike Hofer | last post by:
Please forgive the cross-post to multiple forums. I did it intentionally, but I *think* it was appropriate given the nature of my question. I'm working on an open source code library to help...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.