Forum Moderators: coopster
<?php
$db_name = "database";
$db_login = "username";
$db_password = "password";
$db_host = "localhost";
$db_port = "3306";
$db = mysql_connect($db_host . ":" . $db_port, $db_login, $db_password) or die("Connect error");
mysql_select_db($db_name, $db) or die("Select error");
?>
<html>
<head>
<title>My first MySQL form submission</title>
</head>
<body>
<form action="" method="post">
Company: <input type="text" name="Company"><br>
Phone: <input type="text" name="Phone"><br>
<input type="submit" name="submit" value="Submit!">
</form>
<?php
$Company = $_POST[‘Company’];
$Phone = $_POST[‘Phone’];
mysql_query("INSERT INTO `partner` (Company, Phone) VALUES ('$Company', ‘$Phone’)");
?>
</body>
</html>
any help would be great.
Thank you.
[edited by: jatar_k at 9:30 pm (utc) on Feb. 16, 2006]
[edit reason] generalized login info [/edit]
a couple of things that strike me
there are a lot of curly quotes in there, not sure why but they might cause some issues. They should be changed to '
do you really need the port? that's just the standard mysql port so it shouldn't be required in the connect, 'localhost' should be enough
ref: [iana.org...]
on to what might help find your problem
I would split this up into different lines
mysql_query("INSERT INTO `partner` (Company, Phone) VALUES ('$Company', ‘$Phone’)");
this is a case of curly quotes and I will change those too
$query = "INSERT INTO partner (Company, Phone) VALUES ('$Company', '$Phone')";
echo '<p>',$query;
mysql_query($query) or die('<p>problem with query: ' . mysql_error());
this does 2 things
1. it echo's your query so you can look at it and make sure there aren't any glaring issues
2. adds the or die so if mysql returns an error from your query you will actually know about it and what it is
I also removed the backticks around the tablename just because I don't use them, not because they are wrong.
give that a try and see what happens
it seems the above lines aren't working, furst try just changing the curly quotes like so
$Company = $_POST['Company'];
$Phone = $_POST['Phone'];
next check that 'Company' and 'Phone' are the proper element names from your form, make sure the case is right specifically