Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to validate data on text?
    primarykey
    data
    text
    <p>I have this project where in it requires to validate the data on text field if the user input "0" the process must not run and display an error message instead.. here's my code:</p> <pre><code>&lt;?php include('connect.php'); include('func.php'); if (isset($_REQUEST['command'])=='delete' &amp;&amp; $_REQUEST['pid']&gt;0){ remove_product($_REQUEST['pid']); } else if (isset($_REQUEST['command'])=='update') { $max=count($_SESSION['cart']); for($i = 0;$i &lt; $max; $i++) { $pid = $_SESSION['cart'][$i]['productid']; $q = intval($_REQUEST['product'.$pid]); if( $q &gt; 0 &amp;&amp; $q &lt;= 999){ $_SESSION['cart'][$i]['qty']=$q; } else{ echo "Some products not updated!, quantity must be a number between 1 and 999"; } } } ?&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;script language="javascript"&gt; function del(pid){ if(confirm('Do you really mean to delete this item')){ document.form1.pid.value=pid; document.form1.command.value='delete'; document.form1.submit(); } } function clear_cart(){ if(confirm('This will empty your shopping cart, continue?')){ document.form1.command.value='clear'; document.form1.submit(); } } function update_cart(){ document.form1.command.value='update'; document.form1.submit(); } &lt;/script&gt; &lt;script type="text/javascript" src="lib/jquery.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function(){ $("#qty").keypress(function (e) { if( e.which!=8 &amp;&amp; e.which!=0 &amp;&amp; (e.which&lt;48 || e.which&gt;57)) { return false; } }); }); &lt;/script&gt; &lt;script type="text/javascript" src="lib/jquery.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="src/facebox.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; jQuery(document).ready(function($) { $('a[rel*=facebox]').facebox({ loadingImage : 'src/loading.gif', closeImage : 'src/closelabel.png' }) }) &lt;/script&gt; &lt;script type="text/javascript"&gt; function checkCheckBox(){ agree_check = oForm.elements["agree"].checked; if(!agree_check){ alert("You must agree to the terms and conditions before purchasing."); } return agree_check; } &lt;/script&gt; &lt;style type="text/css"&gt; body { background-color: #FFF; } table { margin-top: 15px; } #wrapper { width:900px; height:auto; margin-left:40px; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="wrapper"&gt; &lt;table width="900" align="center"&gt; &lt;tr&gt; &lt;td&gt;&lt;img src="images/banner.png" width="900" height="138" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;form name="form1"&gt; &lt;input type="hidden" name="pid" /&gt; &lt;input type="hidden" name="command" /&gt; &lt;div style="margin:0px auto; width:600px;" &gt; &lt;div style="padding-bottom:10px"&gt; &lt;h1 align="center"&gt;Your Shopping Cart&lt;/h1&gt; &lt;input type="button" value="Continue Shopping" &lt;onclick="window.location='customerproduct.php'" /&gt; &lt;/div&gt; &lt;table border="0" cellpadding="5px" cellspacing="1px" style="font-family:Verdana, Geneva, sans-serif; font-size:11px; background-color:#E1E1E1" width="100%"&gt; &lt;?php if(isset($_SESSION['cart'])){ echo '&lt;tr bgcolor="#FFFFFF" style="font-weight:bold"&gt;&lt;td&gt;Serial&lt;/td&gt;&lt;td&gt;Name&lt;/td&gt;&lt;td&gt;Price&lt;/td&gt;&lt;td&gt;Qty&lt;/td&gt;&lt;td&gt;Amount&lt;/td&gt;&lt;td&gt;Options&lt;/td&gt;&lt;/tr&gt;'; $max = count($_SESSION['cart']); for($i = 0; $i &lt; $max; $i++){ $pid = $_SESSION['cart'][$i]['productid']; $q = $_SESSION['cart'][$i]['qty']; $pname = get_product_name($pid); if ($q == 0) continue; ?&gt; &lt;tr bgcolor="#FFFFFF"&gt;&lt;td&gt;&lt;?php echo $i+1?&gt;&lt;/td&gt;&lt;td&gt;&lt;?php echo $pname?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo number_format(get_price($pid))?&gt;Php&lt;/td&gt; &lt;td&gt;&lt;input type="text" id="qty" name="product&lt;?php echo $pid?&gt;" value="&lt;?php echo $q?&gt;" maxlength="3" size="2" /&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo number_format(get_price($pid)*$q)?&gt;Php&lt;/td&gt; &lt;td&gt;&lt;a href="javascript:del(&lt;?php echo $pid?&gt;)"&gt;Remove&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt; &lt;?php } ?&gt; &lt;tr&gt; &lt;td&gt;&lt;b&gt;Order Total: &lt;?php echo number_format(get_order_total())?&gt;Php&lt;/b&gt;&lt;/td&gt; &lt;td colspan="5" align="right"&gt; &lt;input type="button" value="Update Cart" onclick="update_cart()"&gt; &lt;input type="checkbox" value="0" name="agree"&gt; &lt;a rel="facebox" href="terms.php"?&gt;terms and condition&lt;/a&gt; &lt;input type="button" id="place" value="Place Order" onclick="window.location='order.php'" &gt; &lt;/form&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php } ?&gt; &lt;/table&gt; &lt;/div&gt; &lt;/form&gt; </code></pre> <p>I like to display the error message when the user inputs "0" in the text of <code>quantity</code>.</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.
    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