Page 1 of 1

Blank page problem

Posted: Wed Oct 15, 2014 12:53 pm
by newbiesher123
Hi! I am quite a newbie in PHP and MySql. Recently I have written some code to connect to my database, it is as follow:

The first page (page1.php) will be a form that will direct the users to another page (page2.php):

Code: Select all

<form action="page2.php" method="post" name="myForm">
// some code
<input type="submit" value="Submit" onClick="location.href='page2.php'">
<input type="reset" value="Reset">
and my code in page2.php:

Code: Select all

<?php
require_once("dbtools.inc.php");
// some code
$link = create_connection();
$sql = some command
$result = execute_sql("database", $sql, $link);
if ($result) {
echo ("succesful"); }
mysql_close($link);
?>
where dbtools.inc.php is :

Code: Select all

<?php
  function create_connection()
  {
    $link = mysql_connect("localhost", "account", "password")
      or die("error<br><br>" . mysql_error());	  		   	
    return $link;
  }
  function execute_sql($database, $sql, $link)
  {
    $db_selected = mysql_select_db($database, $link)
      or die("error<br><br>" . mysql_error($link));					 
    $result = mysql_query($sql, $link);	
    return $result;
  }
?>
When I run my code with localhost on my browser,
after I clicked submit in page1.php,
I got a blank page instead of page2.php,

What is the problem?

Thank you very much for all of your help.

Re: Blank page problem

Posted: Wed Oct 15, 2014 1:16 pm
by requinix
Completely blank? That often indicates a syntax error in your code; check your error logs for a message. You can also change your php.ini to use the settings

Code: Select all

error_reporting = -1
display_errors = on
(restart your web server if you make changes) and you should get those error messages as output so they'll be easier to notice.

If you're still having problems, please post the full code for page2.php. The browser is telling you that you're on page2.php, right? In the address bar?

Re: Blank page problem

Posted: Thu Oct 16, 2014 9:46 am
by newbiesher123
Thank you for your help.

I have done the procedures in php.ini but it is still a blank page.
Yes, the address bar of the browser turns to page2.php, but it is blank.

My full code of page2.php is like:

Code: Select all

<?php
require_once("dbtools.inc.php");
$a = $_POST["a"];
$b = $_POST["b"];
$link = create_connection();
$sql = "INSERT INTO database(A, B) VALUES ('$a', '$b')";
$result = execute_sql("database", $sql, $link);
if ($result) {
echo ("succesful"); }
mysql_close($link);
?>
where a and b are variables got from page1.php and A and B are the two values in the database to store a and b.

Thank you once again.

Re: Blank page problem

Posted: Thu Oct 16, 2014 10:34 am
by Celauran
Have you stepped through the code to determine where it's failing? Also, a blank page when error reporting and displaying are enabled is pretty strange. Have you tried restarting your web server? Sure you set those values in the right place?

Re: Blank page problem

Posted: Sat Oct 18, 2014 4:22 am
by newbiesher123
I have done the settings in the second reply.

Are there any other settings that I should pay attention on such that it can show the errors?

Thank you very much.