Current location: Hot Scripts Forums » Programming Languages » PHP » DB entry thru php form question


DB entry thru php form question

Reply
  #1 (permalink)  
Old 03-20-05, 02:47 AM
ajs ajs is offline
Newbie Coder
 
Join Date: Nov 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
DB entry thru php form question

How do you enter information on an html page that sends the results through the php page to a db?

For example, let's say this is enter.html

PHP Code:

<form method="POST" action="test.php">

  <
input type="text" name="T1" size="20"><input type="submit" value="Submit" name="B1">
</
form
What would test.php include ? Obviously it would include

PHP Code:

<?

$username
="user";
$password="pass";
$database="database";

mysql_connect(localhost,$username,$password);
@
mysql_select_db($database) or die( "Unable to select database");
?>
but how do you handle the rest? Thanks
Reply With Quote
  #2 (permalink)  
Old 03-20-05, 03:55 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
PHP Code:

<?

$username
="user";
$password="pass";
$database="database";

$link mysql_connect('localhost',$username,$password);
@
mysql_select_db($database$link) or die( "Unable to select database");

$t1 addslashes(trim($_POST['T1'])); //because your field name is T1

mysql_query("INSERT INTO table_name (filed_name) VALUES ('$t1')"$link)or
die(
mysql_error());

echo 
mysql_affected_rows($link) . ' row(s) was inserted';
?>
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #3 (permalink)  
Old 03-20-05, 04:59 PM
ajs ajs is offline
Newbie Coder
 
Join Date: Nov 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks!

Another question, how would I pass along information that isn't in a entry box ? (ie: text called up based on a url such as www.site.com/items.php?id=1)
Reply With Quote
  #4 (permalink)  
Old 03-21-05, 09:07 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
you get information from URL with $_GET array and in your example you get the id value with:
PHP Code:

$_GET['id']; 

__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
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
2 profitable script sites for sale cms-master.com General Advertisements 3 07-03-07 10:17 AM
Competition entry form / random entry draw script with PHP? Tim Smith PHP 0 08-12-04 01:45 AM
general question about php and html timfoster PHP 3 05-17-04 12:29 PM
Quick Question for you php guru's Tokahashi PHP 3 04-09-04 12:00 PM
question about updating a page or database for an, php and mysql updating mikewooten PHP 1 02-12-04 12:11 AM


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