Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP variable returns a null value
    primarykey
    data
    text
    <p>I've created a textbox so when the admin types a name and clicks submit, it will shows a list of retrieved data from the database.</p> <pre><code> &lt;form method="post" action=""&gt; &lt;?php $teacherName = $_POST['teacherName']; if ($_POST['submitted'] == 1) { if($teacherName != ""){ $getName = mysql_query("SELECT name, user_id FROM members WHERE name = '$teacherName'"); $teacherdetails = mysql_fetch_array($getName); $teachername = $teacherdetails['name']; $teacher_id = $teacherdetails['user_id']; if($teachername != ""){ print $teachername . "&lt;br/&gt;"; } else { print "Give a valid name &lt;br/&gt;"; } } } if ($teachername == ""){ ?&gt; Teacher name:&lt;input type="text" size="20" name="teacherName"&gt;&lt;input type="hidden" name="submitted" value="1"&gt;&lt;br/&gt; &lt;input type="submit" value="Submit" /&gt; &lt;?php $getModule = mysql_query("......"); while ($row2 = mysql_fetch_array($getModule)) { ?&gt; &lt;input type="checkbox" name="modules[]" value="&lt;?php print $row2["module_id"]?&gt;"/&gt; &lt;?php print $row2["module_name"] . '&lt;br/&gt;'; } ?&gt; &lt;/div&gt;&lt;br/&gt; &lt;?php } ?&gt; &lt;input type="submit" value="Submit" /&gt; &lt;/form&gt; </code></pre> <p>Below I wrote this code (in the same script):</p> <pre><code>&lt;?php $modules = $_POST['modules']; for($i = 0; $i &lt; count($modules); $i++){ $module=mysql_query("INSERT INTO module (module_id,user_id) VALUES ('$modules[$i]','$teacher_id')"); } ?&gt; </code></pre> <p>but for some reason when I call the variable "$teacher_id" (which is the value I retrieved before from the database. It works fine in the form) it returns nothing. It's null but I can't understand why.</p> <p>Am I doing something wrong? </p>
    singulars
    1. This table or related slice is empty.
    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.
 

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