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

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

<?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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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