GregHBushnell GregHBushnell - 1 month ago 12x
HTML Question

php mysql_real_escape_string conversion to mysqli

Hi im currently learning php and mysql a tutorial i am following uses the now out of date mysql_real_escape_string ive read the manual on mysqli's version of it but just cant really figure out how i would do something like the code below.

$username = mysql_real_escape_string($POST['username']);

any help in converting this over to mysqli and any tips are greatly apreciated


I think you want this


// Check connection
if (mysqli_connect_errno()) {
 echo "Failed to connect to MySQL: " . mysqli_connect_error();

// escape variables for security
$username = mysqli_real_escape_string($con, $_POST['username']);