# Insert into database ERROR...?

**URL:** <https://forum.kirupa.com/t/insert-into-database-error/272258>\
**Category:** programming\
**Created:** [October 3, 2008, 10:01am UTC](https://forum.kirupa.com/t/insert-into-database-error/272258 "2008-10-03T10:01:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ian\_dcuk](https://avatars.discourse-cdn.com/v4/letter/i/ea666f/32.png) [@ian\_dcuk](https://forum.kirupa.com/u/ian_dcuk)\
**Post date:** [October 3, 2008, 10:01am UTC](https://forum.kirupa.com/t/insert-into-database-error/272258/1 "2008-10-03T10:01:11Z")

</div>

Hi guys, Ive got the following php script that should connect to my localhost and insert the relevant data however I am responded with an error:

[COLOR=red]"; echo “[/COLOR][[COLOR=red]Back to main page[/COLOR]](file:///F:/Web%202008/Suppleform/Pages/whatwedo.html)[COLOR=red]”; } else { echo “ERROR”; } // close connection mysql\_close(); ?\>[/COLOR]  
[COLOR=#ff0000][/COLOR]  
[COLOR=black][/COLOR]  
My php script is as follows:

\<?php  
$host=“localhost”; // Host name  
$username=“root”; // Mysql username  
$password=“suppleform1”; // Mysql password  
$db\_name=“test”; // Database name  
$tbl\_name=“test\_mysql”; // Table name

// Connect to server and select database.  
mysql\_connect("$host", “$username”, “$password”)or die(“cannot connect”);  
mysql\_select\_db("$db\_name")or die(“cannot select DB”);

// 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”;  
echo “\<BR\>”;  
echo “\<a href=‘whatwedo.html’\>Back to main page\</a\>”;  
}  
else {  
echo “ERROR”;  
}  
// close connection  
mysql\_close();  
?\>

Anyone have an idea as why I am having this problem? I think I have the code all correct at the moment…?
