hi guys, need your help on this.
had a form on html and saving data to mysql but it's not working here's the html code:
<html>
<body>
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td><form name="form1" method="post" action="insertac.php">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td colspan="3"><strong>Insert Data Into mySQL Database </strong></td>
</tr>
<tr>
<td width="71">Name</td>
<td width="6">:</td>
<td width="301"><input name="name" type="text" id="name"></td>
</tr>
<tr>
<td>Lastname</td>
<td>:</td>
<td><input name="lastname" type="text" id="lastname"></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input name="email" type="text" id="email"></td>
</tr>
<tr>
<td colspan="3" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
and here's the php to save to mysql which is not working, please help.
it seems the $_POST is not working but i don't have any ideas why it's not able to get data from the form.
any ideas is greatly appreciated, thanks :)
<?php
$host="localhost"; // Host name
$username="my_username"; // Mysql username
$password="my_password"; // Mysql password
$db_name="testdbx"; // Database name
$tbl_name="tblx"; // Table name
// Connect to server and select database.
$link=mysql_connect("$host","$username", "$password");
if(!$link)
{
die("Could not connect:" .mysql_error());
}
mysql_select_db("$db_name"); //here goes the database selection
echo "Connected successfully!";
// Get values from form
$name = $_POST['name'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
// Insert data into mysql
$sql="INSERT INTO $tbl_name(name, lastname, email)VALUES('$name', '$lastname', '$email')";
$result=mysql_query($sql);
// if successfully insert data into database, displays message "Successful".
if($result){
echo "Successful";
}
else {
echo "ERROR";
}
?>