Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Because you are assigning <code>$yourname</code> and <code>$compname</code> in the first two lines:</p> <pre><code>$yourname = htmlspecialchars($_POST['name']); $compname = htmlspecialchars($_POST['compName']); </code></pre> <p><strong>UPDATE</strong> You can check if these are set in POST, and therefore not need to check them later:</p> <pre><code>$yourname = isset($_POST['name']) ? htmlspecialchars($_POST['name']) : "oops, no value"; $compname = isset($_POST['compName']) ? htmlspecialchars($_POST['compName']) : "oops, no value"; </code></pre> <p>They will always be set, even if NULL or empty. So, your later calls to <code>isset()</code> will always be true. Instead, you may check if they are empty with the <code>empty()</code> function:</p> <p><strong>UPDATE</strong> Not necessary according to corrections in comments. Your <code>isset()</code> should work.</p> <pre><code>// Check with empty() // but still won't work properly. keep reading below... function nametest() { if (!empty($yourname)){ $yourname = $response[0];} else { $yourname = $response[1];; } } </code></pre> <p>However, there is another problem here of variable scope. The variables are not available inside the function unless you either pass them in as parameters or use the <code>global</code> keyword:</p> <pre><code>// $yourname is passed as a function argument. function nametest($yourname, $response) { if (!empty($yourname)){ $yourname = $response[0];} else { $yourname = $response[1];; } } </code></pre> <p>Getting there... Now your function assigns <code>$yourname</code>, but it doesn't return or print any value. Add a return statement, and then you can echo out the result:</p> <pre><code>function nametest($yourname, $response) { if (!empty($yourname)){ $yourname = $response[0];} else { $yourname = $response[1];; } // Add a return statement return $yourname; } // Now call the function, echo'ing its return value echo nametest($yourname, $response); </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. This table or related slice is empty.
    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