Form action same as form page?

This is a discussion on "Form action same as form page?" within the PHP Forum section. This forum, and the thread "Form action same as form page? are both part of the Program Your Website category.



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

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jun 20th, 2005, 03:21
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
Form action same as form page?

I've created a simple links page that grabs the values of links (url, title, description) from a database and displays them on the page. At the base of the page, there is a form to add a new link. What I want to do is set that form's action to be the same page as the form is on, and have some sort of code at the start of the page to insert the form data into the database. The page would then go on to display the database info. I can insert and display all the info no problem, but I don't know how to write the script to ignore the inserting if it is just being displayed (as in, for the first time the page is loaded, not after the form is submitted). I have used this at the start of my page, although when the page is first displayed, it gives an error about an undifined index (because txtLink doesn't exist yet).
Code: Select all
if(($HTTP_POST_VARS['txtLink'])!=""){
$link = $HTTP_POST_VARS['txtLink'];
$url = $HTTP_POST_VARS['txtUrl'];
$description = $HTTP_POST_VARS['txtDescription'];

$query = "INSERT INTO links (link_title, link_url, link_description) 
		 VALUES ('$link', '$url', '$description')";

mysql_query($query) or die('Error, insert query failed');
}
It works fine when you use the form, but not when you don't. How can I do this? Can I do it with isset somehow?
Reply With Quote

  #2 (permalink)  
Old Jun 20th, 2005, 03:25
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
This works, but there has to be an easier/less messy way to do it:

Code: Select all
if(isset($HTTP_POST_VARS['txtLink'])){
if($HTTP_POST_VARS['txtLink']!=""){
$link = $HTTP_POST_VARS['txtLink'];
$url = $HTTP_POST_VARS['txtUrl'];
$description = $HTTP_POST_VARS['txtDescription'];

$query = "INSERT INTO links (link_title, link_url, link_description) 
		 VALUES ('$link', '$url', '$description')";

mysql_query($query) or die('Error, insert query failed');
}
}
Reply With Quote
  #3 (permalink)  
Old Jun 20th, 2005, 03:32
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
Also, is there a way to unset all the form variables?
Reply With Quote
Reply

Tags
form, action, same, page

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
Image button triggers <form> action rcflyer2005 JavaScript Forum 1 Apr 18th, 2008 07:21
Form Help - Action vs 'To:' Stealthspy589 Web Page Design 3 Feb 17th, 2008 23:08
Form Submission page markusdavid Web Page Design 3 Sep 8th, 2007 00:50
Submitting a form on one page! courtjester Classic ASP 5 Sep 10th, 2004 19:03
Multi page form drnibbles Classic ASP 4 Sep 17th, 2003 21:48


All times are GMT. The time now is 18:39.


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