Jump to content

Recommended Posts

hey, why doesnt this work?

 

/* QUERY */
$mysqli = new mysqli('host', 'user', 'password', 'database'); 

if (mysqli_connect_errno()) {
    echo "error";
    exit();
} 

$stmt = $mysqli->prepare("INSERT INTO table VALUES (?, ?, ?, ?)");
$stmt->bind_param('isss', NULL, $var1, $var2, $var3); 

	$var1Raw = substr($_POST['var1'], 0, 50);
	$var2Raw = substr($_POST['var2'], 0, 300);
	$var3Raw = substr($_POST['var3'], 0, 50);

  		$var1 = mysql_real_escape_string(trim(strip_tags($var1RAW)));
	$var2 = mysql_real_escape_string(trim(strip_tags($var2RAW)));
	$var3 = mysql_real_escape_string(trim(strip_tags($var3RAW)));

	$stmt->execute();
	$stmt->close();
	$mysqli->close();

 

i know i dont need the mysql_real_escape thingie but it should work with whatever functions i use, and im being stuborn

Any error messages? try error_reporting(E_ALL);

 

I'm thinking that there's a possibility that your first column is an auto_inc and that you need to pass it null for it to work correctly. As you're casting it as an int it may not be getting to the db as null. If that's the case then try moving the null from the bind_param to the query itself.

Huh... never noticed that they used references. To be honest, I think that's pretty stupid. I normally do not use MySQLi directly. I don't like it's interface. I prefer to use PDO or a custom wrapper around either MySQLi or PDO.

 

Anyway, ricmetal, could you perhaps elaborate on how it "doesn't work".

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.