need some help with php

  • fonsy2000
  • Novice
  • Novice
  • User avatar
  • Posts: 24

Post 3+ Months Ago

Hi all,

I have this code;
Code: [ Select ]
 
<?
if(isset($_GET['$checkout']))
{
header('otherfile.php');
}
else
?>
<form action="thisfile.php" method="POST">
<select name="select13">
   <option> 145-70-13 </option>
   <option> 145-80-13 </option>
   <option> 205-70-13 </option>
                          </select>
<input name="qt" type="text" size="7" maxlength="5">
<input type="submit" value="Continue" name="Continue">
<input type="submit" value="Checkout" name="Checkout">
</form>
 
  1.  
  2. <?
  3. if(isset($_GET['$checkout']))
  4. {
  5. header('otherfile.php');
  6. }
  7. else
  8. ?>
  9. <form action="thisfile.php" method="POST">
  10. <select name="select13">
  11.    <option> 145-70-13 </option>
  12.    <option> 145-80-13 </option>
  13.    <option> 205-70-13 </option>
  14.                           </select>
  15. <input name="qt" type="text" size="7" maxlength="5">
  16. <input type="submit" value="Continue" name="Continue">
  17. <input type="submit" value="Checkout" name="Checkout">
  18. </form>
  19.  


I just trying pass the data to otherfile.php but is not working, the file stay on thisfile.php, somebody can help me, is easy but I don't get it yet.

thank you
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • George L.
  • Bronze Member
  • Bronze Member
  • George L.
  • Posts: 2209
  • Loc: Malaysia

Post 3+ Months Ago

What is your otherfile.php codes look like?
  • dark_lord
  • Graduate
  • Graduate
  • User avatar
  • Posts: 162
  • Loc: India-Kolkata

Post 3+ Months Ago

here is the right code

Code: [ Select ]
 
<?php
 if(isset($_POST['Checkout']))
 {
    $select13 = $_POST["select13"];
    $qt = $_POST["qt"];
   
 header("Location: otherfile.php?select13=$select13&qt=$qt");
 //header('otherfile.php');
 }
 else
 ?>
 <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
 <select name="select13">
    <option> 145-70-13 </option>
    <option> 145-80-13 </option>
    <option> 205-70-13 </option>
                           </select>
 <input name="qt" type="text" size="7" maxlength="5">
 <input type="submit" value="Continue" name="Continue">
 <input type="submit" value="Checkout" name="Checkout">
 </form>
 
  1.  
  2. <?php
  3.  if(isset($_POST['Checkout']))
  4.  {
  5.     $select13 = $_POST["select13"];
  6.     $qt = $_POST["qt"];
  7.    
  8.  header("Location: otherfile.php?select13=$select13&qt=$qt");
  9.  //header('otherfile.php');
  10.  }
  11.  else
  12.  ?>
  13.  <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
  14.  <select name="select13">
  15.     <option> 145-70-13 </option>
  16.     <option> 145-80-13 </option>
  17.     <option> 205-70-13 </option>
  18.                            </select>
  19.  <input name="qt" type="text" size="7" maxlength="5">
  20.  <input type="submit" value="Continue" name="Continue">
  21.  <input type="submit" value="Checkout" name="Checkout">
  22.  </form>
  23.  


You have to work hard on syntax

or simply put this to get all variable to next page and extract using $_POST method

Code: [ Select ]
<form action="otherfile.php" method="post">
<select name="select13">
    <option> 145-70-13 </option>
    <option> 145-80-13 </option>
    <option> 205-70-13 </option>
                         </select>
<input name="qt" type="text" size="7" maxlength="5">
<input type="submit" value="Continue" name="Continue">
<input type="submit" value="Checkout" name="Checkout">
</form>
  1. <form action="otherfile.php" method="post">
  2. <select name="select13">
  3.     <option> 145-70-13 </option>
  4.     <option> 145-80-13 </option>
  5.     <option> 205-70-13 </option>
  6.                          </select>
  7. <input name="qt" type="text" size="7" maxlength="5">
  8. <input type="submit" value="Continue" name="Continue">
  9. <input type="submit" value="Checkout" name="Checkout">
  10. </form>
  • George L.
  • Bronze Member
  • Bronze Member
  • George L.
  • Posts: 2209
  • Loc: Malaysia

Post 3+ Months Ago

dark_lord, I hope you could explain what will happen when using your codes above.
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

George L. wrote:
dark_lord, I hope you could explain what will happen when using your codes above.

What the first code is doing is submitting the first form as POST.

It submits those values to the current page and if the submit button is pressed, then those post files are generated into a GET url.

A GET url looks like:

file.php?get=this&this=get

then the other file (file.php in this example) would GET those values

Code: [ Select ]
$get = $_GET['get'];
$this = $_GET['this'];
  1. $get = $_GET['get'];
  2. $this = $_GET['this'];


OR you could have the form submit to another page using the GET method... that's where the GET url is automatically built and works basically the same way as above.


Another option is to have the form submit to itself using the GET method and the file included using GET request. I hope that made sense :)
  • George L.
  • Bronze Member
  • Bronze Member
  • George L.
  • Posts: 2209
  • Loc: Malaysia

Post 3+ Months Ago

I know there needs to be a GET thing in the otherfile.php, just think that someone might not be clear of these if he is asking something about POST in php. And when posting some codes, I hope he actually tried those if it is working before saying something like " This is the right one ". Or at least explain a little more.
  • fonsy2000
  • Novice
  • Novice
  • User avatar
  • Posts: 24

