Please help me find out what I've done wrong | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Please help me find out what I've done wrong

I have been trying for days to try and do some insert into work with my db from php. IDK maybe I need to just hang it up but I can't seem to get anything to work correctly. It's always one error after the other or something just doesn't work and I have no Idea why. I just started learning last week but I feel like I've really gotten nowhere lol. Anyway, I'm just trying to find out why I am getting Undefined Variable $con in this code. could someone please help me out here <?php include_once 'includes/dbh.inc.php'; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> </body> </html> <?php $sql = "SELECT * FROM users;"; $result = mysqli_query($con, $sql); $resultCheck = mysqli_num_rows($result); if ($resultCheck > 0) { while ($row = mysqli_fetch_assoc($result)) { echo $row['user_uid'] . "<br>"; } } ?>

6th Dec 2023, 3:07 AM
AceRampage
AceRampage - avatar
1 Answer
+ 1
You have the $result line with $con in it, but there's no $con written before that line. If you look at your line before, you declare the $sql variable, you need to do the same for the $con.
6th Dec 2023, 9:05 AM
Ausgrindtube
Ausgrindtube - avatar