Hi David,
Try this..
if(!isset($_POST['ErrorCode'])) {
die('You did not enter an error code!');
} else {
$errorcode = $_POST['ErrorCode'];
$sql = mysql_query("SELECT * FROM Sheet1 WHERE errorcode='".
$errorcode."' ");
if($sql && mysql_numrows($sql) > 0) {
$row = mysql_fetch_array($sql);
for($i=0; $i<mysql_numrows($sql); $i++) {
echo ("Error Code: ".$row[$i]['errorcode']."<br />");
echo ("Error Definition: ".$row[$i]['definition']."<br />");
echo ("<br />");
}
} else {
die('No Error Code found in database');
}
}
Have not tested this, and there may be a better "short-hand" way of
writing this, but hope it gets you on your way...
Best,
Karl
On May 27, 2011, at 2:11 PM, David McGlone wrote:
Hello everyone,
I need a little help. I've never tried to extract from a db in the
manner I'm trying. It's pretty simple and straightforward I
believe, but
for some reason I can't figure out how.
What I have is a form with 1 simple field, and this field takes the ID
of the row I want returned.
Here's my code so far.
--index.php--
echo '<form action="result.php" method="post">
Enter Error Code:<br />
<input type="text" name="ErrorCode" /><br />
<input type="Submit" name="submit" value="Submit">
</form>' ;
-result.php-
$errorcode = $_POST['ErrorCode'];
echo $errorcode;
$sql = mysql_query("SELECT errorcode,definition FROM Sheet1");
while ($row = mysql_fetch_array($sql)) {
echo "$row[errorcode]<br />";
echo "$row[definition]<br />";
}
So far this is as far as I've got. I can successfully post the number
entered into the form field, but I'm having trouble making use of the
number.
With this code, my idea was to turn the posted number from the form
into
a variable and use that as a reference to extract that row number from
the db, but my attempts are unsuccessful.
I've also unsuccessfully attempted to use a WHERE clause in my
SELECT to
only display the row that is posted.
I hope all this makes sense.
Regards,
David M.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Karl DeSaulniers
Design Drumm
http://designdrumm.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php