Jump to content
Weiss

cannot run query

Recommended Posts

Hi. Im scratching my head trying to understand the following issue:

i have a built login/signup system. after user will login he will redirect to profile.php where i have a session with all the info i need.

i want to run a simple query: $result = $mysqli->query("SELECT boardid FROM connector WHERE userid='$id'"); but for some reason this line kills my script.

my $mysqli is working fine in all other php pages... so i try moving this line top to bottom but wherever the page meets this line the script is dead. what am i doing wrong?

<?php
/* Displays user information and some useful messages */
session_start();
// Check if user is logged in using the session variable
if ( $_SESSION['logged_in'] != 1 ) {
  $_SESSION['message'] = "You must log in before viewing your profile page!";
  header("location: error.php");
}
else {
    // Makes it easier to read
    $first_name = $_SESSION['first_name'];
    $last_name = $_SESSION['last_name'];
    $email = $_SESSION['email'];
    $active = $_SESSION['active'];
    $id = $_SESSION['id'];

}

?>
<!DOCTYPE html>
<html >
<head>
  <meta charset="UTF-8">
  <title>Welcome <?= $first_name.' '.$last_name ?></title>
  <?php include 'css/css.html'; ?>
</head>
<body>
  <div class="form">
          <h1>Welcome</h1>
         
     
          <h2><?php echo $first_name.' '.$last_name; ?></h2>
          <p><?= $email ?></p>
          <a href="logout.php"><button class="button button-block" name="logout"/>Log Out</button></a>
    </div>
    <div>
      <?php
//THIS IS THE LINE THAT KILLS EVERYTHING. IF I PUT IT HERE NOTHING WILL HAPPEND, IF U PUT IT UP THE SCRIPT WILL DIE
          $result = $mysqli->query("SELECT boardid FROM connector WHERE userid='$id'");
       ?>
    </div>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src="js/index.js"></script>
</body>
</html>

 

Share this post


Link to post
Share on other sites

As you have it now 'IF I PUT IT HERE NOTHING WILL HAPPEND'  is exactly the result you will get! You are NOT doing anything with $result to produce anything? So I don't understand the problem correctly?

36 minutes ago, Weiss said:

session_start();

Should be at the top before anything else.

Share this post


Link to post
Share on other sites

It doesn't look like $mysqli has been defined.  And if you're not seeing an error message about that, then you either have error messages disabled or you're not checking the error log.  You can display them on the page like this:

ini_set('display_errors', 1);
	error_reporting(E_ALL);

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...