Blank page problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
newbiesher123
Forum Newbie
Posts: 3
Joined: Sat Sep 06, 2014 2:45 am

Blank page problem

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Blank page problem

Post 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?
newbiesher123
Forum Newbie
Posts: 3
Joined: Sat Sep 06, 2014 2:45 am

Re: Blank page problem

Post 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.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Blank page problem

Post 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?
newbiesher123
Forum Newbie
Posts: 3
Joined: Sat Sep 06, 2014 2:45 am

Re: Blank page problem

Post 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.
Post Reply