PHP/MySQL Error 500 when I "Submit" my Form

Bard09

Member
May 23, 2001
55
0
0
Just like the title says. I have MySQL and PHP set up on my server, both working correctly. I'm trying to create a PHP form to submit information to the database. I'm only a newbie at this stuff, so I've paid close attention to tutorials.

However, when I get to the point where I click Submit, my browser goes straight to an Error 500. What the heck? I have all file permissions enabled on the PHP file and I have been able to retrieve from my database. What's wrong with submitting to it?

I can post the code I'm using so far if you need to see it. I'm really getting frustrated with this error!!

-Bard09
 

Bard09

Member
May 23, 2001
55
0
0
Here's the PHP code I'm using. Masked some stuff with X's for security reasons.


<?php
if($submit)
{
$db = mysql_connect("XXXXXXXX", "XXXX", "XXXXXXX")
mysql_select_db("Honor_Bios",$db);
$sql = "INSERT INTO Freshmen (first_name,last_name,hometown,age,major,anything) VALUES ('$first_name','$last_name','$hometown','$age','$major','$anything')";
$result = mysql_query($sql);
echo "Thank you! Information entered.\n";
}
else
{
?>
<form method="post" action="temp.php">
First name:<input type="Text" name="first_name">

Last name:<input type="Text" name="last_name">

Hometown:<input type="Text" name="hometown">

Age:<input type="Text" name="age">

Major:<input type="Text" name="major">

Anything else? <input type="Text" name="anything">

<input type="Submit"name="submit" value=" Enter information"></form>
<?
}
?>
 

loup garou

Lifer
Feb 17, 2000
35,132
1
81
Post the code and I'll give you a hand (don't forget to censor your dbconnect info ;)). I probably won't be able to help till tomorrow afternoon, though.
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
500 is server error right? Check your webserver logs.

At the top of the script you are checking for a variable ($submit) which you have not created, therefore will never evaluate to true. I assume you're checking for a POST value in which case you should do something like if(isset($_POST["submit"])). If magic quotes are turned off, you will need to wrap $sql in addslashes(). Your mysql_connect has no semicolon afterwards. Your second opening tag is just <?, not <?php, which will fail if short tags are turned off. Also it's probably best to use one or the other for consistency's sake. :)

Think I covered it all :)
 

Bard09

Member
May 23, 2001
55
0
0
Wow. Excuse my ignorance. I suppose this is what I get from reading other peoples' code and mashing it all together in one go :) Thanks for the help!

-Bard09
 

oog

Golden Member
Feb 14, 2002
1,721
0
0
It also helps to turn off the "friendly HTTP error messages" that is turned on by default in IE (which I may erroneously be assuming you're using). With many systems, you will then see more details about the error, instead of the generic 500 Internal Server Error.

Edit: To turn off this setting, go to Tools | Internet Options | Advanced tab and find the checkbox that says that it is turned on.
 

jonmullen

Platinum Member
Jun 17, 2002
2,517
0
0
I also find it nice to leave off the "or die ("String Message"); when I am debugging a script, that why I get the full error msg returned by the mySQL. Also if your database querys are not working for some unknown reason try echoing your query string variable then running through something like "myphpadmin" which will often give you a better idea of what you are doing wrong. Just my 4.02
 

jonmullen

Platinum Member
Jun 17, 2002
2,517
0
0
I also find it nice to leave off the "or die ("String Message"); when I am debugging a script, that why I get the full error msg returned by the mySQL. Also if your database querys are not working for some unknown reason try echoing your query string variable then running through something like "myphpadmin" which will often give you a better idea of what you are doing wrong. Just my $.02