Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
Making submit buttons unique
Old 11-28-2007, 07:26 PM Making submit buttons unique
Average Talker

Posts: 20
Name: Levi
Trades: 0
I need to make 2 submit buttons one that if clicked sends data to a mysql server the other if clicked takes data from the mysql server.

This is what my submit buttons are currently.
Code:
<input type="submit" name="submit" id="submit" value="Create an Account" />
<input type="submit" name="submit" id="submit" value="Tell Me My Password" />
I am using an if statement in perl to try and get it to do one of the other action for it like this.

Code:
if ($submit == "Create an Account")
{
Send everything to the database
}
Code:
if ($submit == "Tell Me My Password")
{
Send password back
}
Right now it will run through both of them sending the data to the mysql database as well as sending it back and printing it, and I don't know how to make it so that it will only run through the one clicked on. Can anyone help me?
Levi_ is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-28-2007, 08:12 PM Re: Making submit buttons unique
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,516
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
You can't have two elements with the same ID.

Just give the buttons different names

"create" & "send_pwd" or submit1 & submit2
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-28-2007, 08:19 PM Re: Making submit buttons unique
Nathand's Avatar
Extreme Talker

Posts: 233
Location: USA
Trades: 0
What do you tell the form to do once submitted? E.G. <form action = something>.

First change the name of one of the submit buttons so you have two different names. Something like this:
Code:
<input type="submit" name="submit1" id="submit" value="Create an Account" />
<input type="submit" name="submit2" id="submit" value="Tell Me My Password" />
Then do something like this inside the file that gets executed:
PHP:
Code:
if(isset($_POST["submit1"]))
{
create account code
}
else if(isset($_POST["submit2"]))
{
retrieve password
}
Nathand is offline
Reply With Quote
View Public Profile
 
Old 11-28-2007, 09:15 PM Re: Making submit buttons unique
Average Talker

Posts: 20
Name: Levi
Trades: 0
I changed them so that the first input is submit and the second one is submit2.

Code:
                            <form name="info" id="info" action="cgi-bin/booksonline.cgi" method="post">
                            Account Number: <input type="text" name="username" id="username" size="5" maxlength="5" /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            Password: <input type="password" name="password" id="password" size="10" maxlength="10" />
                            <br /><br />
                            <input type="submit" name="submit" id="submit" value="Create and Account" onclick="" />
                            <input type="submit" name="submit2" id="submit2" value="Tell Me My Password" onclick=""  />
                            </form>
Thats my form code, it is linked to a perl file that says this
Code:
if ($submit == "Create an Account")
{
Send everything to the database
}

elsif ($submit2 == "Tell Me My Password")
{
retrieve the password
}
It still comes up as completing the first if, but it does not get to the second one anymore. That means it is returning the first if true every time I assume?
Levi_ is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Making submit buttons unique
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.47363 seconds with 12 queries