PDA

Click to See Complete Forum and Search --> : much needed help with the following code:


fundean
Dec 18th, 2006, 05:56 PM
<?php
$db_host = "mysql";
$db_user = "lefteh";
$db_pwd = "1234";
$db_name = "MyDB";
mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($db_name);
?>
<html>
<head>
<title>My first MySQL form submission</title>
</head>
<body>
<?php
if (!isset($_POST['submit'])) {
?>
<form action="" method="post">
Name: <input type="text" name="name"><br>
Favorite Color: <input type="text" name="color"><br>
<input type="submit" name="submit" value="Submit!">
</form>
<?php
} else {
$name = $_POST['name'];
$color = $_POST['color'];
mysql_query("INSERT INTO `colors` (name, favoriteColor) VALUES
('$name', '$color')");
echo "Success! Your favourite colour has been added!";
}
?>
</body>
</html>

When I submit the form using the values "fundean" and "blue" I get the following errors:

"Error: method not allowed"

HELP !!!!

fundean

kows
Dec 18th, 2006, 06:11 PM
uhh.. your host name is "mysql"? unless you edited it, that might be the problem?

add some "or die()" statements to your code whenever you call a function, just to tell you where it broke.. ie:
mysql_connect($db_host, $db_user, $db_pwd) or die('could not connect to mysql server');
mysql_select_db($db_name) or die('could not select database');
including your mysql_query() statement, too.