Jump to content

Help! Can't get values into database

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
thesquirrel16

thesquirrel16

    Newbie

  • Members
  • PipPip
  • 12 posts
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?

#2
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts
Try using the [ code ]-tags.

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
thesquirrel16

thesquirrel16

    Newbie

  • Members
  • PipPip
  • 12 posts
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
thesquirrel16

thesquirrel16

    Newbie

  • Members
  • PipPip
  • 12 posts
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
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts
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.

#6
thesquirrel16

thesquirrel16

    Newbie

  • Members
  • PipPip
  • 12 posts
lol yep that was it, im an idiot, thanks a bunch (<-- newb) =)