PNewCode Posted July 17, 2023 Share Posted July 17, 2023 Okay I'm nearly done with my auction project but I figured this was a different questions, so new topic. This is what baffles me... The part in the script that says echo $_SESSION['id']; will show the id correctly, same as if I changed it to echo $'myid'; So I'm getting the error Warning: Trying to access array offset on value of type null on the line if($row['myid'] == $_SESSION['id']) { I've used this method several times and I can't find what is causing this error. Any thoughts? And sorry if this should be obvious, I think I'm getting a bit fatigued on this one. <?php error_reporting(E_ALL); ini_set('display_errors', '1'); $hostname_l = "deleted for posting"; $username_l = "deleted for posting"; $password_l = "deleted for posting"; $dbname_l = "deleted for posting"; $conn_l = mysqli_connect($hostname_l, $username_l, $password_l, $dbname_l); if(!$conn_l){ echo "Database connection error".mysqli_connect_error(); } $user_id = $_SESSION['id']; $myid = $_SESSION['id']; $sql_l = "SELECT * FROM auction WHERE myid= 'myid' ORDER BY 'id' DESC LIMIT 1"; $result = $conn_l->query($sql_l); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { $myid = $row["myid"]; } } else { echo " "; } echo $_SESSION['id']; if($row['myid'] == $_SESSION['id']) { echo ' <table width="40%" border="0" cellspacing="5" cellpadding="1" class="table-round-side2"> <tr class="table-roundmenue44 box10"> <td class="table-roundmenue44"> YOU ARE THE WINNER!!! </td> </tr> </table> '; } else { } ?> Quote Link to comment Share on other sites More sharing options...
requinix Posted July 17, 2023 Share Posted July 17, 2023 What will your code do if there aren't any rows from the query? (I know the answer - I want you to read through it and think about what will happen) 1 Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted July 17, 2023 Solution Share Posted July 17, 2023 Plus, if you are accessing $_SESSION, then you need session_start() at the top of the script. Also errors in the query You are trying to match the value in column myid with the string value 'myid' You are trying to order the results by the string value 'id' 1 Quote Link to comment Share on other sites More sharing options...
PNewCode Posted July 17, 2023 Author Share Posted July 17, 2023 @requinix Holy Moly Batman! hahahaha. I forgot to include this if (isset($_SESSION['myid'])) { and that got rid of the error and is showing the message. But argh It's not matching the winning id and showing it to anyone logged in. Well... the error is solved anyways. Goodness I can't believe I forgot that. So it was not finding the session id to put with the column myid. Quote Link to comment Share on other sites More sharing options...
PNewCode Posted July 17, 2023 Author Share Posted July 17, 2023 @Barand Indeed. I have a session start included further up the page in a different section. I had it also in what I posted but I got the error it was being ignored because I had it above it already Quote Link to comment Share on other sites More sharing options...
dodgeitorelse3 Posted July 17, 2023 Share Posted July 17, 2023 is your database table column named myid or id? Quote Link to comment Share on other sites More sharing options...
Barand Posted July 17, 2023 Share Posted July 17, 2023 Both, apparently Quote Link to comment Share on other sites More sharing options...
PNewCode Posted July 18, 2023 Author Share Posted July 18, 2023 Those are 2 different projects but yes this one is myid that is passed from a previous page that has the session_id sent to this page and then translated to myid I know.... I make things too complicated. I'm getting the hang of it though (slowly) haha Quote Link to comment Share on other sites More sharing options...
dodgeitorelse3 Posted July 18, 2023 Share Posted July 18, 2023 I didn't ask what was passed. I asked what the actual column name is in your database table. Quote Link to comment Share on other sites More sharing options...
PNewCode Posted July 18, 2023 Author Share Posted July 18, 2023 Sorry, for this one it's myid, it's all working now Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.