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..... Quote 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. Quote 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 Quote 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>"; } ?> Quote 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>"; Quote 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>"; } ?> Quote 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']; Quote 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!!!!!!!!! Quote 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']; ?> Quote 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 Quote 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); ?> Quote 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..! Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.