Starnge problem with variables in url and submit

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
genista
Forum Commoner
Posts: 57
Joined: Fri Aug 18, 2006 3:56 pm

Starnge problem with variables in url and submit

Post by genista »

I have a script that grabs an id from a previous page, I then have some html which allows a user to submit some details on that id. The problem I am having is when I hit submit, the page returns, but the update query won't run and in the url of the page the id has pulled back some of the html fields from the html part of the script:

after submitting the url is: supplierenquiryform.php?enquirydetails=&submit=submit

before I submit the url looks like so: supplierenquiryform.php?id=15

id being the supplierid.

Here is the code:

Code: Select all

//session details here 
//checked the user is logged in 
echo '<pre>' . print_r($_GET,true) . '</pre>';

if (isset($_GET['id'])) $id = intval($_GET['id']); //id being supplierid 
$query = "select suppliers.supplierid, suppliers.town, suppliers.county WHERE suppliers.supplierid='" . mysql_real_escape_string($id) . "'"; 

//sort the rows of the database to be used 

//now output some html based on conditions being met: 

   if($haircut == "true"){ 
   echo "<p>The price for service1 is: £$service1price, type of rate: $service1type. Tick this box if you want to enquire on this service:<input type=\"checkbox\" name=\"service1selected\" value=\"true\"</p>"; 

echo "<p>Please select the number of people requiring this service:";  
    $display ='<select size="1" name="service1count">';  
foreach(array('1', '2', '3', '4', '5', '6', '7', '8', '9', '10+') as $value)  
{  
     $selected = (isset($_POST['service1count']) && $_POST['service1count'] == $value ? ' selected="selected"' : ''); 
$display .= "<option value='$value'$selected>$value</option>\n";  
}  
$display .= '</select></p>';  
echo $display; 
} 

//Now to setup the variables to go to the database table: 

  if(isset($_POST['submit']))    
{  

 $_POST['username'] = $row ["username"]; 
 $_POST['supplierid'] = $id; 
if (!isset($_POST['service1selected'])) {    
    $service1selected = 'null';    
}else{  
    $service1selected = $_POST['service1selected'];  
   
      }  
 $service1count = isset($_POST['service1count']) ? $_POST['service1count'] : "";     

//do some validation of input and now the query: 

    $query5 = "INSERT INTO enquiry SET `supplierid` ='$id', `username` = '$username', //etc, etc 

give messages to say that the database is updated ok 
?> 
<html> 
<form> 
<form name="form1" method="post" action="supplierenquiryform.php" 
<tr><td>Please add any details or requests you would like to make:<BR> <TEXTAREA NAME="enquirydetails" value="<?php print isset($_POST["enquirydetails"]) ? $_POST["enquirydetails"] : "" ;?>"COLS=40 ROWS=6></TEXTAREA> 
</td></tr> 
<p><tr><td>&nbsp;</td><td><input name="submit" type="submit" value="submit"></td></tr></p> 
</form> 
</html>
So how can I get the query to run once a user has hit submit and I am assuming it has something to do with $GET part.

You will notice at the top of the script this line:

Code: Select all

echo '<pre>' . print_r($_GET,true) . '</pre>';
On page load it displays:

Code: Select all

Array
(
    [id] => 15
)

on submit it displays:

Code: Select all

Array
(
    [id] => 15
    [submit] => submit
    [enquirydetails] => enquirydetails
)
Any ideas?

Thanks,


G
genista
Forum Commoner
Posts: 57
Joined: Fri Aug 18, 2006 3:56 pm

Post by genista »

I have also noticed that when you hit submit and the page returns the checkboxes are empty along with any other data that you fiiled in, does this help?
User avatar
louie35
Forum Contributor
Posts: 144
Joined: Fri Jan 26, 2007 8:40 am
Location: Dublin
Contact:

Post by louie35 »

first your code is terible. you have two form tag and the action value does not have your id

try this

Code: Select all

<html> 
<form name="form1" method="post" action="supplierenquiryform.php?id=<?php echo $_GET['id'];?>" 
<tr><td>Please add any details or requests you would like to make:<BR> <TEXTAREA NAME="enquirydetails" value="<?php print isset($_POST["enquirydetails"]) ? $_POST["enquirydetails"] : "" ;?>"COLS=40 ROWS=6></TEXTAREA> 
</td></tr> 
<p><tr><td>&nbsp;</td><td><input name="submit" type="submit" value="submit"></td></tr></p> 
</form> 
</html>
Post Reply