Post 3+ Months Ago

thank you guys with this help, it worked, but, what about if I want to use arrays on this code, something like select13 select14, select15, and where each need a value;

select13[1]=100
select13[2]=120
select13[3]=130

and when it finish go to otherfile.php, I think something like this;

Code: [ Select ]
 
 <?php
  if(isset($_POST['Checkout']))
  {
$x=$x+1
while ($x<$counter); {
     
$select13[x] = $_POST["select13"];
     $qt[x] = $_POST["qt"];
print "$select13[x]";
print "$qt[x]";
}
   
  header("Location: otherfile.php?select13=$select13&qt=$qt");
 
  }
  else
  ?>
  <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
 
 
     $counter1=$counter1+1 ;
     <select name="select13[$counter]">
     <option> 145-70-13 </option>
     <option> 145-80-13 </option>
     <option> 205-70-13 </option>
     </select>
 
 
 <input name="qt" type="text" size="7" maxlength="5">
  <input type="submit" value="Continue" name="Continue">
  <input type="submit" value="Checkout" name="Checkout">
  </form>
 
  1.  
  2.  <?php
  3.   if(isset($_POST['Checkout']))
  4.   {
  5. $x=$x+1
  6. while ($x<$counter); {
  7.      
  8. $select13[x] = $_POST["select13"];
  9.      $qt[x] = $_POST["qt"];
  10. print "$select13[x]";
  11. print "$qt[x]";
  12. }
  13.    
  14.   header("Location: otherfile.php?select13=$select13&qt=$qt");
  15.  
  16.   }
  17.   else
  18.   ?>
  19.   <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
  20.  
  21.  
  22.      $counter1=$counter1+1 ;
  23.      <select name="select13[$counter]">
  24.      <option> 145-70-13 </option>
  25.      <option> 145-80-13 </option>
  26.      <option> 205-70-13 </option>
  27.      </select>
  28.  
  29.  
  30.  <input name="qt" type="text" size="7" maxlength="5">
  31.   <input type="submit" value="Continue" name="Continue">
  32.   <input type="submit" value="Checkout" name="Checkout">
  33.   </form>
  34.  


tell how is possible, I am stuck there.
  • dark_lord
  • Graduate
  • Graduate
  • User avatar
  • Posts: 162
  • Loc: India-Kolkata

Post 3+ Months Ago

George L. wrote:
dark_lord, I hope you could explain what will happen when using your codes above.


awwww.... i guess he has that basic knowledge of using $_GET and $_POST

also the later one is more efficient as it reduces number of lines (of coding) and one round trip to server. In addition post method is the added advantage.
  • dark_lord
  • Graduate
  • Graduate
  • User avatar
  • Posts: 162
  • Loc: India-Kolkata

Post 3+ Months Ago

fonsy2000 wrote:
thank you guys with this help, it worked, but, what about if I want to use arrays on this code, something like select13 select14, select15, and where each need a value;

select13[1]=100
select13[2]=120
select13[3]=130

and when it finish go to otherfile.php, I think something like this;

Code: [ Select ]
 
 <?php
  if(isset($_POST['Checkout']))
  {
$x=$x+1
while ($x<$counter); {
     
$select13[x] = $_POST["select13"];
     $qt[x] = $_POST["qt"];
print "$select13[x]";
print "$qt[x]";
}
   
  header("Location: otherfile.php?select13=$select13&qt=$qt");
 
  }
  else
  ?>
  <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
 
 
     $counter1=$counter1+1 ;
     <select name="select13[$counter]">
     <option> 145-70-13 </option>
     <option> 145-80-13 </option>
     <option> 205-70-13 </option>
     </select>
 
 
 <input name="qt" type="text" size="7" maxlength="5">
  <input type="submit" value="Continue" name="Continue">
  <input type="submit" value="Checkout" name="Checkout">
  </form>
 
  1.  
  2.  <?php
  3.   if(isset($_POST['Checkout']))
  4.   {
  5. $x=$x+1
  6. while ($x<$counter); {
  7.      
  8. $select13[x] = $_POST["select13"];
  9.      $qt[x] = $_POST["qt"];
  10. print "$select13[x]";
  11. print "$qt[x]";
  12. }
  13.    
  14.   header("Location: otherfile.php?select13=$select13&qt=$qt");
  15.  
  16.   }
  17.   else
  18.   ?>
  19.   <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
  20.  
  21.  
  22.      $counter1=$counter1+1 ;
  23.      <select name="select13[$counter]">
  24.      <option> 145-70-13 </option>
  25.      <option> 145-80-13 </option>
  26.      <option> 205-70-13 </option>
  27.      </select>
  28.  
  29.  
  30.  <input name="qt" type="text" size="7" maxlength="5">
  31.   <input type="submit" value="Continue" name="Continue">
  32.   <input type="submit" value="Checkout" name="Checkout">
  33.   </form>
  34.  


tell how is possible, I am stuck there.

:?:
not possible!!!
you are confusing the whole thing about returning an array in function and requesting an array using $_REQUEST (includes both $_GET and $_POST) method.

To receive an array in other page instead of sending the array list in a sequence of $_REQUEST parameter,
you can just put that array in $_SESSION variable, and retrieve it on next page.

Post Information

  • Total Posts in this topic: 9 posts
  • Users browsing this forum: No registered users and 98 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.