Starnge problem with variables in url and submit
Posted: Wed Apr 25, 2007 7:57 am
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:
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:
On page load it displays:
on submit it displays:
Any ideas?
Thanks,
G
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> </td><td><input name="submit" type="submit" value="submit"></td></tr></p>
</form>
</html>You will notice at the top of the script this line:
Code: Select all
echo '<pre>' . print_r($_GET,true) . '</pre>';Code: Select all
Array
(
[id] => 15
)on submit it displays:
Code: Select all
Array
(
[id] => 15
[submit] => submit
[enquirydetails] => enquirydetails
)Thanks,
G