Jump to content

Error loading page


toin

Recommended Posts

Hi at all,

I have a problem on the new.php page because when i push the submit button I have a problem on the browser so it doesn't redirect me to the page that i want and there aren't new record on the database

This is the connection of the DB

<?php
/* 
CONNECT-DB.PHP
Allows PHP to connect to your database
*/

// Database Variables (edit with your own server information)
$server = 'localhost';
$user = 'root';
$pass = 'password';
$db = 'test';

// Connect to Database
$connection = mysql_connect($server, $user, $pass) 
or die ("Could not connect to server ... \n" . mysql_error ());
mysql_select_db($db) 
or die ("Could not connect to database ... \n" . mysql_error ());


?>

 

 

View.PHP

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
       <title>View Records</title>
</head>
<body>

<?php
/* 
       VIEW.PHP
       Displays all data from 'players' table
*/

       // connect to the database
       include('connect-db.php');

       // get results from database
       $result = mysql_query("SELECT * FROM players") 
               or die(mysql_error());  

       // display data in table
       echo "<p><b>View All</b> | <a href='view-paginated.php?page=1'>View Paginated</a></p>";

       echo "<table border='1' cellpadding='10'>";
       echo "<tr> <th>ID</th> <th>First Name</th> <th>Last Name</th> <th></th> <th></th></tr>";

       // loop through results of database query, displaying them in the table
       while($row = mysql_fetch_array( $result )) {

               // echo out the contents of each row into a table
               echo "<tr>";
               echo '<td>' . $row['id'] . '</td>';
               echo '<td>' . $row['firstname'] . '</td>';
               echo '<td>' . $row['lastname'] . '</td>';
               echo '<td><a href="edit.php?id=' . $row['id'] . '">Edit</a></td>';
               echo '<td><a href="delete.php?id=' . $row['id'] . '">Delete</a></td>';
               echo "</tr>"; 
       } 

       // close table>
       echo "</table>";
?>
<p><a href="new.php">Add a new record</a></p>

</body>
</html> 

 

new.php

<?php
/* 
NEW.PHP
Allows user to create a new entry in the database
*/

// creates the new record form
// since this form is used multiple times in this file, I have made it a function that is easily reusable
function renderForm($first, $last, $error)
{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>New Record</title>
</head>
<body>
<?php 
// if there are any errors, display them
if ($error != '')
{
echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
}
?> 

<form action="" method="post">
<div>
<strong>First Name: *</strong> <input type="text" name="firstname" value="<?php echo $first; ?>" /><br/>
<strong>Last Name: *</strong> <input type="text" name="lastname" value="<?php echo $last; ?>" /><br/>
<p>* required</p>
<input type="submit" name="submit" value="Submit">
</div>
</form> 
</body>
</html>
<?php 
}




// connect to the database
include('connect-db.php');

// check if the form has been submitted. If it has, start to process the form and save it to the database
if (isset($_POST['submit']))
{ 
// get form data, making sure it is valid
$firstname = mysql_real_escape_string(htmlspecialchars($_POST['firstname']));
$lastname = mysql_real_escape_string(htmlspecialchars($_POST['lastname']));

// check to make sure both fields are entered
if ($firstname == '' || $lastname == '')
{
// generate error message
$error = 'ERROR: Please fill in all required fields!';

// if either field is blank, display the form again
renderForm($firstname, $lastname, $error);
}
else
{
// save the data to the database
mysql_query("INSERT players SET firstname='$firstname', lastname='$lastname'")
or die(mysql_error()); 

// once saved, redirect back to the view page
header("Location: view.php"); 
}
}
else
// if the form hasn't been submitted, display the form
{
renderForm('','','');
}
?> 

Link to comment
Share on other sites

I think the redirection problem is due to the fact that within new.php, it is trying to redirect to "view.php", whereas your file is named "View.php." I would start there -- make sure the file name is all lower case.

 

 

 

The name are all lower case...

I make the delete page and it works it redirect me to the view page...why the insert and modify page not? it's frustrating

Link to comment
Share on other sites

Just so I make sure we are on the same page...

 

-- you can view the main "view.php" page fine.

-- If you click on the "new record" at the bottom of "view.php", that works fine and takes you to new.php.

