Jump to content

[SOLVED] need help with php logic


rondog

Recommended Posts

Ok my script is somewhat working. I've made a quiz in flash and every time you enter a wrong answer, it stores it in an array. If I submit the data once everything is answered correctly, it echoes "success". If I answer everything correctly first time around meaning the wrong answer array is empty, it echoes "error"

 

Can anyone see what I am doing wrong?

<?php
include 'connect.php';
$done = false;
$title = $_POST['theTitle'];
$name = $_POST['theName'];
$account = $_POST['theCurAct'];
$subtitle = $_POST['theSubTitle'];
$address1 = $_POST['theAdd1'];
$address2 = $_POST['theAdd2'];
$city = $_POST['theCity'];
$state = $_POST['theState'];
$zip = $_POST['theZip'];
$phone = $_POST['thePhone'];
$email = $_POST['theEmail'];
$testNum = $_POST['theTestNumber'];
//wrong answer array
$wrongAnswers = $_POST['wrongs'];
$wrongAnswers_arr = explode(",",$wrongAnswers);
$done = true;
if($done == true) {
if($account == 'no') {
	$sql1 = mysql_query("INSERT INTO users (title,name,subtitle,address1,address2,city,state,zip,phone,email) VALUES ('$title','$name','$subtitle','$address1','$address2','$city','$state','$zip','$phone','$email')");
	if($wrongAnswers != "") {
		foreach($wrongAnswers_arr as $wa) {
			$accountWasNo = true;
			$sql2 = mysql_query("INSERT INTO tests (testNum,testQuestion) VALUES ('$testNum','$wa')");
		}
	}
} else {
	if($wrongAnswers != "") {
		foreach($wrongAnswers_arr as $wa) {
			$accountWasYes = true;
			$sql2 = mysql_query("INSERT INTO tests (testNum,testQuestion) VALUES ('$testNum','$wa')");
		}
	}
}
if($accountWasNo == true) {
	echo "&msgText=Success";
	$headers = "From: [email protected]\r\n";
	$headers.= "Content-Type: text/html; charset=ISO-8859-1 ";
	$headers .= "MIME-Version: 1.0 ";
	$msg = "Hello $firstName $lastName,<br/>";
	$msg .= "We would like to thank you for joining our web site.<br/>";
	$msg .= "Please enjoy it and if you have any questions, contact us at <a href=\"mailto:[email protected]\">[email protected]</a>.";
	mail($email,"**SynergEyes Practice Prescribe It! Certification**",$msg,$headers);
} elseif($accountWasYes == true) {
	echo "&msgText=Success";
} else {
	echo "&msgText=Error";
}
}
?>

 

just a little info, account = yes will insert the users data and account = no will not enter their information, just the answers they got wrong..if they got any wrong.

Link to comment
https://forums.phpfreaks.com/topic/80312-solved-need-help-with-php-logic/
Share on other sites

Well the reason you are getting message of Error is because accountwasyes and accountwasno are only assigned when there are wrong answers ($wrongAnswers != "").  So it falls under the else.  

 

Not sure if you are asking anything else or not.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.