When to use single quotes, double quotes, and backticks in MySQL queries from PHP?
Hello everyone! I've just started learning PHP and MySQL, and I'm completely confused about quotes. I'm writing a simple script for a blog where I need to output records from a table and then add a new one. It seems simple, but I constantly get confused about which quote to use when.
\n\nHere's an example of my code. It works, but I'm not sure it's correct:
\n\n// Fetching data\n$query = "SELECT * FROM posts WHERE id = $post_id";\n$result = mysqli_query($link, $query);\n\n// Inserting a new record\n$title = "My new post";\n$query = 'INSERT INTO posts (title, content) VALUES ("' . $title . '", "' . $content . '")';\n$result = mysqli_query($link, $query);\n\n\nI see that there's a mix of single quotes in PHP, double quotes in SQL, and I've also seen backticks somewhere for
No answers yet.
Log in to leave an answer
Blogs
HTTP Client in Swift: Making Requests the Right Way
WebSocket in Go: Building Advanced-Level Real-Time Applications
die() vs exit() in PHP: what's the difference and how to avoid fatal errors
Working with the File System in TypeScript: A Practical Guide