Blank page help


#1

Hi all from phphelp.com

I really need some help in here

I am setting up a registering php page wif the codes below

[php]

<?php //check form is submit if(isset ($_POST['submitted'])){ require_once ('mysql_connect.php'); //conect to db // create escape funcion function escape_data ($data) { global $dbc; //nid connect if (ini_get('magic_quotes_gpc')){ $data=stripslashes($data); } return mysql_real_escape_string(trim($data),$dbc); }// end function $errors=array(); //ini error // check email if (empty($_POST['email'])){ $error[] ='you forgt ur email'; }else { $e = escape_data($_POST[['email']); } if (empty($_POST['Fname'])){ $error[] ='you forgt ur first name'; }else { $fn= escape_data($_POST[['Fname']); } if (!empty($_POST['Lname'])){ $error[] ='you forgt ur last name'; }else { $ln = escape_data($_POST[['Lname']); } // check pass and compass if (!empty($_POST['password1'])){ if ($_POST['password1'] != $_POST['password2']){ $error[] ='Your pass dont match'; }else { $p = escape_data($_POST[['password1']); } }else { $error[] ='Your have forgt your password'; } if (empty($errors)){ // all ok //check pervious regi $query = "SELECT email FROM testdb WHERE email='$e'"; $result = mysql_query($query); if (mysql_num_rows($result) == 0){ // make the query $query="INSERT INTO testdb (email,first_name,last_name,password,registration_date) VALUES ('$e','$fn','$ln',SHA('$p'),NOW())"; $result=mysql_query($query); //run the query if ($result){ //if ran ok //print mssg echo ' THANK you ,Your are now registed'; exit(); }else{ //no run ok echo 'u are nt regi due to sys error'; //echo .mysql_error(). '

QUERY:' .$query.'

'; exit(); } }else{ //alredy regi echo' the email had already been regi'; } }else{ // report error echo'

ERROR!!!!!!

the following error(S) occured:
'; foreach ($errors as $msg) { //print each error echo" - $msg
n"; } echo'please try again'; } // end of if ( mysql_close(); // close DB } ?>

REGISTER

E-mail:




First name::




Last name:




Password:





Comfirm Password:


[/php]

But i kept getting a blank page when i wanted to view it through http://localhost/
can anyone help me solve this problem ?

Details

-These codes are taken from Larry ULLMAN PHP and MYSQL
-I am using a IIS 5.1 for my PHP
-My sql 4.1
-Database is call “testdb”
-I have a page to store my SQL connection call “mysql_connect.php”

[php]

<?php //Files contain My SQL connection //database information DEFINE ('DB_USER','username"'); DEFINE ('DB_PASSWORD','databasepass'); DEFINE ('DB_HOST','localhost'); DEFINE ('DB_NAME','testdb'); //conecting to MYSQL $dbc=@mysql_connect(DB_USER,DB_PASSWORD,DB_HOST) OR die ('could Not connect to MySQL:'.mysql_error()); //select database $dbc=@mysql_connect(DB_NAME) OR die ('could Not connect to MySQL:'.mysql_error()); //create functionfor escaping data function escape_data($data){ //address magic quotes if (ini_get('magic_quotes_gpc')){ $data=stripslashes($data); } // check for my sql_real_escape_strings() support if (function_exists('mysql_real_escape_strings')) { global $dbc; //nid the connection $data=my sql_real_escape_strings(trim($data),$dbc); }else{ $data=my sql_real_escape_strings(trim($data)); } //return escape data return $data } //end of function ?>

[/php]

Thank you all very much

lyjim

Mod Edit: Changed [code] tags to [php] tags.


#2

Third-party script. Did you try contacting the author of this script?


#3

Hi

I’m quite new to PHP itself … what do you mean by Third party script?

These codes was from the book

if this script is not workable … is there a script which work ?

All i just wanted to do was to created a registering page which will validate the form and send the data over to MYSQL

Thanks


#4

Ah, it’s from a book. I thought you got it from a website or through someone. That’s why I said it was a third-party script. Now, have you tried Debugging?


#5

