Re: show data on the text input box
| From: | Ken Robinson | Date: | Sat, 10 May 2014 00:43:29 +0000 |
| Subject: | Re: show data on the text input box | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-323268@lists.php.net to get a copy of this message | ||
Good.
I don't always error check my code.
While developing, you should be running with errors displayed. The 500 error was caused by PHP dying on the error. If you had errors showing, that error would have been shown to you.
Ken
At 08:34 PM 5/9/2014, iccsi wrote:
I got it works now, I just put a curly bracket in the end of the line, Thanks a million again for helping, Regards, Iccsi, "Ken Robinson" wrote in message news:08.2A.46741.2196D635@pb1.pair.com... Here's my re-work of your code. I moved the PHP section to the start of the file & stored the output needed in a temporary array, which is output in the correct place. The reason that this line: <input name="mytext" type="text" value="<?php echo ($row['invdate']); ?>" /> doesn't show anything is that there is no data in $row at that point. <?php $hostname = "localhost"; $username = "root"; $password = "password"; try {$dbh = newPDO("mysql:host=localhost;dbname=mydb;charset=utf8", $username, $password);$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); echo "Connected to database";} catch(PDOException $e) {echo $e->getMessage();} $tmp = array(); $stmt = $dbh->query('SELECT invid, invdate, client_id, amount from invheader'); while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {$tmp[] = "<td>"; $tmp[] = "<input name='mytext' type='text'value='{$row['invdate']}' />";$tmp[] = "</td>"; $tmp[] = "{$row['invid']} {$row['invdate']}{$row['client_id']} {$row['amount']"; //etc... } ?> <!DOCTYPE html> <head><title>Search data</title></head> <body><table> <tr> <td align="center">EMPLOYEES DATA</td> </tr> <tr> <td> <table border="1"> <tr> <?php echo implode("\n",$tmp) . "\n"; ?> </tr> </table> </td> </tr> </table></body> </html> Ken At 07:25 PM 5/9/2014, iccsi wrote:Here is full code, Thanks again for helping, Regards, Iccsi, <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Search data</title> </head> <body> <table> <tr> <td align="center">EMPLOYEES DATA</td> </tr> <tr> <td>-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php<table border="1"> <tr> <td> <input name="mytext" type="text" value="<?php echo ($row['invdate']); ?>" /> </td></tr><?php $hostname = "localhost"; $username = "root"; $password = "password"; try { $dbh = new PDO("mysql:host=localhost;dbname=mydb;charset=utf8", $username, $password);$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); echo "Connected to database"; }catch(PDOException $e) { echo $e->getMessage();}$stmt = $dbh->query('SELECT invid, invdate, client_id, amount from invheader'); while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo $row['invid'].' '.$row['invdate'].' '.$row['client_id'].' '.$row['amount']; //etc... } ?> </table> </td> </tr> </table> </body> </html> "Jim Lucas" wrote in message news:536D5FF8.3050404@cmsws.com... On 05/09/2014 03:54 PM, iccsi wrote:I tried both with '\' or without '\', but I do not see the data on the text box on both situation. Do I need fetch records using php or how do I know that it is not end of file?What does your full code look like now?Thanks again, Regard, Iccsi, "Jim Giner" wrote in message news:AE.B6.46741.8745D635@pb1.pair.com... On 5/9/2014 6:12 PM, iccsi wrote:-- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.phpThanks for the information and help, I use the following code to show data, but it shows '/', but not data. <td><input name="mytext" type="text" value=<?php echo ($row['invdate']); ?> /></td> Are there any way to access from mySQL result data? Thanks again for helping, Regards, Iccsi, "Robert Cummings" wrote in message news:536C7208.6050201@interjinn.com... On 14-05-09 12:37 AM, iccsi wrote:You have no quotes on your value clause. Plus this might be easier to type and read: <? echo "<td><input name='mytext' type='text' value='{$row[\'invdate\']}'>"; ?> (Not sure you need the \ inside the [] on the $row reference, but I put them there.)I have following code to connect MySQL and database. I see 'connected to database', I would like to know that which code do I need to show my data on the text box? Your help and information is great appreciated,Do you mean like the following? <input name="mytext" type="text" value="<?php echo htmlspecialchars( $value ); ?>" /> Cheers, Rob.