Ok, back to this form handling again. I've just had a quick crack at inserting data from a form into a mysql database, here's the code:
the form:
- Code: Select all
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<Table><TR><TD>
<FORM action="index.php" name="Add email" method=post></TD></TR>
<TR><TD>Name</TD></TR><TR><TD>
<INPUT name=txtname type="text" class="cssborder"></TD></TR>
<TR><TD>Email</TD></TR><TR><TD>
<INPUT name=txtemail type="text" class="cssborder"></TD></TR>
<TR><TD>Subject</TD></TR><TR><TD>
<TEXTAREA name=txtsubject rows=3 cols=50 class="cssborder"></TEXTAREA></TD></TR>
<TR><TD>Message</TD></TR><TR><TD>
<TEXTAREA name=txtmessage rows=3 cols=50 class="cssborder"></TEXTAREA></TD></TR>
<TR><TD>
<INPUT type="submit"></TD></TR>
</FORM>
</TABLE>
</body>
</html>
index.
php:
- Code: Select all
<?php
include 'config.php';
include 'opendb.php';
mysql_select_db('phpcontest') or die('Cannot select database');
$cname = $HTTP_POST_VARS['txtname'];
$cemail = $HTTP_POST_VARS['txtemail'];
$csubject = $HTTP_POST_VARS['txtsubject'];
$cmessage = $HTTP_POST_VARS['txtmessage'];
mysql_select_db($dbname);
$query = "INSERT INTO contact (cname, cemail, csubject, cmessage)
VALUES ($cname, $cemail, $csubject, $cmessage)";
mysql_query($query) or die('Error, insert query failed');
include 'closedb.php';
?>
but it's not inserting anything. What am I doing wrong?