Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populate form field with db data 1

Status
Not open for further replies.

frozenpeas

Technical User
Sep 13, 2001
893
CA
Hi, my fields are just showing up blank. Does anyone know why?

Thanks.

I am calling the row properly and am able to use the data elsewhere. I think it's the syntax of my code. I have narrowed the problem down to the lines below.

Code:
<?
echo '<input name=&quot;date&quot; type=&quot;text&quot; id=&quot;date&quot; maxlength=&quot;6&quot; size=&quot;6&quot; value=&quot;'.$row['date'].'&quot;>';
?>
 
I usually do this:

<?
$the_date=$row['date'];

echo '<input name=&quot;date&quot; type=&quot;text&quot; id=&quot;date&quot; maxlength=&quot;6&quot; size=&quot;6&quot; value=&quot;$the_date&quot;>';
?>

HTH,

Quasibobo Don't eat yellow snow!
 
frozenpeas,

Why don't you try doing a:

print_r($row);
die();

just before your statement there to see if what you expect to be in $row is actually in there.

When this happens to me its usually something like case sensitivity.

Quasibobo, Single quoted strings aren't interpolated so the variable whould be printed as '$the_date', to do it that way you would have to use a double quoted string.

Hope this helps. [smurf]
01101000011000010110010001110011
 
Thanks.

Hads, I tried what you suggested but get nothing outputted.

Here is how I'm trying to query the db.

Code:
<?
$query = mysql_query('SELECT * FROM cecil_service WHERE id = 1') or die ('Could not query database.');
$row = mysql_fetch_array($query)
?>

Thanks again.
 
Is your query returning any rows? mysql_query() will only return false if there is a problem with your SQL statement, but a result resource with no rows is valid.

What does mysq_num_rows() say? ______________________________________________________________________
TANSTAAFL!
 
You missed a bit ;-)

Basically you need these bits;

$connection = mysql_connect($db_host, $db_user, $db_pass);
mysql_select_db($db_name);
$result = mysql_query($query, $connection);


But check out sleipnir214s post about 4 down in this thread: thread434-238760 for a good way of querying the database with error checking. [smurf]
01101000011000010110010001110011
 
Oops, bit slow. [smurf]
01101000011000010110010001110011
 
I didn't miss connecting to the database... I can do that fine. I'm including only the code that seems to be causing the problem.

Code:
mysql_num_rows()

returns

Code:
Warning: Wrong parameter count for mysql_num_rows()
 
Code:
mysql_num_rows();
should be
Code:
mysql_num_rows($result);
//Daniel
 
Yeah, I do apoligise, I should learn to read before I post.

I thought you missed mysql_query() because you used the variable $query instead of $result.

My bad. [smurf]
01101000011000010110010001110011
 
I get a parse error no matter how I call

mysql_num_rows($result);
 
A parse error generally means you have a typo somewhere in your code. ______________________________________________________________________
TANSTAAFL!
 
Here's a chunk:

Code:
<?
require_once('connect.php');
require_once('output_fns.php');
html_header(':: Edit Service Record');
?> 
<form action=&quot;edit_record.php&quot; method=&quot;post&quot; name=&quot;form&quot; id=&quot;form&quot;>
          <?
		  $record = $radiobutton;
		  $query = mysql_query('SELECT * FROM cecil_service WHERE id = &quot;$record&quot;') or die ('Could not query database.');
		  $row = mysql_fetch_array($query)
		  echo 'mysql_num_rows($query)';
		  ?>
  <table width=&quot;100%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;5&quot;>
    <tr valign=&quot;top&quot;> 
      <td width=&quot;22%&quot;><font size=&quot;2&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;><strong>Date:</strong></font></td>
      <td width=&quot;78%&quot;> <div align=&quot;left&quot;><font size=&quot;2&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;> 
          <?
		  echo '<input name=&quot;date&quot; type=&quot;text&quot; id=&quot;date&quot; maxlength=&quot;6&quot; size=&quot;6&quot; value=&quot;'.$row['date'].'&quot;>';
		  ?>
		  </font></div></td>
    </tr>
 
That is a lovely chunk of code.

To begin with, the missing semicolon at the end of the line reading &quot;$row = mysql_fetch_array($query)&quot;.

Don't just post code and expect us to figure it out. At the very least, give us the exact[/] error message and indicate the offending line. ______________________________________________________________________
TANSTAAFL!
 
Also,
Code:
          echo 'mysql_num_rows($query)';
would output just that. What you want is
Code:
          echo mysql_num_rows($query);
//Daniel
 
Thanks for your help. There is no need to patronize, sleipnir214... some of us are newer to this than others.

mysql_num_rows($query) is now returning 0. So that would explain why I'm not able to pull any data out of there. But why is it returning 0? The database has entries (that I have been accessing).

Thanks again.
 
Does $record contain what you excpect it to?

Also:

'SELECT * FROM cecil_service WHERE id = &quot;$record&quot;'

should be either;

'SELECT * FROM cecil_service WHERE id = '.$record

or;

&quot;SELECT * FROM cecil_service WHERE id = $record&quot; [smurf]
01101000011000010110010001110011
 
Thanks, hads. $record does contain what I expect it to.

('SELECT * FROM cecil_service WHERE id = '.$record) was the culprit. I wasn't sure how that should be formatted so thanks very much for your help!

I'm giving you a star not only for your helpful advice but for your friendly manner. Things like that go a long way.
 
Why is it that words like &quot;patronize&quot; are only bandied around after the person had benefitted from the patronage of the membership?

I improperly closed a TGML tag for underlining, which underlined more word than I intended. I know better than to post responses with TGML tags in them before posting.

But the advice still holds. When you're posting code that is producing an error, use some method to highlight the offending line. The parse error you got was an easy one to spot -- a missing semicolon. But that error can also be caused by improperly closed quotes, braces, brackets, or parenthesis, which can be a task to spot. Highlighting offending lines of code can be of great value to those who are trying to help you.
______________________________________________________________________
TANSTAAFL!
 
The last part of your last post would have been an appreciated response instead of:

&quot;That's a lovely chunk of code... Don't just post code and expect us to figure it out.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top