ncorrieri Posted February 20, 2007 Share Posted February 20, 2007 hey all - quick question, im sure a stupid one, but could use a hand nonetheless Page process Form > Post to submit page that posts to db > redirects user to 3rd page Looking to take the variables sent submit page and put them into the link going to 3rd page. currently, it looks like this <? require_once("config.php"); require_once("mail.php"); $data = $_POST; $data['dob'] = "$data[dobYYYY]-$data[dobMM]-$data[dobDD]"; $t = "registration"; $q = " INSERT INTO $t (`id`,`prefix`,`suffix`,`fname`,`lname`,`gender`,`dob`, `address1`,`address2`,`city`,`state`,`email`,`areacode`, `regtime`,`ipaddress`,`offer`,`affiliate`,`subaffiliate`) VALUE ( null,[prefix],[suffix],[fname],[lname],[gender],[dob], [address1],[address2],[city],[state],[email], [areacode],NOW(),[ipaddress],[offer],[affiliate],[subaffiliate])"; foreach ($data as $key => $value) { $value = "'".mysql_real_escape_string($value)."'"; $q = str_replace("[$key]",$value,$q ); } mysql_query($q); send_mail($data); ?> Submit data and redirecting... <script>document.location="<?=$forward_url?>"</script> ... so how would we be able to put specific values into the forwarded url location Replacing "<?=$forward_url?>" with example "page3.php?fname=Variable1&lname=Variable2" so would i need to include that in the <?php> tag? and how do i break up the URL i am forwarding to? and how would i insert variables from the above code, would it be simply [fieldname] or would i need to do .$_POST[fieldname]. or do i need to put single quotes around it? like .. "http://ww.page.com/page.php?field1=" '.$_POST[fname].' "&field2=" '.$_POST[lname].' " and am i doing that right? god i feel silly askign these Link to comment https://forums.phpfreaks.com/topic/39368-variables-into-url/ Share on other sites More sharing options...
paul2463 Posted February 20, 2007 Share Posted February 20, 2007 if you have already created the variables then use them <?php // all your stuff minus any html stuff, everything inside php tags header( 'Location: ../../../../index.php?field1='.$variable1.'&field2='.$varaiable2); ?> Link to comment https://forums.phpfreaks.com/topic/39368-variables-into-url/#findComment-189898 Share on other sites More sharing options...
ncorrieri Posted February 21, 2007 Author Share Posted February 21, 2007 the data's being sent to page as post (as in the brackets in the insert into mysql command, so how does that work, variable is $data right now on this page, but fields/data being posted to page names are ,[prefix],[suffix],[fname],[lname],[gender],[dob], [address1],[address2],[city],[state],, [areacode],[ipaddress],[offer],[affiliate],[subaffiliate] Should i just do '.$_POST(prefix).' to pass the prefix value? Link to comment https://forums.phpfreaks.com/topic/39368-variables-into-url/#findComment-190156 Share on other sites More sharing options...
JasonLewis Posted February 21, 2007 Share Posted February 21, 2007 $_POST['prefix'] not $_POST(prefix). so you would do something like this: <form action="page2.php" method="POST"> Variable 1: <input type="text" name="var1"><br> Variable 2: <input type="text" name="var2"><br> <input type="submit" name="submit" value="go"> </form> [code=php:0] then on page2.php: [code=php:0] $var1 = $_POST['var1']; $var2 = $_POST['var2']; mysql_query("INSERT INTO `table` (`var1`,`var2`) VALUES ('{$var1}', '{$var2}')"); header("Location: page3.php?var1={$var1}&var2={$var2}"); then on page3.php: $var1 = $_GET['var1']; $var2 = $_GET['var2']; echo "Variable 1 was {$var1} and Variable 2 was {$var2}"; Link to comment https://forums.phpfreaks.com/topic/39368-variables-into-url/#findComment-190288 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.