delirium Posted May 1, 2007 Share Posted May 1, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/49548-solved-internet-survey-filtering-questions/ Share on other sites More sharing options...
dzysyak Posted May 1, 2007 Share Posted May 1, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/49548-solved-internet-survey-filtering-questions/#findComment-242949 Share on other sites More sharing options...
john010117 Posted May 1, 2007 Share Posted May 1, 2007 To clean the code up a bit... if($_POST['var']=="Something" { redirect("somewhere.php"); } else { header( 'Location: somewhere.php' ) ; } ?> Oh, and validate the $_POST info. Quote Link to comment https://forums.phpfreaks.com/topic/49548-solved-internet-survey-filtering-questions/#findComment-242994 Share on other sites More sharing options...
delirium Posted May 2, 2007 Author Share Posted May 2, 2007 Thanks, guys! This seems to be working well enough. I'm not sure why I didn't think of it Quote Link to comment https://forums.phpfreaks.com/topic/49548-solved-internet-survey-filtering-questions/#findComment-243011 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.