I am attempting to create a MySQL database and table for the first time.
The test code I wrote (PHP 5) retrieves data that I manually inserted into my table and displays it. However, when attempting to INSERT data into that same table from my web page, the code SEEMS to work, but the table is not updated.
Here's the code:
<?php
//Sample Database Connection Syntax for PHP and MySQL.
//Connect To Database
$hostname="mysql.secureserver.net";
$username="xxxxxx";
$password="xxxxxxxx";
$dbname="idaay";
$usertable="NewsList";
$yourfield = "Email";
mysql_connect($hostname,$username, $password)
or die ("<html><script language='JavaScript'>
alert('Unable to connect to database! Please try again later.'),
history.go(-1)</script></html>");
mysql_select_db($dbname);
# Check If Record Exists
mysql_query('INSERT INTO $usertable (Name, Email, Group)
VALUES ("Dianne", "drt@drt.com", "Newsletter")');
$query = "SELECT * FROM $usertable";
$result = mysql_query($query);
if($result)
{
while($row = mysql_fetch_array($result))
{
$name = $row["$yourfield"];
echo "Email: ".$name."<br>";
}
}
?>
Thanks in advance!