i had to work with MySQL on an IIS once. and had to use the mysqli functions instead of mysql once. (don’t know wether that aplies to u as well)

to find out:
remove all @ signs form your script and u should get a fatal error: mysql_connect is not defined (or something like that)

if it is that way:
then you just have to change all mysql_ to mysqli_ and then add the mysqlilink to all querys.

[php]
//conecting to MYSQL
$mysqlilink=@mysqli_connect(DB_USER,DB_PASSWORD,DB_HOST) OR die (‘could Not connect to MySQL:’.mysql_error());
//select database
@mysqli_connect($mysqlilink,DB_NAME) OR die (‘could Not connect to MySQL:’.mysql_error());
[/php]

and any query will be mysqli_query($mysqlilink,‘INSERT …’);

hope this helps
Q


#6

Whether to use mysql or mysqli depends on the installed module :wink: php.ini will help you out on that one as well, and I don’t think it’s IIS specific (though I could be wrong).

Besides that, your mysql(i) functions don’t require a resource identifier to be passed as a parameter (at least, most don’t), they just want an opened connection available. If no identifier is passed, the last (?) opened connection will be used. Naturally, it’s best to pass the identifier to force the action to be run against a defined connection (especially when dealing with multiple mysql connections this is preferrable), but it’s not mandatory.


#7

It is already some while ago. but there was no mysql-functions implementation for IIS.
Maybe there is now.

The big syntax diffrence between the mysql- and mysqli-functions is that the mysql-functions have the connection idenefier as last optional parameter, the mysqli-functions have it as first parameter (so it is mandatory, can’t be realy optional but i never tryed to use NULL).


#8

I presume NULL won’t get you anything but a fatal error though, because in most cases an open connection to a server is mandatory. And IIS (a webserver) and MySQL (database server/PHP module) are two different things entirely, which are, as far as I know, unrelated.


#9

@lyjim:
i still don’t konow where that was your problem.
but if it was take a look at:
http://www.phphelp.com/forum/index.php?topic=7475.0


#10

ya i found out that IIS dont support MYSQL function very well … i try to upload the whole database and codes up to sever to test

Thank you all for the nice reply


#11

if i try to configure everything into IIS sever … dont it make the Codes weird and not supported when i upload it up to a php domain ?

Well anyway i try the debugging … but it does not help in anyway … right now i trying to install apache and PHP 5 to see if anything good or bad happen… hope it will helps …


#12

Hi all … i have happen to done the validation and is now trying to do the DB connect which is at MyPHPadmin … it kept telling me “could Not connect to MySQLDB:” as it what i want it to tell me … but the .mysql_error()); part is not showing

just

could Not connect to MySQLDB:

[php]

connecting DATABASE <?php //Files contain My SQL connection

//database information

$HOST=“something.something.net”;
$USER=“login ID for my PHPadmin”;
$PASSWORD=“lpassword for my PHPadmin”;
$db_name=“My database name not table name”;

//conecting to MYSQL
$dbc=mysql_connect($HOST,$USER,$PASSWORD) OR die (‘could Not connect to MySQL:’.mysql_error());
//select database
$dbc=mysql_connect($db_name) OR die (‘could Not connect to MySQLDB:’.mysql_error());

//create functionfor escaping data
function escape_data($data){

//address magic quotes

if (ini_get(‘magic_quotes_gpc’)){
$data=stripslashes($data);
}

// check for my sql_real_escape_strings() support

if (function_exists(‘mysql_real_escape_strings’)) {
global $dbc; //nid the connection
$data=mysql_real_escape_strings(trim($data),$dbc);
}else{
$data=mysql_real_escape_strings(trim($data));
}
//return escape data
return $data;
}
//end of function
?>

[/php]

Can anyone point me the error ?

PS: the previous problem was solve when i change to apache and PHP5…
Seems like IIS does not like PHP5

Mod Edit: Changed [code] tags to [php] tags.


#13

sorry to kept posting on my problems here … here the newest problem

i change the way the database are connected

from

[php]

$HOST=“something.something.net”;
$USER=“login ID for my PHPadmin”;
$PASSWORD=“lpassword for my PHPadmin”;
$db_name=“My database name not table name”;

