Jump to content

echo repopulating blank data in database on refresh. please help


bremen1984

Recommended Posts

hi all i am having a big problem that i have been trying to find out what is going on for weeks. i have a echo script that echos data that is in my database, and if i have to refresh the page it will add blank data in my database and the top echo info is blank as well. how can i fix this, and i was wanting to know how do i echo out my info in a textarea. i added a jepg to show you what i mean.

 

here is my code

 

echoforms.php

 

<?php

 

error_reporting(0);

 

 

require_once('demo.php');

/*Open the connection to our database use the info from the config file.*/

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

 

$sql = "SELECT company_name, contact_name, address, street_number, postcode, contact_number, contact_email, budget, description FROM 3dartactforms";

 

$results = mysql_query($sql);

 

if (!$results) {

die('Invalid query: ' . mysql_error());

}

 

 

 

while($result = mysql_fetch_array( $results )){

echo '<div style="border: 1px solid #e4e4e4; padding: 15px; margin-bottom: 10px;">';

echo date("d/m/y");

echo '<p>Company Name: ' . $_POST['company_name'] . '</p>';

echo '<p>Contact Name: ' . $_POST['contact_name'] . '</p>';

echo '<p>Address: ' . $_POST['address'] . '</p>';

echo '<p>Street Number: ' . $_POST['street_number'] . '</p>';

echo '<p>Postcode: ' . $_POST['postcode'] . '</p>';

echo '<p>Contact Number: ' . $_POST['contact_number'] . '</p>';

echo '<p>Contact Email: ' . $_POST['contact_email'] . '</p>';

echo '<p>Budget: ' . $_POST['budget'] . '</p>';

echo '<p>Description: ' . $_POST['description'] . '</p>';

echo '</div>';

}

 

 

?>

 

[attachment deleted by admin]

Link to comment
Share on other sites

Your code makes no sense and I would bet money that there is more to the code than you are showing!

 

You do a DB query and then loop through the results assigning each record to the array variable $result. But, in that loop you are echoing the values from the variable $_POST.

 

So, I am guessing that each time the page loads you also have some code (not shown) that is inserting records based upon the POST data which would explain why you get more entries displayed. I also suspect you aren't checking the POST data properly and you are getting an empty record.

 

If you at least change the $_POST to $result in the while() loop you will at least be seeing the data from the database.

 

To echo your data in a textarea, just do exactly that

<textarea name="fieldname"><?php echo $value; ?></textarea>

 

Note, when echoing user entered data to a page, always be sure to apply the appropriate "escaping" mechanism. When displaying as HTML use htmlentities(), in an input field use htmlspecialchars()

Link to comment
Share on other sites

Sorry bremen, as mjdamato pointed out, there is no way you are getting results show from the DB when you have $_POST as the variables.  You need to change those to $result as he suggested.

  echo '<div style="border: 1px solid #e4e4e4; padding: 15px; margin-bottom: 10px;">';
   echo date("d/m/y");
   echo '<p>Company Name: ' . $result['company_name'] . '</p>';
   echo '<p>Contact Name: ' .$result['contact_name'] . '</p>';
   echo '<p>Address: ' .$result['address'] . '</p>';
   echo '<p>Street Number: ' . $result['street_number'] . '</p>';
   echo '<p>Postcode: ' . $result['postcode'] . '</p>';
   echo '<p>Contact Number: ' . $result['contact_number'] . '</p>';
   echo '<p>Contact Email: ' . $result['contact_email'] . '</p>';
   echo '<p>Budget: ' . $result['budget'] . '</p>';
   echo '<p>Description: ' .$result['description'] . '</p>';
   echo '</div>';

Link to comment
Share on other sites

ok sorry i posted the wrong script, here is the right one.

 

<?php

 

error_reporting(0);

 

 

require_once('demo.php');

 

 

/*Open the connection to our database use the info from the config file.*/

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

 

$sql = "SELECT company_name, contact_name, address, street_number, postcode, contact_number, contact_email, budget, description FROM 3dartactforms";

 

$results = mysql_query($sql);

 

if (!$results) {

die('Invalid query: ' . mysql_error());

}

 

