Basic Form to mySQL
Posted: Wed Oct 23, 2002 6:04 pm
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.
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.