Jump to content

my error checking php isnt working


jesushax

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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.