Jump to content

Recommended Posts

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

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!

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

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

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;
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.