edrew04 Posted October 7, 2009 Share Posted October 7, 2009 if the textbox is for letters only(example:first name), numbers and other special characters are not allowed even if you typed it accidentally, it will not show, but only letters...if the textbox is for numbers only(example:age), letters and other special characters are not allowed even if you typed it accidentally, it will not show, but only numbers. i don't know how to do it in php, maybe javascript can , help guys... <?php include("includes/header.php"); include("includes/connection.php"); include("includes/header2.php"); if (isset($_POST['btn'])) { mysql_query("INSERT INTO patients (firstName,surname,bday,patient_age,sex,patient_address) VALUES ('$_POST[patientname]','$_POST[sur]','$_POST[bday]','$_POST[age]','$_POST[sex]','$_POST[add]')") or die (mysql_error); } ?> <table width="1000" border="1" align="center" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC"> <div id="insidebox1"> <form name="form1" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <tr><td><p>First Name: <td><input type="text" name="patientname" id="patientname" size="15" maxlength="30" value=""/></p></td></tr> <tr><td><p>Surname: <td><input type="text" name="sur" id="sur" size="15" maxlength="60" value=""/></p></tr> <tr><td><p>Birhdate: <td><input type="text" name="bday" id="bday" size="15" maxlength="100" value="mm/dd/yyyy"/></p></td></tr> <tr><td><p>Age: <td><input type="text" name="age" id="age" size="15" maxlength="100" value=""/></p></td></tr> <tr><td><p>gender: <td><input type="text" name="sex" id="sex" size="15" maxlength="40" value=""/></p></td></tr> <tr><td><p>Address: <td><input type="text" name="add" id="add" size="15" maxlength="100" value=""/></p></td></tr> <tr><td><p><input type="submit" name="btn" id="btn" value="Add Patient"/></p></td></tr> </form> </div> </table> <hr> <table width="1000" border="1" align="center" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC"> <div id="insidebox1"> <form name="form2" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <tr><td><p>patient_ID: <td><input type="text" name="pat" id="pat" size="15" maxlength="3" value=""/></p></td></tr> <tr><td><p><input type="submit" name="btn2" id="btn2" value="Delete Patient"/></p></td></tr> </form> </div> </table> <hr> <table width="1000" border="1" align="center" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC"> <div id="insidebox1"> <form name="form3" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <tr><td><p>patient_ID: <td><input type="text" name="pat2" id="pat2" size="15" maxlength="11" value=""/></p></td></tr> <tr><td><p><input type="submit" name="btn3" id="btn3" value="Search Patient"/></p></td></tr> </form> </div> </table> <hr> <table width="1000" border="1" align="center" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC"> <div id="insidebox1"> <form name="form1" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <tr><td><p>*Patient_ID <td><input type="text" name="p_id" id="p_id" size="15" maxlength="60" value=""/></p></tr> <tr><td><p>First Name: <td><input type="text" name="patientname" id="patientname" size="15" maxlength="30" value=""/></p></td></tr> <tr><td><p>Surname: <td><input type="text" name="sur" id="sur" size="15" maxlength="60" value=""/></p></tr> <tr><td><p>Birhdate: <td><input type="text" name="bday" id="bday" size="15" maxlength="100" value="mm/dd/yyyy"/></p></td></tr> <tr><td><p>Age: <td><input type="text" name="age" id="age" size="15" maxlength="100" value=""/></p></td></tr> <tr><td><p>gender: <td><input type="text" name="sex" id="sex" size="15" maxlength="40" value=""/></p></td></tr> <tr><td><p>Address: <td><input type="text" name="add" id="add" size="90" maxlength="100" value=""/></p></td></tr> <tr><td><p><input type="submit" name="btn4" id="btn4" value="Update Patient"/></p></td></tr> </form> </div> </table> <?php if (isset($_POST['btn'])) { mysql_query("INSERT INTO patients (firstName,surname,bday,patient_age,sex,patient_address) VALUES ('$_POST[patientname]','$_POST[sur]','$_POST[bday]','$_POST[age]','$_POST[sex]','$_POST[add]')") or die (mysql_error); } else if (isset($_POST['btn2'])) { mysql_query("DELETE FROM patients WHERE patient_id ={$_POST['pat']}")or die (mysql_error); } else if (isset($_POST['btn3'])) { $query=mysql_query("SELECT * FROM patients WHERE patient_id=" . $_POST['pat2']) or die (mysql_error()); echo "<table width='1000' border='2' align='center' cellpadding='1' cellspacing='1' bgcolor='#CCCCCC'><tr><td>SEARCH RESULTS</tr></td></table>"; echo "<table width='1000' border='2' align='center' cellpadding='1' cellspacing='1' bgcolor='#CCCCCC'>"; echo "<tr><td>Patient_ID</td><td>First Name</td><td>Surname</td><td>Birthdate</td><td>Age</td><td>Gender</td><td>Address</td></tr>"; while($row=mysql_fetch_array($query)) { $PatientID=$row['patient_id']; $PatientFN=$row['firstName']; $PatientSN=$row['surname']; $bday=$row['bday']; $age=$row['patient_age']; $sex=$row['sex']; $add=$row['patient_address']; echo "<tr><td>".$PatientID."</td><td>".$PatientFN."</td><td>".$PatientSN."</td><td>".$bday."</td><td>".$age."</td><td>".$sex."</td><td>".$add."</td></tr>"; } echo "</table>"; } else if(isset($_POST['btn4'])){//edit echo "<center/><a href='patients.php'>Check the update results </a></p>"; mysql_query("UPDATE patients SET firstName='".$_POST['patientname']."', surname='".$_POST['sur']."', bday='".$_POST['bday']."',patient_age='".$_POST['age']."',sex='".$_POST['sex']."',patient_address='".$_POST['add']."' WHERE patient_id='".$_POST['p_id']."'") or die (mysql_error()); } ?> <center/><a href="patients.php">Check the patient's database </a></p> <center/><a href="choosedb.php">Use another database </a></p> Quote Link to comment Share on other sites More sharing options...
kickstart Posted October 7, 2009 Share Posted October 7, 2009 Hi Javascript can do it (although you would still have to catch dodgy input when processing the form in php from those who had javascript turned off). Use a onKeyDown event to take each character in turn, and if it is one you do not allow then do not return it. Problem comes with people pasting in incorrect data. Have a google for "javascript input check numeric +onkeydown" and you should find a couple of examples. All the best Keith Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.