Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts

    Question how to show details when passing ID

    Code:
    <?php
    include_once("config.php");
    include_once("functions.php");
    $_GET["ID"];
    
    $result = mysql_query("SELECT * FROM assessment WHERE ID = ".$_GET["ID"]);
    // Check user logged in already:
    checkLoggedIn("yes");
    doCSS();?>
    <div id="header">
    <p class="wrap">
    <? print("\n<a href=\"display.php"."\">View Assessments</a> | \n<a href=\"logout.php"."\">Logout</a> <b>".$_SESSION["login"]."</b>");?>
    </p>
    <h1 class="wrap">Assessments</h1>
    </div>
    
    <form action="insert.php" method="post" class="wrap">
    <input name="Assessor" type="hidden" value="<? print($_SESSION["login"]);?>" />
    <input name="Dateadded" type="hidden" value="<?=date("y,m,d H:i:s A")?>" />
    <br>
    <select name="page">
    <option value="Page to be modified" selected="selected">Page to be modified</option>
    <option value=""></option>
    <option value="page1.htm">page1.htm</option>
    <option value="page2.htm">page2.htm</option>
    <option value="page3.htm">page3.htm</option>
    <option value="page4.htm">page4.htm</option>
    </select>
    <br>
    <select name="section">
    <option value="Page Section..." selected="selected">Page Section...</option>
    <option value=""></option>
    <option value="section1">section1</option>
    <option value="section2">section2</option>
    <option value="section3">section3</option>
    </select>
    <br>
    <select name="assignedto">
    <option value="Assign page to..." selected="selected">Assign page to...</option>
    <option value=""></option>
    <option value="john">john</option>
    <option value="gemma">Gemma</option>
    <option value="jamie">Jamie</option>
    </select>
    <br />
    
    <? 
    
    echo $_GET["ID"];
    echo $result["Assessor"];
    ?>
    <textarea name="Assessment" cols="30" rows="5"></textarea>
    <br>
    <input type="submit" class="button" value="Add Assessment"/>
    <br>
    <a href="display.php">View Assessments</a>
    </form>
    echo $result["Assessor"]; is not showing anything?! why?

  • #2
    New Coder
    Join Date
    Mar 2008
    Location
    Somerset, England
    Posts
    93
    Thanks
    0
    Thanked 10 Times in 10 Posts
    I'm guessing there's something wrong with your SQL change the first couple of lines to this. This will show up any problems with the sql statement.

    PHP Code:
    <?php
    include_once("config.php");
    include_once(
    "functions.php");
    $id $_GET['ID'];

    $sql "SELECT * FROM assessment WHERE ID = '$id'";
    $result mysql_query($sql) or die (mysql_error());

    ?>
    EDIT: just reread your code, the problem is that mysql_query just returns a result resource, to access the result you need to perform another mysql function. If all you require is "Assessor" try this.

    PHP Code:
    <?php
    ...
    $assessor mysql_result($result0'Assessor');
    echo 
    $assessor;
    ...
    ?>
    Also update your SQL statement and replace * with Assessor, no need to pull out the entire row if you only need one field.
    Last edited by RMcLeod; 05-20-2008 at 11:19 AM.

  • #3
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts
    i used your code and i got:

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #7' at line 1

  • #4
    Regular Coder
    Join Date
    Sep 2006
    Location
    Vermont, USA
    Posts
    154
    Thanks
    0
    Thanked 6 Times in 6 Posts
    $result is just a query reference... use something like...
    PHP Code:
    $result mysql_query("SELECT * FROM assessment WHERE ID = ".$_GET["ID"]);
    $record_set $result && mysql_num_rows($result) == mysql_fetch_assoc($result) : false
    now $record_set is either boolean false, or it contains the record you were seeking, so you'd use
    PHP Code:
    echo $record_set['table_column']; 
    to output whatever data you're seeking. This also allows you to check if $record_set == false so you can output an appropriate message.
    Active PHP/MySQL application developer available for immediate work.
    syosoft.com mavieo.com - Remote Web Site Administration Suite - Reseller Ready

  • Users who have thanked syosoft for this post:

    jarv (05-20-2008)

  • #5
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts
    great thanks! x


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •