<?php
$dbserver="localhost";
$username="root";
$pass="root";
$link=mysql_connect("$dbserver","$username","$pass");
if(!$link){die('DB Connection Failed'.mysql_error()); }
echo('connected');
$Name=$_POST["namei"];
$ID=$_POST["pid"];
$Address=$_POST["address"];
$Phone=$_POST["phone"];
$query="INSERT INTO contact(Name,ID,Address,Phone) VALUES('".$Name."',".$ID.",'".$Address."',".$Phone.");";
echo($query);
?>
The code above is used by me to connect to a mysql db, i’m posting the contents to this page from an html page. As i checked there is no problem with POST. but on click of submit it gives me an error ‘500 Internal Server Error’.
I’m using Apache 2.2 Server, and mysql 5.5.
Can any one tell what is my mistake?
Thank you
First please run
to check whether a) you can run any php script and b) the mysql_* functions are available.
Then try
It prints something in any case (echo/flush) and sets error_reporting + display_errors so that error messages are sent to the client (you don’t want that in production, don’t forget to remove those lines).
I also added the necessary calls to mysql_select_db() and mysql_real_escape_string() (needed as soon as the script really sends the query to the mysql server).