genista Posted April 23, 2007 Share Posted April 23, 2007 Hi all, As per the title I have a script that is ignoring the isset $POST submit and running the query on the page loading, am completly stumped as to why this is happening... //session data //get data from the database - this works fine, no problems here if(isset($_POST['submit'])) { $_POST['username'] = $row ["username"]; $_POST['supplierid'] = $id; $enquirydetails = isset($_POST['enquirydetails']) ? $_POST['enquirydetails'] : ""; //data validation - works fine $query = "INSERT INTO enquiry SET `supplierid` ='$id', `username` = '$username', `enquirydetails` = '$enquirydetails'"; $result = mysql_query($query, $link) or die('Update failed: ' . mysql_error()); // echo "<p><td><tr>$query;</td></tr></p>"; mysql_info($link) ; if(mysql_affected_rows($link) == 0) { //$link next to affected rows and mysql query echo ''; } else { echo 'Your enquiry has been submitted successfully, in order to display the changes you have made please click <a href=suppliers.php>here</a> to go back to the main member page.'; echo $query; } } <html> <title><?php print $page ?></title> <br><b>If you wish to make an enquiry as to whether this supplier is available on your chosen day (as displayed below) and get a final quote, please click Submit below</a>.</b></br> <td><tr><?php echo "<br>Your chosen day: $day/ $month/ $year</td></tr>";?> <form> <form action="<?=$_SERVER["PHP_SELF"]?>" method="POST"> <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> This script is an extremly shortened one, as the full length one is huge. However, I have echo'd the query and the query is fine, no errors, all the data retrieved from the database is fine, all the field validation is fine, it is just ignoring that: " if(isset($_POST['submit'])){" and running the query anyway. Any ideas? G Quote Link to comment https://forums.phpfreaks.com/topic/48259-script-ignoring-isset-and-runing-query-regardless/ Share on other sites More sharing options...
MadTechie Posted April 23, 2007 Share Posted April 23, 2007 Why do you say its ignoring the isset? the submit will always be set when the form is posted! Quote Link to comment https://forums.phpfreaks.com/topic/48259-script-ignoring-isset-and-runing-query-regardless/#findComment-235887 Share on other sites More sharing options...
genista Posted April 23, 2007 Author Share Posted April 23, 2007 Well the query runs on the loading of the page, not when you press submit - which is the problem. Quote Link to comment https://forums.phpfreaks.com/topic/48259-script-ignoring-isset-and-runing-query-regardless/#findComment-235946 Share on other sites More sharing options...
MadTechie Posted April 23, 2007 Share Posted April 23, 2007 is that all the code ? assume your aware your missing <?php at the start and ?> before the <html> also i am pretty sure the error isn't in the code to supplied but in a few lines before it Quote Link to comment https://forums.phpfreaks.com/topic/48259-script-ignoring-isset-and-runing-query-regardless/#findComment-235947 Share on other sites More sharing options...
genista Posted April 23, 2007 Author Share Posted April 23, 2007 Hi Thanks, I have all of the <?php stuff in there, there are no actual errors in the script it runs fine, just not when I want it to. The script includes many more rows being taken and posted to a database. I have printed all the variables they are fine, the query itself is fine as it posts the username and supplierid into the database on the page load. When I hit submit the script works fine, ie if I enter some data then hit submit it re-submits the data. For some reason though it is running the query on page load which is very strange! Quote Link to comment https://forums.phpfreaks.com/topic/48259-script-ignoring-isset-and-runing-query-regardless/#findComment-235957 Share on other sites More sharing options...
kenrbnsn Posted April 23, 2007 Share Posted April 23, 2007 At the start of the script, put <?php echo '<pre>' . print_r($_POST,true) . '</pre>'; ?> this will show you what's in the $_POST array when your script starts. If $_POST['submit'] is not set when your script starts and the condition is met later, then make sure your script isn't setting it somewhere. Ken Quote Link to comment https://forums.phpfreaks.com/topic/48259-script-ignoring-isset-and-runing-query-regardless/#findComment-235969 Share on other sites More sharing options...
genista Posted April 23, 2007 Author Share Posted April 23, 2007 Ok so having put that at the top of the script I get this: Array ( [submit] => Submit ) Thanks, G Quote Link to comment https://forums.phpfreaks.com/topic/48259-script-ignoring-isset-and-runing-query-regardless/#findComment-235988 Share on other sites More sharing options...
MadTechie Posted April 23, 2007 Share Posted April 23, 2007 So submit is being set! Quote Link to comment https://forums.phpfreaks.com/topic/48259-script-ignoring-isset-and-runing-query-regardless/#findComment-235998 Share on other sites More sharing options...
genista Posted April 23, 2007 Author Share Posted April 23, 2007 Ok, I think I am getting there, this script loads after the user hits submit elsewhere so I am assuming that this is causing this script to have submit set. Out of curiosity is it quicker to change the previous script or is there something I can add to the top of this one to say submit = 0 or what ever is needed? Thanks, G Quote Link to comment https://forums.phpfreaks.com/topic/48259-script-ignoring-isset-and-runing-query-regardless/#findComment-236002 Share on other sites More sharing options...
MadTechie Posted April 23, 2007 Share Posted April 23, 2007 change <?php if(isset($_POST['submit'])) { $_POST['username'] = $row ["username"]; $_POST['supplierid'] = $id; ?> to <?php if( isset($_POST['username']) && isset($_POST['supplierid']) ) { $_POST['username'] = $row ["username"]; $_POST['supplierid'] = $id; ?> Quote Link to comment https://forums.phpfreaks.com/topic/48259-script-ignoring-isset-and-runing-query-regardless/#findComment-236011 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.