How to do prepare statement with the following query?

How to do prepare statement with the following query?
0

#1

Hey guys!

I am not sure if the following are correct when using prepared statement? Because the word limit is in red when I do this instead of green…

$sql = "SELECT id FROM categories WHERE id= ? LIMIT = ?";

$stmt = mysqli_stmt_init($conn);

	if (!mysqli_stmt_prepare($stmt, $sql)) {
	   echo 'SQL error';
	   
	} else {
	    mysqli_stmt_bind_param($stmt, "ii", $cid, $limit)
	    mysqli_stmt_execute($stmt);

Can I also do the following:

 $limit = 1;

			    $sql3 = "UPDATE categories
                         SET last_post_date = ?, last_user_posted = ?
                         WHERE id = ?
                         LIMIT = ?
                         
			            ";

			    $stmt = mysqli_stmt_init($conn);

				if (!mysqli_stmt_prepare($stmt, $sql3)) {
				   echo 'SQL error';
				   
				} else {
				    mysqli_stmt_bind_param($stmt, "ssii", $date, $creator, $cid, $limit);
				    mysqli_stmt_execute($stmt);

#2

Not sure what you mean by red and green.


#3

I am using subline text, so I am assuming that if the red is in red, it means that there is an error?


#4

I have no idea, because I do not use sublime. Maybe someone who does will chime in.


#5

Are you using a Sublime Linter for PHP? If not, maybe it’s just the way Sublime colors your code, did you run that code?


#6

And I think you’re missing a} after the else statement.


#7

I will check but the brackets looks okay… I am also getting an error here;

$sql2 = “SELECT * FROM topics WHERE category_id= '”.$cid."’ ORDER BY topic_reply_date DESC";

The word order by, should it be in red or green?


#8

Can you post an screenshot please?