Jump to content

Form issues


zenix

Recommended Posts

Hi, I am new to php and have been learning right along when suddenly my form pages don't display. All the other php pages display just fine. All I get is a 500 error in IE and a blank page in Firefox. If someone could lend some assistance I would really appreciate it. If the HTML is alone it displays perfectly. Here is the code:

 

<head>
<title>Entry 2</title>
</head>

<body>
<?php

//Didn't show anything
//ini_set('display_errors', 1);
//error_reporting(E_ALL);

if(isset($_POST['submit']))
{
//connect and select
if($dbc = mysql_connect ('localhost', 'root'))
{
	if(!@mysql_select_db ('myblog'))
	{
		dir('<p>Could not select database because <b>' . mysql_error() . '</b></p>';
	}
}
else
{
	print "<p>Could not connect to database because <b>" . mysql_error() . "</b></p>";
}
//define query
$query = "INSERT INTO blog_entries
(bog_id, title, entry, date_entered) VALUES(0, '{$_POST['title']}', '{$POST['entry']}', NOW())";

//execute query
if(@mysql_query($query))
{
print '<p>The blog entry has been added</p>';
}
else
{
"<p>Could not add entry because: <b>" . mysql_error() . "</b>. The query was $query.</p>"
}
mysql_close();
?>

<form action ="add_entry.php" method ="post">
<p>Entry title: <input type ="text" name ="title" size ="40" maxsize ="100"/></p>
<p>Entry text: <text area name="entry" cols ="40" rows ="5"/></p>
<br/>
<input type ="submit" name ="submit" value ="Add my entry!"/>
</form>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/161046-form-issues/
Share on other sites

The posted code contains two (or more) fatal parse errors. One on line 19 due to a missing ) and one on line 38 due to a missing ; on line 37. Line 37 also does not have any php statement, it is only a quoted string. Edit: There is also a missing closing } that goes with the if(isset($_POST['submit'])) statement.

 

You should be learning php, developing php code, and debugging php code on a system with error_reporting set to E_ALL and display_errors set to ON in your php.ini. For fatal parse errors, you cannot set those two settings in your code because your code is never executed when there are parse errors.

Link to comment
https://forums.phpfreaks.com/topic/161046-form-issues/#findComment-849887
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.