Jump to content

[SOLVED] Load Form With Database Information


usadarts

Recommended Posts

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.....

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>";
	  } 

?>

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>";

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>";
	  } 

?>

 

<?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'];
?>

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);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.