Hi, guys.
I'm working on a section of code that inserts values from an HTML form into a MYSQL database. However, each time I run the code, two rows of identical data are inserted into the database.
Can anybody help me resolve this problem?
Here is the code mentioned above. Even running this code by itself, without using the html form first, has the same problem.
<?php
//Define Variables
$username="dot_dot";
$password="q(@Q7SP4L((D";
$database="dot_thesiteguru";
$title=$_POST['title'];
$meta=$_POST['meta'];
$header_1=$_POST['header_1'];
$paragraph_1=$_POST['paragraph_1'];
$header_2=$_POST['header_2'];
$paragraph_2=$_POST['paragraph_2'];
$author=$_POST['author'];
//Connect To the Database Server
mysql_connect(localhost,$username,$password);
//Select the Database
@mysql_select_db($database) or die("Unable to select database");
//Command the Server to Insert Values
$query="INSERT INTO webpage VALUES ('','$title','$meta','$header_1','$paragraph_1','$header_2','$paragraph_2','$author')";
mysql_query($query);
$id = mysql_insert_id();
//Check if Insertation of Values Was Successful
if(mysql_query($query)) {
echo "You have successfully saved a webpage with author $author and title $title. The ID for this webpage is $id.";
} else {
echo "There was a problem processing the information. Please contact us at support[@]thesiteguru.com.";
}
//Close the Connection
mysql_close();
?>