Hi,
Can someone take a look at the two snippets of code and tell me what am I doing wrong to cause the following error?
Error: Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, string given....
Here's the code (flies - there are two - one the db_connection string and the other the script attempting to perform the insert)
<?php
// db connection string that resides in 'includes' folder
function execute($query) {
$db_con = mysqli_connect("localhost","db_user","passxxx");
mysqli_select_db($db_con, "mytable_name");
$res=mysqli_query($db_con,$query) or die(mysqli_error($db_con) . '<br />' . $query) ;
mysqli_close($db_con);
return $res;
}
?>
I know this is the (old) procedure way but I don't have the time to revamp the code to OOP - will update to PDO in coming weeks; for now, i need this set of code to work (if possible).
Now, here's the portion of the code where I want to escape string - giving two as example - which throws the (above) error.
<?php
require("includes/db_con.php");
$v1 = $_GET['v1'];\
$v2 = $_GET['v2'];
$v3 = $_GET['v3'];
// I even tried adding mysqli_real_escape_string($db_con,$v1) - as an example here but still error
$v1 = mysqli_real_escape_string(mysqli $db_con,$v1);
-----------
// Below is the function to execute MySQL Insert which pulls from the include file (db_con.php) - this is where i have the 'mysqli_real_ecape_string() defined for $v1, $v2, $v3 currently but still throwing error:
execute("insert into logs (logid,value1,value2,value3) values ('',,'$'".mysqli_real_escape_string($v1).'".mysqli_real_escape_string($v2)."','".mysqli_real_escape_string($v3)."')");
?>
Note: I know the syntax is mysqlI_real_escape_string(mysqli $link, string) - when i add 'mysqli $link - code breaks....
Issue: I switched current code from mysql to mysqli and need to launch; once up and running, i plan to go back and revise code to PDO which, I know the prefer choice - just under gun to get up and running so switched to mysqli just in interim.
Any advise to get provided snippet code running where insert possible, much appreciated - thx!
Edited by n1concepts, 10 March 2013 - 07:54 PM.













