Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>An alternative is to use PDO...</p> <pre><code>&lt;?php $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="ureviewdu"; // Database name $tbl_name="Student"; // Table name $return=''; if(isset($_POST)){ $continue=true; if(empty($_POST['reguser']) || strlen($_POST['reguser']) &lt; 3){$continue=false;} if(empty($_POST['regpass']) || strlen($_POST['regpass']) &lt; 6){$continue=false;} if(empty($_POST['regfirst']) || strlen($_POST['regfirst']) &lt; 3){$continue=false;} if(empty($_POST['reglast']) || strlen($_POST['reglast']) &lt; 3){$continue=false;} if(empty($_POST['regemail']) || filter_var($_POST['regemail'], FILTER_VALIDATE_URL)==false){$continue=false;} if(empty($_POST['regclassrank']) || is_int($_POST['regclassrank'])==false){$continue=false;} if($continue===true){ //Attempt to insert try{ $dbh = new PDO("mysql:host=$host;dbname=$db_name", $username, $password); /*** set the error reporting attribute ***/ $dbh-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); /*** variables ***/ foreach($_POST as $key=&gt;$value){ if(get_magic_quotes_gpc()) { $value = stripslashes($value); } $values[$key]=$value; } /*** prepare the SQL statement ***/ $stmt = $dbh-&gt;prepare("INSERT INTO $tbl_name (uname, pass, fname, lname, email, currGrade) VALUES(:uname,:upass,:fname,:lname,:email,:currGrade)"); /*** bind the paramaters ***/ $salt = '~Z`!@#$%I^&amp;*()_-+Q=}]{[\|"&gt;&lt;'; $stmt-&gt;bindParam(':uname', $values['reguser']); $stmt-&gt;bindParam(':upass', sha1($salt.$values['regpass'])); $stmt-&gt;bindParam(':fname', $values['regfirst']); $stmt-&gt;bindParam(':lname', $values['reglast']); $stmt-&gt;bindParam(':email', $values['regemail']); $stmt-&gt;bindParam(':currGrade', (int)$values['regclassrank']); /*** execute the prepared statement ***/ $stmt-&gt;execute(); $return='Thanks for signing up!'; /*** close the database connection ***/ $dbh = null; }catch(PDOException $e){ $return='Failed:'. $e-&gt;getMessage(); } }else{ $return='All fields are required'; } } echo $return. '&lt;form ...........'; ?&gt; </code></pre>
    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.
    1. VO
      singulars
      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