Hi, okay so I am new to databasing but I have been following some tutorials to try to get started, I have a database created with a table. Here is the code I am using to try to input the values into the table.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<p>The Official try at this ****</p>
<input type="submit" />
<?php
$con = mysql_connect(server , username, pw);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("eventdb", $con);
mysql_query("INSERT INTO title (Title, Host, Place)
VALUES ('Peter', 'Griffin', '35')");
mysql_close($con);
?>
<p> </p>
</body>
</html>
The username/pw/server is all correct it connects fine, but the values are not inserted into the table for some reason. I have tried upper case and lower case just to try on the collumns. The database is called eventdb and the table is called title and the columns are called Title, Host, Place. Any idea why this code isn't working? I am building in DreamWeaver. Also... another side question, when does the page know when to run the php? when it loads?
Help! Can't get values into database
Started by thesquirrel16, Apr 20 2007 10:04 PM
5 replies to this topic
#1
Posted 20 April 2007 - 10:04 PM
|
|
|
#2
Posted 20 April 2007 - 11:21 PM
Try using the [ code ]-tags.
Try to do this;
Try to do this;
mysql_query("INSERT INTO title (Title, Host, Place) VALUES ('Peter', 'Griffin', '35')") or die(mysql_error());
Then you can see if some errors occurs.
#3
Posted 21 April 2007 - 12:45 AM
Hi, thanks for the reply, I added that line in and nothing happened still. I am going to guess that either the php code isn't running or the error isn't outputting. Any idea which it would be? How does the form know to call to the php code when the button is clicked?
#4
Posted 21 April 2007 - 03:18 AM
Ok, I think i have another theory on why this isn't working. I am running all of that code in an html file, does it need to be a php file? Or do I need one of each? Is there a good tutorial about this?
#5
Posted 21 April 2007 - 04:09 AM
Hehe, that's your problem.
When your putting them in a HTML-file, the browser thinks the <?php is a tag, and the same with ?>. If you try, you can the the source online, if it's in a HTML-file. You can't do that if it's a PHP-file, because it executes at the server, not trough the browser.
Try to replace your extension ".htm" or ".html" with ".php", then it should work.
When your putting them in a HTML-file, the browser thinks the <?php is a tag, and the same with ?>. If you try, you can the the source online, if it's in a HTML-file. You can't do that if it's a PHP-file, because it executes at the server, not trough the browser.
Try to replace your extension ".htm" or ".html" with ".php", then it should work.
#6
Posted 21 April 2007 - 02:13 PM
lol yep that was it, im an idiot, thanks a bunch (<-- newb) =)


Sign In
Create Account


Back to top









