I am having trouble posting information into a mysql table. My table is named testing_db. The table contains four columns named: compname, trainname, address, city. All I require, is that the user enters the information into the form, press submit, and the information is stored in the mysql db and the user receives a confirmation that the info went through.
here is the form:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<form method="post" action="formdata2.php">
company name:
<input type="Text" name="compname"><br>
trainee name::
<input type="Text" name="trainname"><br>
address:
<input type="Text" name="address"><br>
city:
<input type="Text" name="city"><br>
<input type="Submit" name="submit" value="Enter information">
</form>
</body>
</html>
Here is the php code (formdata2):
<?
$db = mysql_connect("localhost","usernamexxxxxx","passwordxxxx");
mysql_select_db (testing);
$result = mysql_query ("INSERT INTO testing_db (compname, trainname, address, city,)
VALUES ('$compname', '$trainname', '$address', '$city',)");
if(!$result)
{
echo "<b>Something not added:</b> ", mysql_error();
exit;
}
if($result)
{
mysql_close($db);
print "Something added sucessfully!";
}
?>
All suggestions are greatly appeciated and thank you for your time.
Basic Form to mySQL
Moderator: General Moderators
Code: Select all
$result = mysql_query ("INSERT INTO testing_db (compname, trainname, address, city,)
VALUES ('$compname', '$trainname', '$address', '$city',)");Code: Select all
$result = mysql_query ("INSERT INTO testing_db (compname, trainname, address, city)
VALUES ('$compname', '$trainname', '$address', '$city')");- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
-
mikehillside
- Forum Newbie
- Posts: 2
- Joined: Wed Oct 23, 2002 6:04 pm
qads: Thank you for helping! Removing the extra commas did the trick. I greatly appreciate the help, as this is my first php script and mysql table. I now have a stepping stone towards a better understanding of php. Have a good weekend.
twigletmac: I read the viewtopic 511, but since this is my second day working with php and mysql code, it is still foreign to me. I set up my mysql database and php script from previous examples I found throughout the many forums. Thanks for the advice, as I look forward to learning php and mysql in depth.
twigletmac: I read the viewtopic 511, but since this is my second day working with php and mysql code, it is still foreign to me. I set up my mysql database and php script from previous examples I found throughout the many forums. Thanks for the advice, as I look forward to learning php and mysql in depth.