Jump to content

kasitzboym

Members
  • Posts

    26
  • Joined

  • Last visited

Posts posted by kasitzboym

  1. Hey everyone this is my first post so hopefully i am doing this right...

     

    I have a basic php file to use to test my idea which seams to work just fine but when i try to pull the information from a mysql database and implement the same idea with database variables the information doesn't seem to work. I have tried multiple ways to get the code to read correctly but i cant seam to find the error.. The code below is the starter code i have to work with then below i will post the code which i am trying to work with... if someone could help explain this to me i would greatly appreciate it.

     

    ----------------------WORKING BASIC CODE

     

     

    <?php

    //set up a "database" of names, descriptions, and image locations for two staff members: jane and bob

     

    $names = array('jane'=>'Jane Dow', 'bob'=>'Bob Smith');

    $descriptions = array('jane'=>'Jane is an ECE major', 'bob'=>'Bob is a physics major');

    $images = array('marcus'=>'/images/marcus.jpg', 'bob'=>'/images/bob.jpg');

     

    //determine which staff member the user wants to see info for

    $input = $_GET['name']; //for staff.php?name=[name]

    //could also use $keys = array_keys($_GET); $input = $keys[0]; if you want something like staff.php?[name]

     

    //this section takes the input from the URL (what we want to see information for) and selects the appropriate content from the arrays

    $name = $names[$input];

    $description = $descriptions[$input];

    $image = $images[$input];

     

    ?>

     

     

    <html>

    <body>

    <a href="testscript.php?name=jane">Jane</a><br>

    <a href="testscript.php?name=bob">Bob</a>

     

    <img src="<?php echo $image; ?>">

    <br><b>Name:</b> <?php echo $name; ?></b>

    <br><b>Description:</b> <?php echo $description; ?>

    </body>

    </html>

     

     

    -----------------------This is the code that i was trying to actually use

     

    <?php

     

    require("connect.php");

     

    $id = ($_GET['id']);

     

    $query="SELECT * FROM staff";

    $result=mysql_query($query);

     

    mysql_close();

     

     

    $result = mysql_fetch_array($result);

    $id=$result['id'];

    $firstname=$result['firstname'];

    $lastname=$result['lastname'];

    $bio=$result['bio'];

     

     

     

     

    if (isset($_GET['id']))

    {

    echo "$firstname <br> $bio ";

    }

    else

    {

    echo "The Staff Member Does Not Exist";

    }

     

    ?>

     

     

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