Howdy! problem with code.

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
paulytrick
Forum Newbie
Posts: 8
Joined: Mon May 11, 2009 1:40 pm
Location: Sheffield, UK

Howdy! problem with code.

Post by paulytrick »

Hi. Can anyone tell me why this code won't work? it's supposed to display a form with two boxes and submit those values into a database when the submit button is clicked.

Code: Select all

 
<body>
<form action="" method="post">
<Fieldset>
<legend>Add a quote</legend>
<label for "quote">Quote:</label>
<input type="text" name="quote" id="quote" maxlength="255" />
<label for="author">Author:</label>
<input type="text" name="author" id="author" maxlength="40" />
<input type="submit" value="add quote" />
</fieldset>
</form>
 
 
 
<?php 
error_reporting(E_ALL);
$user="root";
$pass="****";
$database="afp";
$connection = mysql_connect('localhost',$user,$pass);
@mysql_select_db($database) or die ( "Unable to connect to database :<"
);
if ($_REQUEST['quote'] !="") {
    if($_REQUEST['author'] !="" {
        $author = $_REQUEST['aurhor'];
    } else {
        $author= "Anonymous";
        }
        $quote = $_REQUEST['quote'];
        $query="INSERT INTO `quotes` ('quote','author') values('" . mysql_real_escape_string($quote) ."','" . mysql_real_escape_string($author) . "')"
        ;
            $result = mysql_query($query) or die(mysql_error());
            echo("inserted quote: " . htmlentities($quote) . " by" . htmlentities($author) . " into database"
            );
            } else {
            echo("<p>Please enter a quote and author</p>");
            }
            ?>
            
 
</body>
</html>
 
I'm sure it will be a syntax error. all i get when i run it in a browser is error 500 There is a problem with the page you are trying to reach and it cannot be displayed.

MAny thanks in advance,

Paul.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Howdy! problem with code.

Post by Benjamin »

Code: Select all

 
$author = $_REQUEST['aurhor'];
 
Should be:

Code: Select all

 
$author = $_REQUEST['author'];
 
But that's not the cause of your 500 error. Check your server error logs. It could be that the file permissions are set incorrectly.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Howdy! problem with code.

Post by califdon »

And remove the @ from the mysql_select_db call until you clear this up. That defeats the purpose of setting error reporting on.
Post Reply