3v4l.org

run code in 300+ PHP versions simultaneously
<?php // -- PULLING IN PRODUCTS TO READ OUT TO USER -- // $stmt = (" SELECT products.ID, products.title, products.category, products.location, products.price, products.negotiable, products.description, products.photo, products.user_id FROM products"); $result = $db->query($stmt); foreach ($result as $row) { $product_id = $row['ID']; $title = htmlspecialchars($row['title'], ENT_QUOTES); // User input, prevent first order XSS $category = $row['category']; // local variable for remainder, ensuring to use htmlspecialchars() for any user input that will be read out to browser } // -- INSERTING PRODUCTS TO MAIN PRODUCT PAGE USING PREPARED STATEMENT -- // // Incoming user input from some form // Assign input to local variables // Probably should validate data $null_value = null; // To bind null values... I'm lazy $stmt = $db->prepare(" INSERT INTO products VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->bind_param('sssssssss', $null_value, $title, $category, $location, $price, $negotiable, $description, $photo, $user_id); $stmt->execute(); $result = $stmt->get_result();
Output for 8.0.0 - 8.0.13, 8.1rc1 - rc3
Warning: Undefined variable $db in /in/rqT4l on line 20 Fatal error: Uncaught Error: Call to a member function query() on null in /in/rqT4l:20 Stack trace: #0 {main} thrown in /in/rqT4l on line 20
Process exited with code 255.
Output for 7.3.32, 7.4.26
Fatal error: Uncaught Error: Call to a member function query() on null in /in/rqT4l:20 Stack trace: #0 {main} thrown in /in/rqT4l on line 20
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.3.33, 7.4.0 - 7.4.25
Notice: Undefined variable: db in /in/rqT4l on line 20 Fatal error: Uncaught Error: Call to a member function query() on null in /in/rqT4l:20 Stack trace: #0 {main} thrown in /in/rqT4l on line 20
Process exited with code 255.

preferences:
35.44 ms | 463 KiB | 5 Q