Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think you're overthinking this. </p> <p>Just add an extra option to the <code>&lt;select&gt;</code> - i.e. a literal value, not something PHP generates - before you add all the other values from the database. Give it a value like "0" or "NotSelected", then check for that in your validation routines.</p> <p>Oh, and as an unrelated issue, don't do this:</p> <pre><code>$selectedKey = $_GET['selected_key']; $query = "SELECT * FROM `1 received` WHERE Key = '".$selectedKey."'"; </code></pre> <p>You're opening yourself to SQL injections. If you don't know what that is, look it up. You should be using prepared/parameterized queries for this. Both the PDO and mysqli extensions have this capability, so you should be using one of those instead of the mysql extension, which has been deprecated (i.e. "this will be removed from the language soon, so stop using it") in the latest version of PHP.</p> <hr> <p>Update:</p> <p>Based on the fact that you're updating the HTML directly using an AJAX request to get new content for the <code>&lt;select&gt;</code> element, you need to move the <code>&lt;option&gt;</code> item I mentioned to be part of the script you call in your AJAX request.</p> <p>Specifically, you should do it directly before your <code>foreach</code> loop:</p> <pre><code>&lt;?php $selectedKey = $_GET['selected_key']; // DO SOME VALIDATION ON $selectedKey here // Remember what I said about SQL injection and using mysqli/PDO $query = "SELECT * FROM `1 received` WHERE Key = '".$selectedKey."'"; $run = mysql_query($query); echo "&lt;option value='NotSelected'&gt;Select Contract&lt;/option&gt;"; while($row = mysql_fetch_assoc($run)) { echo "&lt;option value='".$row['Number']."'&gt;".$row['Number']."&lt;/option&gt;"; } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload