jesushax Posted March 26, 2009 Share Posted March 26, 2009 hi all below is my code ive commented out the mysql becuase i dont want an more info being inserted into my db for now but i tried inputting the same postcode as the one record that already has been added to the db and i just get taken to register.php?action=part1 and the sql statement the if statement to check the domain and the postcode isnt working as i see it and the lower if statement to referr to part 2 isnt working either becuase it should been executed if the first if statement didnt work? also for the postcode check if already got it turning to uppercase is theere a way i can remove all spaces too? thanks $email = $_POST["Sect1_6"]; $error = mysql_query("SELECT `Sect1_6`,`Sect1_7d`,`CompanyID` FROM tblDirectory2 WHERE `Sect1_6`='$email'") or die(mysql_error()); $errorID = mysql_fetch_array($error); $emailcheck = $errorID["Sect1_6"]; list($name, $domain) = explode("@", $email); list($name, $domaincheck) = explode("@", $emailcheck); $postcode = strtoupper($_POST["Sect1_7d"]); $postcodecheck = strtoupper($errorID["Sect1_7d"]); if ($domaincheck == $domain || $postcodecheck == $postcode) { header("Location: /new_directory/completed.php?ID=".$errorID["CompanyID"].""); exit(); } $posts = $_POST; unset($posts['password']); unset($posts['password2']); for($i=1; $i<=21; $i++) { unset($posts['T'.$i]); } $SQL = "INSERT INTO tblDirectory2 ("; foreach($posts as $key=>$value){ $SQL .= "`$key`, "; } $SQL .="`Sect1_2`,`password`) VALUES ("; foreach($posts as $key=>$value){ $SQL .= "'$value', "; } $const = "T" ; for ($i=1;$i<=21;$i++){ $var = trim($_POST[$const.$i]) ; if(!empty($var)) { $trades .= $_POST[$const.$i] . "," ; } } $SQL .="'".mysql_escape_string($trades)."','".md5($_POST["password"])."')"; echo $SQL; //mysql_query($SQL) or die (mysql_error()); $Company = mysql_query("SELECT `CompanyID` FROM tblDirectory2 WHERE `Sect1_6`='$email'") or die(mysql_error()); while ($ID = mysql_fetch_array($Company)) { header("Location: /new_directory/regform_sect2.php?ID=".$ID["CompanyID"].""); exit(); } Link to comment https://forums.phpfreaks.com/topic/151218-my-error-checking-php-isnt-working/ Share on other sites More sharing options...
taquitosensei Posted March 26, 2009 Share Posted March 26, 2009 If you're going to get more than 1 result. If Sect1_6 isn't a unique index. Then you need to loop through the mysqlresults. But that doesn't quite work with the header redirection. list($name, $domain) = explode("@", $email); $error = mysql_query("SELECT `Sect1_6`,`Sect1_7d`,`CompanyID` FROM tblDirectory2 WHERE `Sect1_6`='$email'") or die(mysql_error()); $errorID = mysql_fetch_array($error); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $emailcheck=$row['Sect1_6']; list($name, $domaincheck) = explode("@", $emailcheck); $postcode = strtoupper($_POST["Sect1_7d"]); $postcodecheck = strtoupper($errorID["Sect1_7d"]); if ($domaincheck == $domain || $postcodecheck == $postcode) { header("Location: /new_directory/completed.php?ID=".$errorID["CompanyID"].""); exit(); } [/code] I would also put the code exploding $email outside of the loop so that you're not exploding it every instance through the loop. If it's going to be a single result then this would probably get you close $email = $_POST["Sect1_6"]; $error = mysql_query("SELECT `Sect1_6`,`Sect1_7d`,`CompanyID` FROM tblDirectory2 WHERE `Sect1_6`='$email'") or die(mysql_error()); $errorID = mysql_fetch_array($error,MYSQL_NUM); // This gives you a numeric indexed array $emailcheck = $errorID[0]["Sect1_6"]; // notice the 0 list($name, $domain) = explode("@", $email); list($name, $domaincheck) = explode("@", $emailcheck); $postcode = strtoupper($_POST["Sect1_7d"]); $postcodecheck = strtoupper($errorID[0]["Sect1_7d"]); // Notice the 0 if ($domaincheck == $domain || $postcodecheck == $postcode) { header("Location: /new_directory/completed.php?ID=".$errorID["CompanyID"].""); exit(); } Link to comment https://forums.phpfreaks.com/topic/151218-my-error-checking-php-isnt-working/#findComment-794377 Share on other sites More sharing options...
jesushax Posted March 26, 2009 Author Share Posted March 26, 2009 i tried the code suggested and the redirects still dont work :| heres the code now case "part1"; $email = $_POST["Sect1_6"]; $error = mysql_query("SELECT `Sect1_6`,`Sect1_7d`,`CompanyID` FROM tblDirectory2 WHERE `Sect1_6`='$email'") or die(mysql_error()); $errorID = mysql_fetch_array($error,MYSQL_NUM); // This gives you a numeric indexed array $emailcheck = $errorID[0]["Sect1_6"]; // notice the 0 list($name, $domain) = explode("@", $email); list($name, $domaincheck) = explode("@", $emailcheck); $postcode = strtoupper($_POST["Sect1_7d"]); $postcodecheck = strtoupper($errorID[0]["Sect1_7d"]); // Notice the 0 if ($domaincheck == $domain || $postcodecheck == $postcode) { header("Location: /new_directory/completed.php?ID=".$errorID["CompanyID"].""); exit(); } $posts = $_POST; unset($posts['password']); unset($posts['password2']); for($i=1; $i<=21; $i++) { unset($posts['T'.$i]); } $SQL = "INSERT INTO tblDirectory2 ("; foreach($posts as $key=>$value){ $SQL .= "`$key`, "; } $SQL .="`Sect1_2`,`password`) VALUES ("; foreach($posts as $key=>$value){ $SQL .= "'$value', "; } $const = "T" ; for ($i=1;$i<=21;$i++){ $var = trim($_POST[$const.$i]) ; if(!empty($var)) { $trades .= $_POST[$const.$i] . "," ; } } $SQL .="'".mysql_escape_string($trades)."','".md5($_POST["password"])."')"; echo $SQL; //mysql_query($SQL) or die (mysql_error()); $Company = mysql_query("SELECT `CompanyID` FROM tblDirectory2 WHERE `Sect1_6`='$email'") or die(mysql_error()); while ($ID = mysql_fetch_array($Company)) { header("Location: /new_directory/regform_sect2.php?ID=".$ID["CompanyID"].""); exit(); } break; Link to comment https://forums.phpfreaks.com/topic/151218-my-error-checking-php-isnt-working/#findComment-794380 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.