Page 1 of 1

PHP Still inserts data even if the condition is not met (IE)

Posted: Thu Jan 11, 2007 3:44 am
by php_ghost
Hi guys i'm having this weird problem in php / IE. I have a page with a form and text boxes and when I click the submit button, It will be posted to a second php page which contains this code.
It all works fine in firefox however.
What could possibly be wrong with my code? Please help me guys. I've been stuck in the office trying to figure this one out.
Thanks. ^_^

Code: Select all

<?
require_once("../../common/include.php")
include_once("../../lib/functions.lib.php")
include_once("postVar.php");

$query = "SELECT * from $default_table_accounts WHERE loginemail='$loginemail'";
$result = db_query($query) or die(db_error());

if(db_num_rows($result)) {
include_once("hiddenFields.php");
-- go back to previous page --
} else {

$password = generate_password();
$refcode = generate_refcode();
$applicationdate = date("Y-m-d H:i:s");

$querystr  = "INSERT INTO $default_table_accounts (professionalcapacity,operationarea,country,desiredstartingdate,desiredsalary,firstname,
middlename,lastname,gender,birthdate,maritalstatus,nationality,phonenum,username,loginemail,password,address,zipcode,city,homecountry,applicationdate,regstatus,refcode) VALUES ";
$querystr .= "('$professionalcapacity','$operationarea','$country','$desiredstartingdate','$desiredsalary','$firstname'
,'$middlename','$lastname','$gender','$birthdate','$maritalstatus','$nationality','$phonenum','$loginemail','$loginemail','$password','$address','$zipcode','$city','$homecountry','$applicationdate','I','$refcode')";
$querystr .= db_query($querystr) or die(db_error()); 
 
 
}
?>

Posted: Thu Jan 11, 2007 4:01 am
by GM
Why are you using PHP tags on every line of code?????

Code: Select all

<?php
   //all you code ;
   // goes here ;
   //on various lines ;
   // ended with semicolons ;
   // and then, at the end ;
   // you close the php tag ;
?>
The problem is probably on the page with your form on it rather thean the page which inserts the data.

Posted: Thu Jan 11, 2007 4:10 am
by dibyendrah
check the db_num_rows($result) value.

Posted: Thu Jan 11, 2007 4:21 am
by php_ghost
but it all works fine in firefox.

What it does when I'm in IE is it executes the data insertion first before reading the if / else statement.

But when I just use echo for both conditions it works fine.

Posted: Thu Jan 11, 2007 6:58 am
by GM
PHP doesn't care much about what browser you use - it runs on the server, and so is oblivious to the browser. This means that if for some reason you are getting different results with different browsers, it generally means that you have a problem in your HTML or javascript on the calling page.

I'd check what's going on in your hiddenfields.php include for starters.

Posted: Thu Jan 11, 2007 8:16 am
by volka
print and check the query

Code: Select all

$query = "SELECT * FROM $default_table_accounts WHERE loginemail='$loginemail'";
echo '<div>Debug: ', $query, "</div>";
$result = db_query($query) or die(db_error());