Current location: Hot Scripts Forums » Programming Languages » PHP » Adding information to MySQL database via forms.


Adding information to MySQL database via forms.

Reply
  #1 (permalink)  
Old 12-21-03, 07:17 AM
Dale Dale is offline
Newbie Coder
 
Join Date: Dec 2003
Location: London, UK
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Adding information to MySQL database via forms.

I have 6 things and the ID and DATE i suppose are NULL as the date is something like CURDATE() and ID is auto increasment but how do i have a form that sends the information to the database as the Spoono.com tutorial dont work.

Quote:
id
title
msg
author
email
date
Reply With Quote
  #2 (permalink)  
Old 12-21-03, 09:46 AM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
Quote:
Originally Posted by Dale
I have 6 things and the ID and DATE i suppose are NULL as the date is something like CURDATE() and ID is auto increasment but how do i have a form that sends the information to the database as the Spoono.com tutorial dont work.
Very simple form to db set up. On one page...

<form action="insert.php" method="post">
Title <input type="text" name="title" size="30">
Message <input type="text" name="msg" size="30">
Author <input type="text name="author" size=""30">
Email <input type="text" name="email" size="30">
<input type="submit" name="submit" value="Submit">
</form>

Another page, named insert.php
PHP Code:

$title=$_POST['title'];
$message=$_POST['message'];
$author=$_POST['author'];
$email=$_POST['email'];
                
$location="localhost";
$username="your_db_username";
$password="your_db_password";
$database="database_name";
 
$conn mysql_connect("$location","$username","$password");
 if (!
$conn) die ("Could not connect MySQL");
 
mysql_select_db($database,$conn) or die ("Could not open database");
 
$query "INSERT INTO table_name(id,title,message,author,email,date0 VALUES('','$title','$msg','author','email',now())";
 
                
$result=mysql_query($query);
                
mysql_close(); 
Just change the database section and the table name to match your set up.
Reply With Quote
  #3 (permalink)  
Old 12-21-03, 10:02 AM
Dale Dale is offline
Newbie Coder
 
Join Date: Dec 2003
Location: London, UK
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Its working but its not adding the information into the database.
Reply With Quote
  #4 (permalink)  
Old 12-21-03, 10:06 AM
Dale Dale is offline
Newbie Coder
 
Join Date: Dec 2003
Location: London, UK
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Its fine!!!!

Just had to change $message to $msg

Thanks mdhall!
Reply With Quote
  #5 (permalink)  
Old 12-21-03, 10:13 AM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
Glad it worked for you.
Reply With Quote
  #6 (permalink)  
Old 02-17-04, 02:43 AM
johnnytalk johnnytalk is offline
New Member
 
Join Date: Jan 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
adding send email to the code

How would you code it so that it sends you and the form filler a copy of the response to the form?
J.



Quote:
Originally Posted by mdhall
Glad it worked for you.
Reply With Quote
  #7 (permalink)  
Old 02-17-04, 04:58 AM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
Quote:
Originally Posted by johnnytalk
How would you code it so that it sends you and the form filler a copy of the response to the form?
J.
Add something like this at the end of the insert.php page, before the "?>" tag. This is very basic, you can do more with headers and multiple emails...


$sendto = "$email";
$subject = "Your Information";
$message = "Thank you for your input. It has been added to out database.";
$website = "my_web_site.com";
if($query){//On Success of the insertion mail
($sendto, $subject, $message, $website);
}
Reply With Quote
  #8 (permalink)  
Old 08-13-05, 01:53 PM
0o0o0 0o0o0 is offline
Wannabe Coder
 
Join Date: Jul 2005
Posts: 213
Thanks: 0
Thanked 0 Times in 0 Posts
got a question

when making a database writeable.. for a script like this

What needs to be NULL, and what doesnt?

He has

id
title
msg
author
email
date

? which is null or not? thanks
Reply With Quote
  #9 (permalink)  
Old 08-13-05, 09:55 PM
0o0o0 0o0o0 is offline
Wannabe Coder
 
Join Date: Jul 2005
Posts: 213
Thanks: 0
Thanked 0 Times in 0 Posts
alright bigger question

Now I got this all figured out and had to tweek most of it to make it run on my system.

Big question now is.. how does one make mandatory fields?

Since the average joe could sit and just press send send send send blank entries all day long.. and auto fill the db.

Lemme know this question whenever you can thanks!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
loop through & update a mysql database ednit Perl 4 10-03-09 10:07 PM
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
form not inserting information into the database sabret00the PHP 7 12-01-03 03:35 PM
Send sms via php and mysql database help meeeeee eggdesign PHP 2 10-03-03 12:29 AM
Adding binary files to mysql? angst ASP 0 07-03-03 08:56 AM


All times are GMT -5. The time now is 07:39 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.