inserting data to mysql db

This is a discussion on "inserting data to mysql db" within the PHP Forum section. This forum, and the thread "inserting data to mysql db are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Closed Thread
 
LinkBack Thread Tools
  #1 (permalink)  
Old May 6th, 2005, 03:53
Tim356's Avatar
Reputable Member
Join Date: Nov 2003
Location: Australia
Age: 25
Posts: 331
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Tim356
inserting data to mysql db

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?

  #2 (permalink)  
Old May 6th, 2005, 04:20
Tim356's Avatar
Reputable Member
Join Date: Nov 2003
Location: Australia
Age: 25
Posts: 331
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Tim356
nevermind, I left the ' out of the values.
Closed Thread

Tags
inserting, data, mysql

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
inserting time phiero21 JavaScript Forum 1 May 2nd, 2008 20:09
mysql data loads once user login longstand PHP Forum 9 Feb 7th, 2008 07:10
example of Inserting and Retrieving data from xml file hanusoft Classic ASP 1 Sep 25th, 2007 17:21
Code for button to refresh page after inserting data in sql db wacara JavaScript Forum 0 Apr 27th, 2007 02:45
Form data to MySql casper22 Introduce Yourself 4 Aug 8th, 2006 21:30


All times are GMT. The time now is 21:49.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43