Jump to content

sompal

Members
  • Content count

    2
  • Joined

  • Last visited

Community Reputation

0 Neutral

About sompal

  • Rank
    Newbie
  1. sompal

    JAVASCRIPT

    <script type="text/javascript"> function checksName(form) { var eobj=document.getElementById('SnameError'); var sName = form.sName.value; var oRE = /^[A-Z a-z]*$/; var error=false; eobj.innerHTML=''; if (sName == '') { error='Error: Surname cannot be blank!'; form.sName.focus(); } else if (!oRE.test(sName)) { error="Incorrect format."; } if (error) { form.sName.focus(); eobj.innerHTML=error; return false; } } function validPhone(form) { var eobj=document.getElementById('phonenoerror'); var valid = '0123456789'; var phone = form.phoneno.value; var error=false; var i=0; var temp; eobj.innerHTML=''; if (phone == '') { error='Error: Please enter phone number'; } else if (!phone.length > 1 || phone.length < 😎 { error='please enter the 8 didgit only';} else{ for (i=0; i < phone.length; i++){ temp = '' + phone.substring(i, i + 1); if (valid.indexOf(temp) == -1) { error='Invalid characters, please enter only numbers'; } } } if (error){ form.phoneno.focus(); eobj.innerHTML=error; return false;} return true;} function selectOnlyThis(id) { for (var i = 3; i <= 9; i++) { document.getElementById("tick" + i).checked = false; } var ticked = document.getElementById(id).checked = true; var checkBox = document.getElementById("tick9"); } function formValidation() { var form = document.forms['form']; /* created array to store another function name to check their validation */ var ary=[checksName,validPhone,selectOnlyThis]; var rtn=true; var z0=0; for (var z0=0;z0<ary.length;z0++) { if (!ary[z0](form)) { rtn=false; } } return rtn; } <input type="checkbox" id="tick1" onclick="selectOnlyThis(this.id)"> <label for="passport">Passport</label> <span class="message" id="tickError"></span><br> <div class="Objects"> <label for="sName">Party 1's surname</label> <input type="text" name="sName" id="sName" placeholder="Enter surname"> <span class="message" id="SnameError"></span> <br> </div> <div> <label> Phone number </label> <input type="text" name="phoneno" maxlength="10" placeholder="Enter 8 digit phone number" value="04"> <span id="phonenoerror" ></span> <br> </div> </script>
  2. sompal

    PHP

    <?php $dbConn = new mysqli("localhost", "student", "Autumn", "fact"); if($dbConn->connect_error) { die("Failed to connect to database " . $dbConn->connect_error); } ?> <?php error_reporting(E_PARSE); //require_once("conn.php"); $number = $_POST["quantity"]; if (isset($_POST["submit"])) { if(!empty($number)){ if (is_numeric($number)){ if($number < 60){ $sql = "SELECT name, quantityInStock, price FROM product where quantityInStock > $number order by quantityInStock ASC "; $results = $dbConn->query($sql) or die ('Problem with query: ' . $dbConn->error); } else { echo "<p class='errorMsg'>There are no products that have more than 60 in stock.</p>"; } } else { echo "<p class='errorMsg'> The value entered for quantity was not a number. </p> "; } } else { echo "<p class='errorMsg'>input can not be blank</p> "; } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <style> input[type="text"] {border: 1px solid black;} </style> <link rel="stylesheet" href="styles.css"> <title>Quiz</title> </head> <body> <form id="" action="" method="post"> <h1>Product In Stock </h1> <table> <tr> <th>Name</th> <th>QuantityInStock</th> <th>Price</th> </tr> <?php while ($row = $results->fetch_assoc()) { ?> <tr> <td><?php echo $row["name"]?></td> <td><?php echo $row["quantityInStock"]?></td> <td><?php echo $row["price"]?></td> </tr> <?php } $dbConn->close(); ?> </table> </form> </body> </html>
×