Page 1 of 1

Basic Form to mySQL

Posted: Wed Oct 23, 2002 6:04 pm
by mikehillside
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.

Posted: Wed Oct 23, 2002 6:13 pm
by qads

Code: Select all

$result = mysql_query ("INSERT INTO testing_db (compname, trainname, address, city,) 
VALUES ('$compname', '$trainname', '$address', '$city',)");
change it to

Code: Select all

$result = mysql_query ("INSERT INTO testing_db (compname, trainname, address, city) 
VALUES ('$compname', '$trainname', '$address', '$city')");

Posted: Thu Oct 24, 2002 2:11 am
by twigletmac
Have a read of this if you have PHP > 4.1:
viewtopic.php?t=511

Mac

Posted: Thu Oct 24, 2002 9:24 am
by mikehillside
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.