hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Quick Question form submission
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

Quick Question form submission

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 10-28-2008, 10:37 AM
Brywright Brywright is offline
Junior Guru Wannabe
 
Join Date: Oct 2004
Posts: 52
Quick Question form submission

Hi, I am entering multiple data into a sql database via a form.
At the moment when you submit the form, it simply says
"item added".
How do i get it to reshow the form when you click submit instead?
As this will make it far quicker in submitting new items.
here is my html code
Code:
<body>
<?php
if(isset($_POST['add']))
{
include 'config.php';
include 'connect.php';

$name = $_POST['name'];
$price = $_POST['price'];

$query = "INSERT INTO pricelist (name, price) VALUES ('$name', '$price')";
mysql_query($query) or die('Error, insert query failed');

mysql_close($conn);
echo "New Item Added";
}
else
{
?>
<form action="<? echo($PHP_SELF) ?>" method="post">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="100">Name</td>
<td><input name="name" type="text" id="name"></td>
</tr>
<tr>
<td width="100">Price</td>
<td><input name="price" type="text" id="price"></td>
</tr>
<tr>
<td width="100"></td>
<td></td>
</tr>
<tr>
<td width="100"></td>
<td><input name="add" type="submit" id="add" value="Add New Price"></td>
</tr>
</table>
</form>
<?php
}
?>
</body>


Many Thanks





Last edited by Brywright : 10-28-2008 at 10:44 AM.

Reply With Quote


Sponsored Links
  #2  
Old 10-28-2008, 11:13 AM
bear bear is offline
Community Leader
 
Join Date: Oct 2002
Location: cognito
Posts: 17,436
You have the form displaying within the "else" statement so it appears only if it's not been submitted (add). Take it out of that conditional, and it should always display.
By the way, you don't appear to be sanitizing any input. I hope this isn't live to the public in that form.





__________________Did you know WHT has rules and a help desk?%20, The Final Frontier

Reply With Quote
  #3  
Old 10-28-2008, 11:16 AM
Brywright Brywright is offline
Junior Guru Wannabe
 
Join Date: Oct 2004
Posts: 52
No its not live, its just in developement at the moment will be adding valdiation later.
Hmm I didnt think it was in the if statement as the php statement is closed before the form is shown, not too sure how to remove it

Reply With Quote
Sponsored Links
  #4  
Old 10-28-2008, 11:21 AM
WebNaz WebNaz is offline
Junior Guru Wannabe
 
Join Date: Aug 2008
Location: Cyprus, EU
Posts: 50
As bear said, remove the "else"
PHP Code:



<body><?phpif(isset($_POST['add'])){include 'config.php';include 'connect.php';$name = $_POST['name'];$price = $_POST['price'];$query = "INSERT INTO pricelist (name, price) VALUES ('$name', '$price')";mysql_query($query) or die('Error, insert query failed');mysql_close($conn);echo "New Item Added";}?><form action="<? echo($PHP_SELF) ?>" method="post"><table width="400" border="0" cellspacing="1" cellpadding="2"><tr><td width="100">Name</td><td><input name="name" type="text" id="name"></td></tr><tr><td width="100">Price</td><td><input name="price" type="text" id="price"></td></tr><tr><td width="100"></td><td></td></tr><tr><td width="100"></td><td><input name="add" type="submit" id="add" value="Add New Price"></td></tr></table></form></body>

Reply With Quote
  #5  
Old 10-28-2008, 11:26 AM
Brywright Brywright is offline
Junior Guru Wannabe
 
Join Date: Oct 2004
Posts: 52
Ah i see, thanks that works great.
You have made my day

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
Lead Generation Part 1 – Form Fills Blog 2012-11-16 09:03:48
Rackspace Blog Looks at Easy Outsourcing for App Development Blog 2012-03-05 19:07:48
WikiLeaks Delays Launch of New Submission System Over SSL Security Concerns Web Hosting News 2011-11-30 15:22:06
Blackberry the UnCloud Blog 2011-10-14 15:28:54
Web Host HostDime Offers Attracta SEO Tools to Resellers Web Hosting News 2011-08-03 17:07:08


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

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

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?