PHP if (submit)

Posted on 2005-04-21
Last Modified: 2013-12-12
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)) {
echo ("MakeName [$i] = $makeName[$i]<br>");

Question by:mhoggatt1
    LVL 49

    Accepted Solution

    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'])


    Author Comment

    Thanks for the reply. Actually where would you put this line in the code I sent ?
    LVL 49

    Expert Comment

    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.


    Author Comment

    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.

      <title>JSRS Select Demo</title>
      <script language="javascript" src="jsrsClient.js"></script>
      <script language="javascript" src="selectphp.js"></script>
        #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;}
      $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">
      SelectBox ("Make",    "lstMake");    
      SelectBox ("Model",   "lstModel");    
      SelectBox ("Options", "lstOptions");  
    <div id="show">
      <input type="submit" name="cmdSubmit" value="Submit" id="cmdSubmit" title="Show selects with preselected values" style="" /><br />


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


    Author Comment

    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.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to dynamically set the form action using jQuery.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now