...

View Full Version : how to show details when passing ID



jarv
05-20-2008, 09:56 AM
<?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?

RMcLeod
05-20-2008, 10:13 AM
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
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
...
$assessor = mysql_result($result, 0, '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.

jarv
05-20-2008, 10:23 AM
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

syosoft
05-20-2008, 11:30 AM
$result is just a query reference... use something like...


$result = mysql_query("SELECT * FROM assessment WHERE ID = ".$_GET["ID"]);
$record_set = $result && mysql_num_rows($result) == 1 ? mysql_fetch_assoc($result) : false;


now $record_set is either boolean false, or it contains the record you were seeking, so you'd use


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.

jarv
05-20-2008, 12:01 PM
great thanks! x



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum