Note that there are some explanatory texts on larger screens.

plurals
  1. POValidating dynamic text box array values in PHP
    text
    copied!<p>The issue is that when the second form is displayed the validation doesn't happen the way I need. Irrespective of I have a value or not in <code>TextBoxEntry</code> I get the message <code>Saved</code>. Ideally if the text box is not empty then only I should have the message <code>Saved</code> but even if I don't have anything I get the message <code>Saved</code></p> <p>Can someone pls help?</p> <p>Thanks</p> <p>Here is the code:</p> <pre><code>&lt;?php SESSION_start(); include ("../connection/index.php"); ?&gt; &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt;&lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="One"&gt; &lt;form name="form1" method="post" action=""&gt; &lt;?php $SQLbrands="SELECT * FROM brands"; $runBrands=mysqli_query($db, $SQLbrands) or die ("SQL Error"); $noRow=mysqli_num_rows($runBrands); $brndTable = "&lt;table border='1' cellspacing='0' cellpadding='1' id='brndTable1' class='brndTable1'&gt;"; $brndTable .= "&lt;thead&gt;&lt;tr&gt;&lt;th class='brT11'&gt;Brand Name&lt;/th&gt;&lt;th class='brT21'&gt;Variant&lt;/th&gt;&lt;th class='brT31'&gt;SKU&lt;/th&gt;&lt;th class='brT41'&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;"; $brndTable .= "&lt;tbody&gt;"; while ($reK = mysqli_fetch_array($runBrands)) { $wec = $reK['id']; $wec2 = $reK['bvariant']; $wec3 = $reK['bsku']; $brndTable .= "&lt;tbody class='colormine'&gt;&lt;tr&gt;"; $brndTable .= "&lt;td class='brT1'&gt;".$reK["name"]."&lt;/td&gt;"; $brndTable .= "&lt;td class='brT2'&gt;".$reK["address"]."&lt;/td&gt;"; $brndTable .= "&lt;td class='brT3'&gt;".$reK["tphone"]."&lt;/td&gt;"; $brndTable .= "&lt;td class='brT4'&gt;&lt;input type='checkbox' name='checkedMe[]' value='$wec' /&gt;&lt;/td&gt;"; $brndTable .= "&lt;/tr&gt;"; } $brndTable .= "&lt;/tbody&gt;"; $brndTable .= "&lt;/table&gt;"; echo $brndTable; ?&gt; &lt;input type="submit" name="sendone" id="sendone" value="OneClick"&gt; &lt;/form&gt; &lt;/div&gt; &lt;div id="two"&gt; &lt;?php if(isset($_POST['sendone'])) { if(!isset($_POST['checkedMe'])) {echo 'No check boxes are selected!'; return;} else { $mohan = "&lt;form method='post' action=''&gt;&lt;table border='1' id='myTad' cellspacing='0' cellpadding='2'&gt; &lt;tr class='tabColor'&gt; &lt;td&gt;Name&lt;/td&gt; &lt;td&gt;Address&lt;/td&gt; &lt;td&gt;Phone&lt;/td&gt; &lt;/tr&gt;"; foreach($_POST['checkedMe'] as $checkedMe) { $checkedMe=mysqli_real_escape_string($db,$checkedMe); $QR = "SELECT bname, bvariant, bsku FROM brands WHERE id='$checkedMe'"; $rr = mysqli_query($db,$QR) or die ("SQL Error"); $roV = mysqli_num_rows($rr); $rr = $rr-&gt;fetch_assoc(); $mohan .= "&lt;tr class='sc_eght' &gt;&lt;td class='sc_five'&gt;".$rr['bname']." ".$rr['bvariant']." ".$rr['bsku']; $mohan .="&lt;/td&gt; &lt;td&gt;&lt;textarea style='width:80px;' name='schema[]' id='vtext' class='sc_one' rows='1' cols='1' maxlength='100'&gt;&lt;/textarea&gt;&lt;/td&gt; &lt;td&gt;&lt;input style='width:80px;' type='text' name='TextBoxEntry[]' id='vtext' class='sc_two' size='80' maxlength='5'&gt;&lt;/td&gt; &lt;/tr&gt;"; } $mohan .= "&lt;input type='submit' name='sendMe' id='sendMe' value='Save'&gt;&lt;/table&gt;&lt;/form&gt;"; $_SESSION['cb'] = $mohan; } if(isset($_SESSION['cb'])) echo $_SESSION['cb']; } if(isset($_POST['sendMe'])) { if(!(isset($_POST['TextBoxEntry']) || $_POST['TextBoxEntry'] == '')) {echo $_SESSION['cb']; echo "Empty!"; return;} else { echo $_SESSION['cb']; echo "Saved!"; return;} } ?&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

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