• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 474
  • Last Modified:

PHP if (submit)

Below is code from the JSRS 'Select Demo'. I want the result to be placed into select.php (below the dropdown boxes). I have replaced result.php with select.php. I have written query code to printout the mankeName field as practice. My question is where do I place the if(submit) line of code ? Also give a sample preferred if(submit) line of code.

Query code if needed -
require ("local_connection.php");
$result = mysql_query("SELECT DISTINCT makeName FROM makes ORDER BY makeName ASC", $mysql_access) or die("Sql error : " . mysql_error());
$num_makes = mysql_num_rows($result);
     echo ("There are $num_makes Makes.<br>");
$i = 0;
while($row = mysql_fetch_array($result)) {
$makeName[$i]=mysql_result($result,$i,"makeName");
echo ("MakeName [$i] = $makeName[$i]<br>");
  $i++;
}

Thanks,
Michael
0
mhoggatt1
Asked:
mhoggatt1
  • 3
  • 2
1 Solution
 
RoonaanCommented:
Add a hidden field to your form (<input type="hidden" name="form_action" value="mysubmitkey" />) or use one of your mandatory fields to recognize that the correct form data is received:

if($_SERVER['REQUEST_METHOD'] == 'POST' && 'mysubmitkey' == @$_POST['form_action'])
{
}

-r-
0
 
mhoggatt1Author Commented:
Thanks for the reply. Actually where would you put this line in the code I sent ?
Thanks,
0
 
RoonaanCommented:
I am not sure what the functionality is that you require?

When lookin up JSRS "Select demo" on google, It seems to be some multi-selectbox code where selectbox content relies on selected item in another box. This does (for now) however not match the code you provided, because it doesn't even contain a selectbox in the output.

-r-
0
 
mhoggatt1Author Commented:
Hi Roonaan,
   I forgot to paste the select.php code for you to view. Here also is the link to the demo if you need it.

http://www.ashleyit.com/rs/jsrs/select/php/select.php

<html>
<head>
  <title>JSRS Select Demo</title>
  <script language="javascript" src="jsrsClient.js"></script>
  <script language="javascript" src="selectphp.js"></script>
  <style>
    body{background:#dddddd;text-align:center;}
    #sel {width:100%;margin: 0px auto 0px auto;}
    #show {background-color:darkgray;width:80%;height:45px;text-align:center;margin-top:15px;padding-top:10px;}
  </style>
</head>
<?php
  $make = isset($_POST['lstMake']) ? $_POST['lstMake'] : -99;
  $model = isset($_POST['lstModel']) ? $_POST['lstModel'] : -99;
  $options = isset($_POST['lstOptions']) ? $_POST['lstOptions'] : -99;
?>
<body onload="preselect('<?php echo $make;?>', '<?php echo $model;?>', '<?php echo $options;?>', 1);" onhelp="jsrsDebugInfo();return false;">
<h2>JSRS Select Box Filling Demo - page #1</h2>
<form name="QForm" method="post" action="./select.php">
<div id="sel">
<table class="normal" width="575" BORDER="0" CELLSPACING="2" CELLPADDING="2" VALIGN="TOP">
<?php
  SelectBox ("Make",    "lstMake");    
  SelectBox ("Model",   "lstModel");    
  SelectBox ("Options", "lstOptions");  
?>
</table>
<div id="show">
  <input type="submit" name="cmdSubmit" value="Submit" id="cmdSubmit" title="Show selects with preselected values" style="" /><br />
</div>
</div>
</form>

</body>
</html>
<?php

function SelectBox( $Label, $selectName ){
  ?>
  <tr ALIGN="LEFT">
    <td width="15%"><?php echo $Label ?></td>
    <td align="left">
      <select name="<?php echo $selectName ?>">
        <option></option><option></option><option></option>
        <option>--------- Not Yet Loaded ---------</option>
      </select>
    </td>
  </tr>
<?php
}
?>



0
 
mhoggatt1Author Commented:
Actually to make this easier please modify this code to print out "The results go here" below the Submit button after the Submit button is selected. The page should refresh itself and print any result at the bottom of the smae page.
Thanks,
Michael
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now