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";
}
?> 

What output do you see?

hi pritaeas, thanks for your reply.
I just notice actually, the code works fine in Google Chrome but not in Firefox and IE.
Any ideas?
i'm using wamp on my workstation.
thanks.

Strange, it is a server side script. The browser should not matter. You sure that there is nothing else interfering?

turn on error_reporting and also try to run the output of $sql directly in phpmyadmin or your MySQL application see if it inserts without error.

solution from this link: . http://www.daniweb.com/hardware-and-software/microsoft-windows/threads/30275/ie-wont-open-local-php-files-anymore
need to do some registry editing, and here's the solution from the URL above:
u need to change the .php file settings through regedit. Go to start --> run --> regedit --> under HKEY_CLASSES_ROOT, right click on .php file and select New String value. Name it Content Type. Then double click Content Type in the right panel of the window and add text/html under Value data.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.