echo '<h3>3D art ACT</h3>';

 

while($result = mysql_fetch_array( $results )){

echo '<div style="border: 1px solid #e4e4e4; padding: 15px; margin-bottom: 10px;">';

echo '<p>Company Name: ' . $result['company_name'] . '</p>';

echo '<p>Contact Name: ' . $result['contact_name'] . '</p>';

echo '<p>Address: ' . $result['address'] . '</p>';

echo '<p>Street Number: ' . $result['street_number'] . '</p>';

echo '<p>Postcode: ' . $result['postcode'] . '</p>';

echo '<p>Contact Number: ' . $result['contact_number'] . '</p>';

echo '<p>Contact Email: ' . $result['contact_email'] . '</p>';

echo '<p>Budget: ' . $result['budget'] . '</p>';

echo '<p>Description: ' . $result['description'] . '</p>';

echo '</div>';

}

 

 

?>

 

Link to comment
Share on other sites

ok thanks i got the echo scropt working, but i need help with it echoing in the textarea, can get more help pleas.

 

What help do you need? You apparently didn't take the time to even really read the initial response I gave you because you completely disregarded the problem I raised. But, I also showed you how you would echo contents inside a textarea. What about the sample code I provided do you not understand?

Link to comment
Share on other sites

As mjdamato point out, you just put it between your textarea tags.  I would check to see if you have a value for the textarea and display it if found otherwise not put variable in.  Something like this.

IF (!empty($result['description'])){
echo "<textarea name=\"newdescription\" cols='80' rows='5'>$result[description]</textarea>\r";
}
ELSE{
echo "<textarea name=\"newdescription\" cols='80' rows='5'></textarea>\r";
}

Link to comment
Share on other sites

As mjdamato point out, you just put it between your textarea tags.  I would check to see if you have a value for the textarea and display it if found otherwise not put variable in.  Something like this.

IF (!empty($result['description'])){
echo "<textarea name=\"newdescription\" cols='80' rows='5'>$result[description]</textarea>\r";
}
ELSE{
echo "<textarea name=\"newdescription\" cols='80' rows='5'></textarea>\r";
}

 

No offense, but that IF/THEN statement serves no purpose. If the result is empty then you will get the same results if you used the first echo. Since $result['description'] is a field returned from the DB query it will be defined, but it may not have a value. Typically, you would do something as you showed if the variable may not be set - to prevent errors.

Link to comment
Share on other sites

ok i get what you are saying i think, that is not what i am asking. see in my web site i do not have much room for the echo results so i was thinking that if i was to echo them in a textara or add a scrollbar then they can fit on my site. i was think of like in an email form there is a scrollbar that one can move to see all that is there. i hope that clear's thing up.

 

 

 

<?php

 

/*Open the connection to our database use the info from the config file.*/

$link = mysql_connect("localhost", "root", "Steph1989");

 

//connect to the database

mysql_select_db("eclipse_media");

 

$sql = "SELECT company_name, contact_name, address, street_number, postcode, contact_number, contact_email, budget, description FROM 3dartactforms";

 

$results = mysql_query($sql);

 

if (!$results) {

die('Invalid query: ' . mysql_error());

}

 

echo '<h3>3D art ACT</h3>';

 

while($result = mysql_fetch_array( $results )){

echo '<div style="border: 1px solid #e4e4e4; padding: 15px; margin-bottom: 5px;">';

echo date("d/m/y");

echo '<p>Company Name: ' . $result['company_name'] . '</p>';

echo '<p>Contact Name: ' . $result['contact_name'] . '</p>';

echo '<p>Address: ' . $result['address'] . '</p>';

echo '<p>Street Number: ' . $result['street_number'] . '</p>';

echo '<p>Postcode: ' . $result['postcode'] . '</p>';

echo '<p>Contact Number: ' . $result['contact_number'] . '</p>';

echo '<p>Contact Email: ' . $result['contact_email'] . '</p>';

echo '<p>Budget: ' . $result['budget'] . '</p>';

echo '<p>Description: ' . $result['description'] . '</p>';

echo '</div>';

}

 

 

?>

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.