Jump to content

Recommended Posts

Hey all, I'm fairly new to PHP and found this message board while I was searching for info.

 

I'm currently working on a dynamic internet survey using PHP and MySQL.  Everything is working great, but there is one thing I'm trying to fix, as the way I'm doing it now doesn't seem very elegant or efficient...

 

Each page of the survey consists of an HTML form with a few questions.  When the form is submitted, the next page in the sequence is loaded, which connects to the database and inserts the results from the previous page.  This is all fine and good when everyone is supposed to get every question, but there is a problem when I have to skip questions based on previous responses. 

 

The only way I've figured out how to do this is to insert a page between questions that does a check on the previous answer given and then redirects them to the proper page.  My code looks something like this:

 

mysql_query("UPDATE data SET game1='$_POST[game1]' WHERE psraid='$id'");
mysql_query("UPDATE data SET game2='$_POST[game2]' WHERE psraid='$id'");

$result=mysql_query("SELECT * FROM data");
while ($row=mysql_fetch_array($result)) {
if ($row['psraid']==$id) {
	if ($row['game1']=="1" || $row['game2']=="1") {
		 $address="page5.php"; }
	else {
		 $address="page8.php"; }
}
else { 
	$address="error.php"; }
}

echo "<meta http-equiv='REFRESH' content='0;url=" . $address ."'>"; 

 

(Before you tell me, I'm aware that $_POSTing directly into a database is bad form)

 

Does anyone have suggestions on how I can possibly get rid of this page and find a way to ask conditional questions in a more direct, elegant fashion? 

 

Thanks for taking the time to read this.

Can sugges to use something like that (that is more algorithm than a gode):

 

<?
// Be ginig of the next page script
if($_POST['var']=="Something"){
  echo "<meta http-equiv='REFRESH' content='0;url=page{$i}.php'>"; 
  exit();
}

?>

 

Sure it will be better to validate the $_POST data.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.