usadarts Posted August 19, 2007 Share Posted August 19, 2007 I have a form in which I want to load information from a database within a textarea. I have the following code: <?php $dbh=mysql_connect ("localhost", "xxxxxxx_xxxxxxx", "xxxxxxx") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("xxxxxxx_xxxxxxx"); $queryr = "SELECT * FROM `page`"; $date = $_GET['date']; $comments = $_GET['comments']; ?> <form action="posthp.php" method="POST"> <textarea name="newcomments" cols="100" rows="20"><?php echo $comments; ?></textarea> <br> <input type="submit" name="Submit" value="Submit Form"> </form> Not working..... Link to comment https://forums.phpfreaks.com/topic/65734-solved-load-form-with-database-information/ Share on other sites More sharing options...
trq Posted August 19, 2007 Share Posted August 19, 2007 Define not working. You never actually query the database so im note sure exactly what your trying to do. Take a look at the examples for mysql_query() if your stuck. Link to comment https://forums.phpfreaks.com/topic/65734-solved-load-form-with-database-information/#findComment-328352 Share on other sites More sharing options...
teng84 Posted August 19, 2007 Share Posted August 19, 2007 try to read this http://w3schools.com/php/php_mysql_select.asp get back if still dont understand base on your post you really dont know what your doing that link i gave is very basic and will surely help you Link to comment https://forums.phpfreaks.com/topic/65734-solved-load-form-with-database-information/#findComment-328353 Share on other sites More sharing options...
usadarts Posted August 19, 2007 Author Share Posted August 19, 2007 This is what I have now and receiving the following error: Parse error: syntax error, unexpected T_ECHO, expecting ',' or ';' in /modifyhp.php on line 29 <?php $dbh=mysql_connect ("xxxxxxxx", "xxxxxxxx_xxxxxxxx", "xxxxxxxx") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("xxxxxxxx_xxxxxxxx"); $query = "SELECT * FROM `homepage`"; $result = mysql_query($query,$dbh) or die(mysql_error()); $comments = $_GET['comments']; while($row = mysql_fetch_array($result)) { echo "<form action=\"posthp.php\">"; echo "<textarea name=\"newcomments\" cols=\"100\" rows=\"20\">"; echo "$comments" echo "</textarea>"; echo "<input type="submit" />"; echo "</form>"; } ?> Link to comment https://forums.phpfreaks.com/topic/65734-solved-load-form-with-database-information/#findComment-328363 Share on other sites More sharing options...
MadTechie Posted August 19, 2007 Share Posted August 19, 2007 change echo "<form action=\"posthp.php\">"; echo "<textarea name=\"newcomments\" cols=\"100\" rows=\"20\">"; echo "$comments" echo "</textarea>"; echo "<input type="submit" />"; echo "</form>"; to echo "<form action=\"posthp.php\">"; echo "<textarea name=\"newcomments\" cols=\"100\" rows=\"20\">"; echo "$comments"; //ADDED ; echo "</textarea>"; echo "<input type=\"submit\" />"; // " to \" echo "</form>"; Link to comment https://forums.phpfreaks.com/topic/65734-solved-load-form-with-database-information/#findComment-328366 Share on other sites More sharing options...
usadarts Posted August 19, 2007 Author Share Posted August 19, 2007 Missed that. Fixed that line and a few other things. The page now loads, but nothing appears in the textarea. <?php $dbh=mysql_connect ("xxxxxxxx", "xxxxxxxx_xxxxxxxx", "xxxxxxxx") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("xxxxxxxx_xxxxxxxx"); $query = "SELECT * FROM `homepage`"; $result = mysql_query($query,$dbh) or die(mysql_error()); $comments = $_GET['comments']; while($row = mysql_fetch_array($result)) { echo "<form action=\"posthp.php\">"; echo "<textarea name=\"newcomments\" cols=\"100\" rows=\"20\">"; echo "$comments"; echo "</textarea>"; echo "<br>"; echo "<input type=\"submit\">"; echo "</form>"; } ?> Link to comment https://forums.phpfreaks.com/topic/65734-solved-load-form-with-database-information/#findComment-328371 Share on other sites More sharing options...
MadTechie Posted August 19, 2007 Share Posted August 19, 2007 i assume echo "$comments"; should be echo $row['comments']; Link to comment https://forums.phpfreaks.com/topic/65734-solved-load-form-with-database-information/#findComment-328374 Share on other sites More sharing options...
usadarts Posted August 19, 2007 Author Share Posted August 19, 2007 TY!!!!!!!!! Link to comment https://forums.phpfreaks.com/topic/65734-solved-load-form-with-database-information/#findComment-328376 Share on other sites More sharing options...
daled Posted August 19, 2007 Share Posted August 19, 2007 <?php $query = "SELECT * FROM `homepage`"; $result = mysql_query($query,$dbh) or die(mysql_error()); $comments = $_GET['comments']; ?> Your comments aren't coming from a database, their coming from a $_GET variable. should be: <?php $query = "SELECT * FROM `homepage`"; $result = mysql_query($query,$dbh) or die(mysql_error()); $row_result = mysql_fetch_assoc($result); $comments = $row_result['comments']; ?> Link to comment https://forums.phpfreaks.com/topic/65734-solved-load-form-with-database-information/#findComment-328379 Share on other sites More sharing options...
MadTechie Posted August 19, 2007 Share Posted August 19, 2007 please click topic solved (bottom left) if we're done Link to comment https://forums.phpfreaks.com/topic/65734-solved-load-form-with-database-information/#findComment-328385 Share on other sites More sharing options...
usadarts Posted August 20, 2007 Author Share Posted August 20, 2007 Now the POSTHP is not updating the database. This is all new to me, the update via webpage. Here is the POST code <?php $newcomments = $_POST['newcomments']; $date = date('ymd'); $dbh=mysql_connect ("xxxxxxxx", "xxxxxxxx_xxxxxxxx", "xxxxxxxx") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("xxxxxxxx_xxxxxxxx"); $update = "UPDATE `homepage` SET `date` = $date, `comments` = $newcomments WHERE `rrn` = 1"; $results = mysql_query($update); ?> Link to comment https://forums.phpfreaks.com/topic/65734-solved-load-form-with-database-information/#findComment-328394 Share on other sites More sharing options...
MadTechie Posted August 20, 2007 Share Posted August 20, 2007 is this correct ? $update = "UPDATE `homepage` SET `date` = $date, `comments` = $newcomments WHERE `rrn` = 1"; as i am not going to do all the work..! Link to comment https://forums.phpfreaks.com/topic/65734-solved-load-form-with-database-information/#findComment-328412 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.