Join date: May 15, 2022

System Analysis And Design Shelly Cashman.pdf




System Analysis and DesignShelly Cashman.pdf JU-864 Shelly Cashman.pdf System Analysis and Design 9e - Shelly Cashman.pdfQ: PHP Mysqli Login system; create if not exist I am new to mysqli so this is just a piece of code i am working on. The system has 2 form pages, the first one for registration, and the second for login. It was working great and using mysql and now i decided to replace it with mysqli and it was working great until i came across this. I have an object called $db which represents mysqli connection. So in the registration form i have: if (isset($_POST['submit'])) { $email = $_POST['email']; $pass = $_POST['pass']; $email = mysqli_real_escape_string($db, $email); $pass = mysqli_real_escape_string($db, $pass); $sql = "INSERT INTO users (email, pass) VALUES ('$email', '$pass')"; if ($stmt = $db->prepare($sql)) { $stmt->bind_param("ss", $email, $pass); $stmt->execute(); $stmt->close(); echo "Registered"; } else { echo "Something went wrong"; } } When i submit i am receiving a registered message but if i submit the login form and fill out the fields i get the message "something went wrong". Is there any way that i can somehow check if the database already has a record for that email and password or is there something wrong with my code. Thanks A: You could do: $sql = "SELECT COUNT(*) FROM users WHERE email = '$email' AND pass = '$pass'"; $result = $db->query($sql); $numRows = $result->fetch_assoc(); if($numRows['COUNT(*)'] == 0




System Analysis And Design Shelly Cashman.pdf
More actions