...

View Full Version : going bald fast thanks to this



rossored
06-08-2004, 10:46 AM
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

MrShed
06-08-2004, 11:24 AM
Pass the three values as hidden form items on the second page

rossored
06-08-2004, 01:18 PM
Yeah I can do that - thanks - its the rest of it I'm struggling with.

MrShed
06-08-2004, 01:35 PM
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

rossored
06-08-2004, 02:00 PM
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

mindlessLemming
06-08-2004, 02:13 PM
I'm as much a php newb as yourself, probably more so, but how about this:


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

:)

MrShed
06-08-2004, 02:15 PM
Erm...ok ill try my best but im very confused today because i am extremely hungover :p 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

MrShed
06-08-2004, 02:16 PM
Oh and yeh forgot about that bit....what mindlesslemming has just posted should work afaik to pass it to the next page

rossored
06-08-2004, 02:33 PM
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!)

MrShed
06-08-2004, 02:35 PM
Lol sorry I misunderstood obviously :p I'm totally not with it today!! If you need anymore help pm me and I'll be happy to help

rossored
06-08-2004, 05:47 PM
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.

MrShed
06-08-2004, 06:34 PM
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.

rossored
06-09-2004, 08:45 AM
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.

MrShed
06-09-2004, 09:55 AM
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
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.

rossored
06-09-2004, 10:48 AM
No, its wasnt in php tags, but that new code doesnt work : get parse errors on first/second lines of that code.

MrShed
06-09-2004, 11:54 AM
k...hmm. I'm not sure then. But you definitely need those 2 lines of html code ive given u there, and u need to echo them from inside php. I'm not sure what I've done wrong....just play about with it

rossored
06-10-2004, 05:47 PM
I've sorted it.

The HTML code wasnt ness.

This is the end result :

<form>
<input type="hidden" name="compcode" value="<? echo $compcode ?>">
<input type="hidden" name="quantity" value="<? echo $quantity ?>">
</form>

Works like a charm. Turns out the fields werent being echoed correctly in the first place, so weren't going to the db.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum