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,
</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.
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
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.
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
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)
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.
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:
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