GregHBushnell GregHBushnell - 1 year ago 122
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

Answer Source

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']);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download