Page 1 of 1

Howdy! problem with code.

Posted: Wed May 20, 2009 1:03 pm
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.

Re: Howdy! problem with code.

Posted: Wed May 20, 2009 4:22 pm
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.

Re: Howdy! problem with code.

Posted: Wed May 20, 2009 6:06 pm
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.