$dbc=mysql_connect($HOST,$USER,$PASSWORD) OR die (‘could Not connect to MySQL:’.mysql_error());
//select database
$dbc=mysql_connect($db_name) OR die (‘could Not connect to MySQLDB:’.mysql_error());

[/php]

to

[php]
$dbc=mysql_connect(something.something.net,login ID for my PHPadmin,password for my PHPadmin) OR die (‘could Not connect to MySQL:’.mysql_error());
//select database
$dbc=mysql_connect(My database name not table name) OR die (‘could Not connect to MySQLDB:’.mysql_error());

[/php]

making it no longer predefine … it now have no more error message …
But even so … now im back to square one … this time with validation. As now my validation is printed on the page itself … so i kw there is validation done

But after that … BLANK PAGE
… i check my database on MYPHPADMIN … nothing was inserted …
I had try to do a simple inserting of data to MYPHPADMIN … it was also a blank page …

can anyone point me into the right way ?

Mod Edit: Changed [code] tags to [php] tags.


#14

oh ya the form page is change to

[php]

PHP User Registration Form Example

<? // only validate form when form is submitted if(isset($_POST["submit_button"])){ $error_msg=''; if(trim($_POST["username_input"])=='' || strlen(trim($_POST["username_input"])) < 6 || strlen(trim($_POST["username_input"])) > 15) { $error_msg.="Please enter a username between 6 to 15 characters long
"; } if(trim($_POST["password_input"])=='' || strlen(trim($_POST["password_input"])) < 4) { $error_msg.="Please enter a password at least 4 characters long
"; } if (!empty($_POST['password_input'])){ if ($_POST['password_input'] != $_POST['cpassword_input']){ $error_msg.="your password dont match
"; } } if(trim($_POST["email_input"])=='') { $error_msg.="Please enter an email
"; } else { // check if email is a valid address in this format username@domain.com if(!ereg("[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\.[a-z]", $_POST["email_input"])) $error_msg.="Please enter a valid email address
"; } // display error message if any, if not, proceed to other processing if($error_msg==''){ require_once ('mysql_connect.php'); //check pervious regi $query = "SELECT DB_Email FROM members WHERE email='$e'"; $result = mysql_query($query); if (mysql_num_rows($result) == 0){ // make the query $query="INSERT INTO members (DB_Email,DB_First_name,DB_Last_name,DB_Password) VALUES ('$email_input','$first_name_input','$last_name_input',SHA('$password_input') )"; $result=mysql_query($query); //run the query if ($result){ //if ran ok //print mssg echo ' THANK you ,Your are now registed'; exit(); }else{ //no run ok echo 'u are nt regi due to sys error'; exit(); } }else{ //alredy regi echo' the email had already been regi'; } } else { echo "$error_msg"; } } ?>
First Name
Last Name
Username (between 6 to 15 characters)
Password (must be at least 4 characters)
comfirm Password (Please Reenter your password)
Email

[/php]

is there anything wrong ?

Mod Edit: Changed [code] tags to [php] tags.


#15

First of all, I changed your [code] tages to [php] tags to enable highlighting. Makes it easier for all of us.

The next line:
[php]$dbc=mysql_connect(My database name not table name) OR die (‘could Not connect to MySQLDB:’.mysql_error());[/php]

This is not the way to connect to a database. See mysql_select_db() in the PHP manual for more info.

the next line:
[php]$query = “SELECT DB_Email FROM members WHERE email=’$e’”; [/php]

Where do you define the $e variable? I presume you’ve read the part about error_reporting(E_ALL) in Debugging? Error reporting should have picked that one up. I see more uninitialized variables throughout your code.


#16

Thank you all for the great help … finally solved the problem .

The problem was wat zyppora pointed out … alot of undefine Values being use and also the
[php]

$dbc=mysql_connect(My database name not table name) OR die (‘could Not connect to MySQLDB:’.mysql_error());
[/php]

should be

[php]

$dbc=mysql_select_db(My database name not table name) OR die (‘could Not connect to MySQLDB:’.mysql_error());
[/php]

Very bad mistake error on my fault

Thank you all