I installed MAMP on my mac to run sql and apache server on my local machine to host a website i am working on. Now i am using phpmyadmin to control and create my database tables. I am running into a couple of issues with inserting values into the tables. I have two pages namely, test.html and test.php. test.html has a form with username and password and it calls a javascript to post the values to test.php.Following is code snippet of how i am posting the value on test.html.
$.post("test1.php",
{
username: username,
password: password
},
function( dataFromServer ){
alert(dataFromServer);
}
);
I am unable to insert the two values in the table. When i click submit, i receive the following error in firefox:
POST http://localhost:8888//test1.php
500 Internal Server Error
Following is code snippet of how i insert values on test.php:
include('config.php');
$tbl_name="table1";
$username=$_POST['username'];
$password=$_POST['password'];
$sql="INSERT INTO $tbl_name(col1,col2)VALUES('$username','$password')";
$result=mysql_query($sql);
Can anybody point the mistake here. I am new to web coding so this might be really trivial.
Thanks,
-B
500 internal error means there is something wrong in your php file.
Check the following things
1.Is there any syntax error in your php file.
2.
should be written as
Also,always sanitize data before you use it.