Note that there are some explanatory texts on larger screens.

plurals
  1. POPlease help me to convert PDO from old mysql to this code
    primarykey
    data
    text
    <p>I am new to MySQL and PHP. I have been working on a project that's like some kind of blog. But I heard old MySQL is vulnerable or easily hackable. So I was suggested to use PDO. But I am confused how to convert this code to PDO. Please help me.</p> <pre><code>&lt;?php //Start session session_start(); //Include database connection details require_once('scripts/dblog.php'); //Array to store validation errors $errmsg_arr = array(); //Validation error flag $errflag = false; //Function to sanitize values received from the form. Prevents SQL injection function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } //Sanitize the POST values $username = clean($_POST['username']); $password = clean($_POST['password']); //Input Validations if($username == '') { $errmsg_arr[] = 'Username missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'Password missing'; $errflag = true; } //If there are input validations, redirect back to the login form if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location: login.php"); exit(); } //Create query $qry="SELECT * FROM member WHERE BINARY username='$username' AND BINARY password='$password'"; $result=mysql_query($qry); //Check whether the query was successful or not if($result) { if(mysql_num_rows($result) &gt; 0) { //Login Successful session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID'] = $member['mem_id']; $_SESSION['SESS_FIRST_NAME'] = $member['username']; $_SESSION['SESS_LAST_NAME'] = $member['password']; session_write_close(); header("location: post.php"); exit(); } else { //Login failed $errmsg_arr[] = '&lt;div class="alert alert-error"&gt;user name and password not found&lt;/div&gt;'; $errflag = true; if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location: login.php"); exit(); } } } else { die("Query failed"); } ?&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.
 

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