Hi, I have recently created a database on phpMyadmin and added php code to my website to read from the database. The code is below:
[code=php]
<?PHP
$user_name = “Myusername”;
$password = “Mypassword”;
$database = “Mydatabase”;
$server = “Myserver”;
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);
if($db_found){
$SQL = “SELECT * FROM Wavelength”;
$result = mysql_query($SQL);
while ( $db_field = mysql_fetch_assoc($result) ) {
print $db_field[‘Telescope ID’] . “<BR>”;
print $db_field[‘Telescope Name’] . “<BR>”;
print $db_field[‘Acronym’] . “<BR>”;
print $db_field[‘Wavelength’] . “<BR>”;
print $db_field[‘Cost’] . “<BR>”;
print $db_field[‘Launched’] . “<BR>”;
print $db_field[‘Mission Length’] . “<BR>”;
}
mysql_close($db_handle);
}
else{
print”Database NOT Found”;
mysql_close($db_handle);
}
?>
This successfully displayed my database on my website so the next stage was to add another entry into the database using the following code:
[code=php]
<?PHP
$user_name = “Myusername”;
$password = “Mypassword”;
$database = “Mydatabase”;
$server = “Myserver”;
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);
if($db_found){
$SQL = “INSERT INTO Wavelength (Telescope Name, Acronym, Wavelength, Cost, Launched, Mission Length)
VALUES ($’James Webb’,$’JWST’,$’Infra-red’,$’10B’,$’1998-10-6′,$’10’)”;
$result = mysql_query($SQL);
mysql_close($db_handle);
print”Records added to the database”;
}
else{
print”Database NOT Found”;
mysql_close($db_handle);
}
?>
This seemed to be successful, on my website it said “Records added to the database” but when I opened up PHPMyadmin no new entry was there. The database is a space telescopes database with a table name of Wavelength and 7 fields. For the last few months I have learnt how to write enough code to launch a website and I am continuing to learn new skills, I have become stuck with this problem and have failed to find any solutions. I would greatly appreciate help from someone with this problem.