Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-08-2004, 10:46 AM   PM User | #1
rossored
New Coder

 
Join Date: May 2004
Location: Earth
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
rossored is an unknown quantity at this point
going bald fast thanks to this

Hope someone can help me here, I'm a bit of a beginner (understatement) with php and I'm having a real problem with something that ought to be fairly simple from what I've read.

I have a form on a basic html page ( call it page1.html ) which I am wanting to get to submit three fields to the next page ( page2.html ) : I want two of the fields to echo in another part of the page2.html ( I can do that bit! ) but I also want those two values (and the third value) to be picked up and inserted into a mySQL database upon submission of the next form, which is also on page2.html. This form contains an additional 12 fields which I want written to the database, along with the values from page1.html

Ideally, I would also like to be able to send 4 of the second lot of 12 fields to another webpage via URL.

Can this be done? If so, can anyone suggest a method of doing this, or tell me where to look?

Yours, really really stuck and pulling my hair out now,

RR
rossored is offline   Reply With Quote
Old 06-08-2004, 11:24 AM   PM User | #2
MrShed
New Coder

 
Join Date: Jun 2004
Location: Newcastle, England
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
MrShed is an unknown quantity at this point
Pass the three values as hidden form items on the second page
__________________
Beauty is in the eye of the beer-holder

Man who smoke pot, choke on handle
MrShed is offline   Reply With Quote
Old 06-08-2004, 01:18 PM   PM User | #3
rossored
New Coder

 
Join Date: May 2004
Location: Earth
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
rossored is an unknown quantity at this point
Yeah I can do that - thanks - its the rest of it I'm struggling with.
rossored is offline   Reply With Quote
Old 06-08-2004, 01:35 PM   PM User | #4
MrShed
New Coder

 
Join Date: Jun 2004
Location: Newcastle, England
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
MrShed is an unknown quantity at this point
ERm....what exactly do u mean the rest of it? Post some code if u can, I'll try and help as best i can
__________________
Beauty is in the eye of the beer-holder

Man who smoke pot, choke on handle
MrShed is offline   Reply With Quote
Old 06-08-2004, 02:00 PM   PM User | #5
rossored
New Coder

 
Join Date: May 2004
Location: Earth
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
rossored is an unknown quantity at this point
Okay: this is the form from the first page -

<form action="http://www.domain.com/details.php?code=ROL" method="post">
<div align="center">
<input type="hidden" name="comp" value="c1">
</div>
<p align="center" class="style6">I <span class="style6"> would like</span>
<select name="quantity">
<option value="5.00">1 ticket</option>
<option value="10.00">2 tickets</option>
<option value="15.00">3 tickets</option>
<option value="20.00">4 tickets</option>
<option value="25.00">5 tickets</option>
</select>
(Removed some code here that isnt ness. for this post)
</form>

So that should send the two values = "comp" and "quantity" - to my details.php page.


