I am very new to PHP/MySQL and need some very simple help on my very simple script. What I am wishing to accomplish is to have a simple HTML form submit to a php script which adds the values of the form input into my MySQL database.
My MYSQL database table has 7 fields, one of which is an autoincremental integer. The rest are data fields.
I have 3 scripts total: HTML form, php submission form, php database connection info script (included in the submission form).
The following are my scripts:
HTML FORM:
Code: Select all
<html>
<head>
<title>SUBMISSION FORM</title>
<link href="test.css" rel="stylesheet" type="text/css">
</head>
<body>
<FORM ACTION="submitform.php" METHOD="POST">
<table width="500" border="0" cellspacing="3" cellpadding="0">
<tr>
<td align="right" valign="top">Name:</td>
<td align="left" valign="top"><INPUT TYPE="TEXT" NAME="name"></td>
</tr>
<tr>
<td align="right" valign="top">* Email:</td>
<td align="left" valign="top"><INPUT TYPE="TEXT" NAME="email"></td>
</tr>
<tr>
<td align="right" valign="top">City:</td>
<td align="left" valign="top"><INPUT TYPE="TEXT" NAME="city"></td>
</tr>
<tr>
<td align="right" valign="top">State:</td>
<td align="left" valign="top"><INPUT TYPE="TEXT" NAME="state"></td>
</tr>
<tr>
<td align="right" valign="top">Testimony:</td>
<td align="left" valign="top"><textarea name="testimony" cols="45" rows="15"></textarea></td>
</tr>
<tr>
<td align="right" valign="top"> </td>
<td align="left" valign="top"><INPUT TYPE="SUBMIT" value="SUBMIT!"></td>
</tr>
</table>
</FORM>
</body>
</html>PHP SUBMISSION SCRIPT:
Code: Select all
<?php
$name=$_POST['name'];
$email=$_POST['email'];
$city=$_POST['city'];
$state=$_POST['state'];
$testimony=$_POST['testimony'];
include("dbinc.php");
mysql_connect(localhost,$user,$pw);
@mysql_select_db($db) or die( "Unable to select database");
$query = "INSERT INTO testimonies ( tid, name, email, city, state, testimony, posted ) VALUES ('','$name','$email','$city','$state','$testimony','N')";
mysql_query($query);
mysql_close();
?>PHP DB CONNECTION SCRIPT:
Code: Select all
<?php
$user = "username"
$pw = "password"
$db = "contactus"
?>