-1

I try to save a users "Office-365 ID" in a MySQL database, after a login into my page. But it doesn't work.

<?php
$servername = 'localhost';
$username = 'root';
$password = '';
$db = 'test';

$Office_ID = $_POST['Office_ID'];
$exists = mysqli_query($conn, "SELECT * from users WHERE  Office_ID = '$Office_ID'");

$no_of_rows = mysqli_num_rows($exists);
if($no_of_rows == 0)
{
    mysqli_query($conn, "INSERT INTO users VALUE ('$Office_ID')");
}
?>

Did i make a mistake?

IMSoP
  • 77,988
  • 8
  • 99
  • 149
  • "It doesn't work" is not a useful problem description. Read up on how to check for errors with mysqli, then look at what the error tells you, and search for existing questions with similar errors. You should also learn [how to protect yourself from a serious security vulnerability called "SQL injection"](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php). – IMSoP May 08 '22 at 16:34
  • You need to post the error messages. – Lucas May 08 '22 at 16:35
  • Well there are no error messages, that's the problem – kerma94 May 08 '22 at 16:37
  • Add this line before making the connection: `mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);` and run your code again. – Lucas May 08 '22 at 18:11
  • First of all you have undefined variable $conn – pepeD May 08 '22 at 21:39
  • 1
    Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community May 09 '22 at 19:40

0 Answers0