I am trying to create a simple HTML form that calls a .php script called submitter. Submitter should then put the values into my database called test. The HTML code is:
<html>
<body>
<form method="post" action="submitter.php">
First name:<input type="Text" name="first"><br>
Last name:<input type="Text" name="last"><br>
Address:<input type="Int" name="age"><br>
<input type="Submit" name="submit" value="Enter information">
</form>
</body>
</html>
and the php script:
<?php
$db = mysql_connect("localhost", "root");
mysql_select_db("test",$db);
$sql = "INSERT INTO test (FirstName,LastName,Age) VALUES ('$first','$last','$age')";
$result = mysql_query($sql);
echo "Thank you! Information entered.\n";
?>
All this does is put nothing into the database. When i display the database using a seperate php script it just shows 0??
Any ideas?
Help....if you can!
Moderator: General Moderators
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
-
richcoleuk
- Forum Newbie
- Posts: 24
- Joined: Fri Nov 05, 2004 1:33 pm
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
Form:
submitter.php
Code: Select all
<html>
<body>
<form method="post" action="submitter.php">
First name:<input type="text" name="first"><br>
Last name:<input type="text" name="last"><br>
Age:<input type="text" name="age"><br>
<input type="Submit" name="submit" value="Enter information">
</form>
</body>
</html>Code: Select all
<?php
$db = mysql_connect("localhost", "root"); //connect to database
mysql_select_db("test",$db); //select database
//check that values are present - can add more checking at this poing
if(isset($_POST['first'])){
$first = $_POST['first'];
}else{
$first = "";
}
if(isset($_POST['last'])){
$last = $_POST['last'];
}else{
$last = "";
}
if(isset($_POST['age'])){
$age = $_POST['age'];
}else{
$age = "";
}
//insert data into database
$sql = "INSERT INTO test (FirstName, LastName, Age) VALUES ('$first', '$last', '$age')";
$result = mysql_query($sql);
echo "Thank you! Information entered.\n";
?>