0

I have created a booking system which uses a clients username from their log in to auto populate a user name field when making a booking. I am not sure of how to get other information like their full name and ID from the database into these fields. Below is the code I have used to verify log in and store their username:

  <?php

    // Start up your PHP Session 
    session_start();

    // If the user is not logged in send him/her to the login form
    if ($_SESSION["Login"] != "YES_client") {
      header("Location: login.php");
    }

    $username = $_SESSION["username"];


  ?>

I have also implemented the user name in the field using the following code:

echo "<input type='text' name='name' class='form-control' id='FullInputName' value=" . $username . ">"

Is there something simple I am missing? I have tried various methods to display the full data like using $row["Client_ID"] etc but could not get this to work for only the client who is logged into the system. My SQL statement is as follows:

"SELECT * FROM client WHERE Client_username= $username"

I would like to use the Client_ID in the select statement also to make it Unique. I have tried but got various errors.

Any help would be much appreciated!

EDIT

This is the code I have now tried to implement:

$query = "SELECT * FROM client WHERE Client_username='$username'";
            echo $query;
            $result = mysql_query($query);


            while($row = mysql_fetch_array($result))
            {
                echo $row['Client_username'];
            }

But it is not working correctly - I am receiving this error:

mysql_fetch_array() expects parameter 1 to be resource, boolean given
Chris R.
  • 41
  • 6

1 Answers1

0

Starting with your query i think is not correct.

If you are selecting a row and the type is a VARCHAR you need to add single quotes like this:

"SELECT * FROM client WHERE Client_username= '$username'"

Later you can read the results like

(pseudocode) while($row = mysqli_fetch_array) $row['Client_username']

something like that.

Tell me if this works for you

Slico
  • 436
  • 2
  • 16
  • Using the help I have been given, I added single quotes to `'$username'` in the SQL string but the system is stil given errors - see my EDIT. – Chris R. Sep 17 '15 at 13:36
  • The problem is that the mysql query is not correct check that the fields on your query corresponds with the fields of the mysql database. Check this link, i hope it helps you http://stackoverflow.com/a/2973209/4270737 – Slico Sep 17 '15 at 14:57