Jump to content


  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About Nematode128

  • Rank
  1. Gotcha, that makes sense. Thank you. I'm having trouble using fetch array in this other function though. This function will be to show the user notifications however fetch array is giving me this error: "Fatal error: Uncaught Error: Call to undefined method mysqli_stmt::fetch_array() in /home/evoarena/public_html/Dev/functions.php:69 Stack trace: #0 /home/evoarena/public_html/Dev/index.php(5): notifications(Object(mysqli)) #1 {main} thrown in /home/evoarena/public_html/Dev/functions.php on line 69" where line 69 is $news_user = $news_stmt->fetch_array(); The functions are basically copy and pasted with variables and th query changed as needed so why does this function provide me with a fetch array error? function notifications($link) { if (isset($_SESSION['username'])) { $news_query = "SELECT news_read FROM users WHERE username=?"; if ($news_stmt = $link->prepare($news_query)) { $username = $_SESSION['username']; $news_stmt->bind_param("s", $username); $news_stmt->execute(); $news_result = $news_stmt->get_result(); $news_user = $news_stmt->fetch_array(); if ($news_user['news_read'] == '0') { echo "<div class='alert alert-primary alert-dismissible' role='alert'> <center><button type='button' class='close' data-dismiss='alert'>&times;</button>There is a new post on the <a href='http://www.pereia.net/Dev/news/index.php'>Updates</a> page </center></div>"; } } else { $error = $link->errno . ' ' . $link->error; echo $error; } } }
  2. So I'd just want this? function egg_received($link) { //contents } or would I need to add more code inside the actual function
  3. I'm trying to use a prepared statement inside a function and it's giving me some trouble. I have an RPG game I'm working on an want a function to include on pages that tells a user to collect their egg from the professor if they haven't already received it yet. When I try to call the function on the page these are the errors I get: Notice: Undefined variable: link in /home/evoarena/public_html/Dev/functions.php on line 23 Fatal error: Uncaught Error: Call to a member function prepare() on null in /home/evoarena/public_html/Dev/functions.php:23 Stack trace: #0 /home/evoarena/public_html/Dev/login.php(59): egg_received() #1 {main} thrown in /home/evoarena/public_html/Dev/functions.php on line 23 $link is defined in a db config file and on the page I'm trying to call the function I have the files required like this so I'm wondering why it still thinks link is an undefined variable require "config.php"; require "functions.php"; Function Code: function egg_received () { if (isset($_SESSION['username'])) { $username = $_SESSION['username']; $query = "SELECT egg_received FROM users WHERE username=?"; if ($stmt = $link->prepare($query)) { $stmt->bind_param("s", $username); $stmt->execute(); $result = $stmt->get_result(); $egg = $result->fetch_array(); if ($egg['egg_received'] == '0') { echo "<div class='alert alert-primary' role='alert'> Oh well hello there! It appears the professor is looking for you today!<br><a href='../world/professor.php'>Visit the Professor</a> </div>"; require "footer.php"; exit; } } else { $error = $link->errno . ' ' . $link->error; echo $error; } } }
  4. I'm getting username, email and a few other things later on.
  5. Hello I'm currently working on a staff page for my website and I'm having trouble with a function not working corrrectly. The function is supposed to display an error message if the logged in user isn't a high enough level however it doesn't seem to be correctly getting the users rank level correctly cause in the error message it returns "You have a rank of" instead of "You have a rank of x". Here are my codes below maindir/header.php $username = $_SESSION['username']; $sql = "SELECT * FROM users WHERE username=? LIMIT 1"; // SQL with parameters $stmt = $link->prepare($sql); $stmt->bind_param("s", $username); $stmt->execute(); $result = $stmt->get_result(); // get the mysqli result $user = $result->fetch_assoc(); // fetch data function verify_staff() { if ($user['rank'] <= '2') { echo " <div class='alert alert-danger' role='alert'> You're not supposed to be here. You have a rank of " . $user['rank'] . " </div> "; exit; } } /maindir/staff/index.php <?php require '../header.php'; verify_staff(); echo "Staff panel"; require '../footer.php'; ?>
  6. How do you include files from a higher up directory? I'm currently working on a file in public_html/Directory/otherdirectory and want to include a config file that's in public_html/Directory so how would I include public_html/Directory/config.php in the public_html_Directory/otherdirectory/index.php file? I've tried using ../ and ../Directory/ in the includes line but got errors both times
  7. $sql = "SELECT * from updates ORDER BY id DESC LIMIT 3"; $stmt = $link->prepare($sql); $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows = '0') { echo "There haven't been any updates yet."; } else { echo "There are news posts"; } Gives me the error "Cannot write property in /home/evoarena/public_html/Dev/news.php:14 ", line 14 is the if statement. How can I fix it? "
  8. @ginerjm https://www.php.net/manual/en/mysqli-result.fetch-array.php that's what I found about the fetch array on PHP.net. so for the results var it would be something like like "$results = mysqli_store_result($stmt) or am I misunderstanding?
  9. This is the code on the line it points to " $info = mysqli_fetch_array($stmt);"
  10. Hello I'm trying to set up a user area for my site where it displays the current logged in users ranking and other information in the future. <? ini_set('display_errors', 1); require_once "header.php"; $sql = "SELECT * FROM users WHERE username = ?"; if($stmt = mysqli_prepare($link, $sql)){ mysqli_stmt_bind_param($stmt, 's', $_SESSION['username']); if(mysqli_stmt_execute($stmt)){ $info = mysqli_fetch_array($stmt); echo "Current rank:" . $info['rank']; } else { echo "Can't find user"; } } mysqli_stmt_close($stmt); ?> That's the code I currently have but it gives me the error "but get an error message of mysqli_fetch_array() expects parameter 1 to be mysqli_result"
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.