RE: [PHP-DB] SELECT statement does not return rows
| From: | Shrock, Court | Date: | Fri, 01 Feb 2002 23:32:42 +0000 |
| Subject: | RE: [PHP-DB] SELECT statement does not return rows | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-16432@lists.php.net to get a copy of this message | ||
I am assuming that this code is NOT the file "do_mod_job.php".
What happens if you do this next line right after you execute your query?:
echo 'num rows fetched: '.mysql_num_rows($result).'<br>';
also, the while loop shouldn't really be necessary as the query should only
return one record if I understand the naming of your fields correctly. Your
echo statements don't have to have the variable encapsulated with
double-quotes either--it is actually easier on PHP if they are not (if you
use single-quotes rather than double-quotes as well when appropriate).
If there is a row being returned from the query as discovered above, you
might try the following to make sure that what you are getting is what you
are expecting:
$row = mysql_fetch_array($result)
echo
'<table><tr><th>column</th><th>value</th></tr>';
while(list($key, $val) = each($row)) {
// $row has two key/value pairs per column -- one integer, one string
if (is_string($key)) {
echo "<tr><td>$key</td><td>$val</td></tr>";
}
}
echo '</table>';
exit;
basically, you need to verify that $row['id'] is not empty.....
> -----Original Message-----
> Todd Williamsen <todd@williamsen.net> said:
>
> > Weird..
> >
> > I want to be able to edit records, which I have done in the
> past, and I
> > cannot see why it isn't working... I have tried single
> qoutes around the
> > $row = and that doesn't work either. here is the code:
> >
> > $db = @mysql_select_db($db_name, $connection) or die("Could
> not select
> > database");
> > $sql="SELECT * FROM Jobs WHERE id = '$id' ";
> > $result = mysql_query($sql,$connection) or die("Couldn't
> execute query");
> > while ($row = mysql_fetch_array($result))
> > {
> > $id = $row["id"];
> > $Industry = $row["Industry"];
> > $Other = $row["Other"];
> > $JobTitle = $row["JobTitle"];
> > $Description = $row["Description"];
> > $Location = $row["Location"];
> > $Date = $row["Date"];
> > }
> > ?>
> > <html>
> > <head>
> > <Title>Edit Job Posting</title>
> > </head>
> > <body>
> > <h1>Edit Job Posting</h1>
> > <form method="post" action="do_mod_job.php">
> > <input type="hidden" name="id" value="<? echo
> > "$id"; ?>">
> > <table cellspacing=3 cellpadding=5 align="center">
> > <tr>
> > <th>Job Information and Location</th>
> > <th>Job Description</th>
> > </tr>
> > <tr>
> > <td valign=top>
> > <p><strong>Job Title:</strong><br>
> > <input type="text" name="JobTitle" value="<?php echo
> "$JobTitle"?>" size=50
> > maxlength=75></p>
> > <p><strong>Industry:</strong><br>
> > <input type="text" name="Industry" value="<? echo
> "$Industry"; ?>" size=50
> > maxlength=75></p>
> > <p><strong>Other:</strong><br>
> > <input type="text" name="Other" value="<? echo
> > "$Other";?>" size=50
> > maxlength=75></p>
> > <p><strong>Location:</strong><br>
> > <inout type="text" name="Location" value="<? echo
> "$Location"; ?>" size=50
> > maxlength=75></p>
> > <p><strong>Date:</strong><br>
> > <input type="text" name="Date" value="<? echo
> > "$Date"; ?>" size=30
> > maxlength=40></p>
> > </td>
> > <td valign=top>
> > <p><strong>Description:</strong><br>
> > <textarea name="Description" cols="50"
> > rows="10"><? echo
> > "$Description"; ?></textarea>
> > </p>
> > </td>
> > </tr>
> > <tr>
> > <td align=center colspan=2><br>
> > <p><input type="submit" name="submit" value="Update
> > Job"></p>
> > <br>
> > </td>
> > </tr>
> > </table>
> > </form>
> > </body>
> > </html>