John Davidson

javascript - PHP AJAX - Function not Returning SQL ID

0 comments
Message:


I am trying to get a query to run where it returns the SQL row's id of a user using a collar number through PHP.


For some reason, it is not working and providing an error: trying to access array offset on value of type null. Full Error Message - https://gyazo.com/38367bee5066d16f419a43aab93cbc89


I am not exactly sure how to fix this, I've tried a lot of things. I want the function to return the id so I can then use it where ever needed. I am using PHP's include functions.



UpdatePassword.php



session_start();

include("functions.php");

$id = findUserID(array_key_exists("collar", $_POST));
echo($id);


Functions.php



function findUserID($collar){
$id = "";

include("../connection.php");

$query = "SELECT `id` FROM `users` WHERE collar = '".mysqli_real_escape_string($link, $collar)."'";

if ($result = mysqli_query($link, $query)){
//echo "Query was Successful";

$row = mysqli_fetch_array($result);
return($row['id']);
}
}




My Answer:
"db.php");__function getUserId($collarNumber) {__ global $conn;__ $stmt = $conn->prepare("SELECT id FROM users WHERE collar_number = ?");__ $stmt->bind_param("s", $collarNumber);__ $stmt->execute();__ $result = $stmt->get_result();__ $row = $result->fetch_assoc();__ return $row['id'];__}__?>

Rate this post

5 of 5 based on 3959 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us