-- when you are on new.php, and you enter your information, and click submit, you are given a "page not found" error? What is that exact error? (copy/paste from your browser please.)

 

As far as I know, my code should work fine (and I've tested it on both my local computer and my webhosting), and I haven't gotten any complaints from anyone else who has tried it.

Link to comment
Share on other sites

Just so I make sure we are on the same page...

 

-- you can view the main "view.php" page fine.

-- If you click on the "new record" at the bottom of "view.php", that works fine and takes you to new.php.

-- when you are on new.php, and you enter your information, and click submit, you are given a "page not found" error? What is that exact error? (copy/paste from your browser please.)

 

As far as I know, my code should work fine (and I've tested it on both my local computer and my webhosting), and I haven't gotten any complaints from anyone else who has tried it.

translate from google :)

 

The connection has been canceled

The server connection was canceled when the page loads.

 

 

 

 

The site may be unavailable or overloaded. Try again in a few moments.

If you can not load any pages, check your computer's network connection.

If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the web.

 

It's possibile to stamp only a message for example: New record added?

Link to comment
Share on other sites

I'm not sure what to tell you. Based on the error, it doesn't sound like it can't find the page. Just that the server connection was canceled for some reason. I'm guessing it is some sort of server configuration issue, but I really have no idea. I don't know why you would get this issue only on pages that include forms, and the rest of it seems to work fine.

 

At this point, I'm not sure if I can help you any more. As I said before, this works fine for me in multiple locations, and has worked fine for everyone else that has tried it (as far as I know). Have you tried uploading this to an actual web server? If it works there, you know that it is a server misconfiguration issue of some sort, and doesn't have anything to do with the code itself.

Link to comment
Share on other sites

I'm not sure what to tell you. Based on the error, it doesn't sound like it can't find the page. Just that the server connection was canceled for some reason. I'm guessing it is some sort of server configuration issue, but I really have no idea. I don't know why you would get this issue only on pages that include forms, and the rest of it seems to work fine.

 

At this point, I'm not sure if I can help you any more. As I said before, this works fine for me in multiple locations, and has worked fine for everyone else that has tried it (as far as I know). Have you tried uploading this to an actual web server? If it works there, you know that it is a server misconfiguration issue of some sort, and doesn't have anything to do with the code itself.

 

I'm watching on the error log of apache and when i try to submit on the edit page I have this:

PHP Warning:  Directive 'register_globals' is no longer supported in PHP 6 and greater in Unknown on line 0
PHP Warning:  Directive 'register_long_arrays' is no longer supported in PHP 6 and greater in Unknown on line 0
PHP Warning:  Directive 'magic_quotes_gpc' is no longer supported in PHP 6 and greater in Unknown on line 0
[Mon Jul 25 10:30:13 2011] [notice] Child 1668: Child process is running
[Mon Jul 25 10:30:13 2011] [notice] Child 1668: Acquired the start mutex.
[Mon Jul 25 10:30:13 2011] [notice] Child 1668: Starting 64 worker threads.
[Mon Jul 25 10:30:13 2011] [notice] Child 1668: Starting thread to listen on port 80.

 

It's a problem on the version of Php?

Link to comment
Share on other sites

I'm watching on the error log of apache and when i try to submit on the edit page I have this:

PHP Warning:  Directive 'register_globals' is no longer supported in PHP 6 and greater in Unknown on line 0
PHP Warning:  Directive 'register_long_arrays' is no longer supported in PHP 6 and greater in Unknown on line 0
PHP Warning:  Directive 'magic_quotes_gpc' is no longer supported in PHP 6 and greater in Unknown on line 0
[Mon Jul 25 10:30:13 2011] [notice] Child 1668: Child process is running
[Mon Jul 25 10:30:13 2011] [notice] Child 1668: Acquired the start mutex.
[Mon Jul 25 10:30:13 2011] [notice] Child 1668: Starting 64 worker threads.
[Mon Jul 25 10:30:13 2011] [notice] Child 1668: Starting thread to listen on port 80.

 

It's a problem on the version of Php?

 

Was a problem of Php...I put an older version of Php and it works...Thanks the same Ben for your helps :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...