Jump to content

head first mysql php


phpbiginner

Recommended Posts

how you doing guys. I'm having a little bit of a problem right now, with this thing call view-profile.php, i hope you guys know what it is, I'm new to php, so please try to help.

it says the same thing everytime.

 

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\siteS\viewprofile.php on line 26

 

There was a problem accessing your profile

 

 

<h3>Mismatch - View Profile</h3>

 

<?php

  require_once('appvars.php');

  require_once('connectvars.php');

 

  // Connect to the database

  $dbc = mysqli_connect('localhost', '***', '*****', '*****');

 

  // Grab the profile data from the database

  if (!isset($_GET['user_id'])) {

    $query = "SELECT username, first_name, last_name, gender, birthdate, city, state, picture FROM mismatch_user WHERE user_id = '$user_id'";

  }

  else {

    $query = "SELECT username, first_name, last_name, gender, birthdate, city, state, picture FROM mismatch_user WHERE user_id = '" . $_GET['user_id'] . "'";

  }

  $data = mysqli_query($dbc, $query);

line26-----------> if (mysqli_num_rows($data) == 1) {

    // The user row was found so display the user data

    $row = mysqli_fetch_array($data);

    echo '<table>';

    if (!empty($row['username'])) {

      echo '<tr><td class="label">Username:</td><td>' . $row['username'] . '</td></tr>';

    }

    if (!empty($row['first_name'])) {

      echo '<tr><td class="label">First name:</td><td>' . $row['first_name'] . '</td></tr>';

    }

    if (!empty($row['last_name'])) {

      echo '<tr><td class="label">Last name:</td><td>' . $row['last_name'] . '</td></tr>';

    }

    if (!empty($row['gender'])) {

      echo '<tr><td class="label">Gender:</td><td>';

      if ($row['gender'] == 'M') {

        echo 'Male';

      }

      else if ($row['gender'] == 'F') {

        echo 'Female';

      }

      else {

        echo '?';

      }

      echo '</td></tr>';

    }

    if (!empty($row['birthdate'])) {

      if (!isset($_GET['user_id']) || ($user_id == $_GET['user_id'])) {

        // Show the user their own birthdate

        echo '<tr><td class="label">Birthdate:</td><td>' . $row['birthdate'] . '</td></tr>';

      }

      else {

        // Show only the birth year for everyone else

        list($year, $month, $day) = explode('-', $row['birthdate']);

        echo '<tr><td class="label">Year born:</td><td>' . $year . '</td></tr>';

      }

    }

    if (!empty($row['city']) || !empty($row['state'])) {

      echo '<tr><td class="label">Location:</td><td>' . $row['city'] . ', ' . $row['state'] . '</td></tr>';

    }

    if (!empty($row['picture'])) {

      echo '<tr><td class="label">Picture:</td><td><img src="' . MM_UPLOADPATH . $row['picture'] .

        '" alt="Profile Picture" /></td></tr>';

    }

    echo '</table>';

    if (!isset($_GET['user_id']) || ($user_id == $_GET['user_id'])) {

      echo '<p>Would you like to <a href="editprofile.php">edit your profile</a>?</p>';

    }

  } // End of check for a single row of user results

  else {

    echo '<p class="error">There was a problem accessing your profile.</p>';

  }

 

  mysqli_close($dbc);

?>

 

 

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • 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.