0

I need to write my php variables correctly.

$query2 = mysqli_query($con,"SELECT * FROM palettes LIMIT '$starting_number, $palettes_per_page'");
0

3 Answers 3

1

I don't think you want single quotes on your LIMIT parameters. One way is to use . to concatenate strings.

Since $starting_number and $palettes_per_page are integers, you do not need to escape them. If they were strings, wrap them in mysqli_real_escape_string or mysqli_escape_string to escape special characters.

$query2 = mysqli_query( $con,
             "SELECT * FROM palettes LIMIT " .
             $starting_number .
             "," .
             $palettes_per_page );
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much! this was exactly what i needed
0

Just remove the single quote, because double quote can read variable's value

$query2 = mysqli_query($con,"SELECT * FROM palettes LIMIT $starting_number, $palettes_per_page");

Hope this works for you

Comments

0

You could use parameterized queries which also prevent any need to use mysqli_real_escape_string

$stmt = $conn->prepare("SELECT * FROM palettes LIMIT ?, ?'"); $stmt->bind_param("ii", $starting_number, $palettes_per_page); $stmt->execute();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.