On the details.php page, I have got this form : (code edited heavily as there's loads in there that wont help this question)


<form name="details" method="post" action="/tester.php">
<input name="fname" type="text" size="40">


<tr>
<td> <input name="address_1" type="text" size="50">
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name="address_1a" type="text" size="50"></td>
</tr>
<tr>
<td class="style5">Town * </td>
<td><input name="address_2" type="text" size="50"></td>
</tr>
<tr>
<td class="style5">County/State/Province * </td>
<td><input name="county" type="text" size="40"></td>
</tr>
<tr>
<td class="style5">Country * </td>
<td>
<select name="country">
(LIST OF COUNTRIES)
</select>
</td>
</tr>
<tr>
<td class="style5">Postcode/Zip * </td>
<td><input name="zip" type="text" size="30"></td>
</tr>
<tr>
<td class="style5">Email Address * </td>
<td><input name="submit_by" type="text" size="30" maxlength="40"></td>
</tr>
<tr>
<td class="style5">Main Telephone * </td>
<td><input name="PrPhone" type="text" size="40"></td>
</tr>
<tr>
<td class="style5">Second Telephone </td>
<td><input name="SecPhone" type="text" size="40"></td>
</tr>
(CODE EDITED AGAIN HERE AS ITS JUST SUBMIT BUTTONS ETC)
<tr>
<td>
<input type="checkbox" name="agreed" value="checkbox">
<span class="style5"> <span class="style4">I have read and agreed to the</span> <a href="terms.htm">Terms &amp; Conditions</a></span></td>
</tr>

</tr>
THIS IS THE BIT I'M PRETTY SURE IS COMPLETELY AND UTTERLY WRONG
<input type="hidden" value="quantity">
<?php $_GET=('$ROL');?>
<input type="hidden" value="ROL">
</form>



So - I have no idea how to get the information - all the fields - from this page into my database, and how to send a further 4 values - namely : 'fname', 'address_1', 'zip' and 'quantity' - into the URL and over to another page.

I hope this makes sense. If not I may well just throw the PC out of the window.

Thanks, RR
rossored is offline   Reply With Quote
Old 06-08-2004, 02:13 PM   PM User | #6
mindlessLemming
Senior Coder

 
Join Date: Oct 2003
Location: Australia
Posts: 1,963
Thanks: 0
Thanked 0 Times in 0 Posts
mindlessLemming is an unknown quantity at this point
I'm as much a php newb as yourself, probably more so, but how about this:
PHP Code:
 <?php $ROL=$_GET['ROL'];?>
<input type="hidden" value="<?php print $ROL?>">
__________________

I take no responsibility for the above nonsense.


Left Justified
mindlessLemming is offline   Reply With Quote
Old 06-08-2004, 02:15 PM   PM User | #7
MrShed
New Coder

 
Join Date: Jun 2004
Location: Newcastle, England
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
MrShed is an unknown quantity at this point
Erm...ok ill try my best but im very confused today because i am extremely hungover so sorry if i make little sense!

to put it into the database, im assuming you dont kno at all how to connect etc? (assuming ur using mysql):

mysql_connect(server, username, password)

then mysql_select_db(database name)

then

mysql_query("INSERT INTO tablename SET address='{$HTTP_POST_VARS['address']}' name='{$HTTP_POST_VARS['name']}'")

etc etc

Obviously the database and table will have to be created first.

to make that bit easier have a referenced variable eg:

$form =& $HTTP_POST_VARS;

I think this is what you are asking....but as I say I am hungover so am not really with it! If you have an instant messenger or sumthing ill help u thru step by step if u want
__________________
Beauty is in the eye of the beer-holder

Man who smoke pot, choke on handle
MrShed is offline   Reply With Quote
Old 06-08-2004, 02:16 PM   PM User | #8
MrShed
New Coder

 
Join Date: Jun 2004
Location: Newcastle, England
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
MrShed is an unknown quantity at this point
Oh and yeh forgot about that bit....what mindlesslemming has just posted should work afaik to pass it to the next page
__________________
Beauty is in the eye of the beer-holder

Man who smoke pot, choke on handle
MrShed is offline   Reply With Quote
Old 06-08-2004, 02:33 PM   PM User | #9
rossored
New Coder

 
Join Date: May 2004
Location: Earth
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
rossored is an unknown quantity at this point
ok thanks folks, i'll give all that a try and let u know how i get on

(it is a mySQL db, and I know how to connect to it, just cant seem to actually get it into there!)
rossored is offline   Reply With Quote
Old 06-08-2004, 02:35 PM   PM User | #10
MrShed
New Coder

 
Join Date: Jun 2004
Location: Newcastle, England
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
MrShed is an unknown quantity at this point
Lol sorry I misunderstood obviously I'm totally not with it today!! If you need anymore help pm me and I'll be happy to help
__________________
Beauty is in the eye of the beer-holder

Man who smoke pot, choke on handle
MrShed is offline   Reply With Quote
Old 06-08-2004, 05:47 PM   PM User | #11
rossored
New Coder

 
Join Date: May 2004
Location: Earth
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
rossored is an unknown quantity at this point
OK made a bit of progress but still have a problem :

this is the modified code from the bottom of the second form - (again edited and some values changed)


<input type="hidden" value="quantity">
<?php $compcode=$_GET['compcode'];?>
<input type="hidden" value="<?php print $compcode; ?>">
</form>
<?$dbh=mysql_connect ("localhost", "server_username", "password") or die ('Cannot connect to MySQL database because: ' . mysql_error());
mysql_select_db ("dbname");?>
<?
$db="dbname";
mysql_query ("INSERT INTO dbname (quantity, compcode, fname, address_1, address_1a, address_2, county, country, zip, submit_by, PrPhone, SecPhone) VALUES ('$quantity','$compcode','$fname','$address_1','$address_1a','$address_2','$county','$country','$zip ','$submit_by','$PrPhone','$SecPhone')");
?>

</table>

Connect to db fine.

However - only inserts the fields from the first form - 'quantity' and 'compcode' - none of the fields from the second form go in.

Although - MrShed, I changed some of your SQL code because I kept getting a SQL error : so is the problem in the SQL query part that I have changed? yours didnt seem to work but perhaps I am doing something else wrong (this is more than likely btw)

Thanks for all your help, I am a newbie at most of this.


PS How do I get some of the values from this second form into the url for submission to another site? Sorry to sound like a dumbass. I am.

Last edited by rossored; 06-08-2004 at 05:49 PM..
rossored is offline   Reply With Quote
Old 06-08-2004, 06:34 PM   PM User | #12
MrShed
New Coder

 
Join Date: Jun 2004
Location: Newcastle, England
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
MrShed is an unknown quantity at this point
The second pages variables will not be going in because you won't have submitted the form yet if that code is in the second page. You need to have the insert code in a third page. And my MySQL query could well have been wrong....yours looks ok imo.
__________________
Beauty is in the eye of the beer-holder

Man who smoke pot, choke on handle
MrShed is offline   Reply With Quote
Old 06-09-2004, 08:45 AM   PM User | #13
rossored
New Coder

 
Join Date: May 2004
Location: Earth
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
rossored is an unknown quantity at this point
Okay, thanks for your help so far.

Have now created a third page with the mySQL INSERT command on it - now all the data from page two goes in, but the first two fields from page one - 'compcode' and 'quantity' must be getting lost somewhere.

This is the code I've got in the bottom of the SECOND form, which I think brings the values over the the FIRST form (as you guys suggested yesterday - thanks)

<input type="hidden" value="quantity">
<?php $compcode=$_GET['compcode'];?>
<input type="hidden" value="<?php print $compcode; ?>">


And so I've put this code in the third page, just above the mySQL INSERT command :

<input type="hidden" value="quantity">
<input type="hidden" value="compcode">
<?$dbh=mysql_connect ("localhost" etc etc)

But, as I say, only the values from the second form get submitted, nothing at all from the first form.

Can anyone shed any light on this? I know I'm doing something wrong here but I really dont know what.

Also, how do I pass variables in the URL to another page? I know there is the " page.php=action&add " command, but " page.php=action&add'$compcode' " does not seem to work.

Thanks again for all your help so far guys, I'll get there in the end.
rossored is offline   Reply With Quote
Old 06-09-2004, 09:55 AM   PM User | #14
MrShed
New Coder

 
Join Date: Jun 2004
Location: Newcastle, England
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
MrShed is an unknown quantity at this point
OK....so theres obviously a problem with this bit of code/html:

<input type="hidden" value="quantity">
<input type="hidden" value="compcode">
<?$dbh=mysql_connect ("localhost" etc etc)

ahhh think ive spotted the problem. have you got those first two lines inside php tags? or outside of them? if they are not in php tags, quantity and compcode will be getting parsed as that text, not as the variable contents(and they should be $quantity and $compcode). Oh and if you haven't named them is it possible to access them? I don't know but I wouldn't have thought so. So something like this:

PHP Code:

<?php
echo <<<HTML_CODE
<input type="hidden" value="$quantity" name="quantity">
<input type="hidden" value="$compcode" name="compcode">
HTML_CODE;
//rest of code etc
?>
Try that see if it works....I think its right. If it doesn't work I'm starting to think you should pass the variables using a session.....but try that first.
__________________
Beauty is in the eye of the beer-holder

Man who smoke pot, choke on handle
MrShed is offline   Reply With Quote
Old 06-09-2004, 10:48 AM   PM User | #15
rossored
New Coder

 
Join Date: May 2004
Location: Earth
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
rossored is an unknown quantity at this point
No, its wasnt in php tags, but that new code doesnt work : get parse errors on first/second lines of that code.
rossored is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 05:08 AM.


Advertisement
Log in to turn off these ads.