bremen1984 Posted May 23, 2011 Share Posted May 23, 2011 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] Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 23, 2011 Share Posted May 23, 2011 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() Quote Link to comment Share on other sites More sharing options...
bremen1984 Posted May 24, 2011 Author Share Posted May 24, 2011 if there is data in the database it will echo it fine it just, displays blank data if i refresh the page. and to be frank it is all the code fro my echo script. Quote Link to comment Share on other sites More sharing options...
Drummin Posted May 24, 2011 Share Posted May 24, 2011 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>'; Quote Link to comment Share on other sites More sharing options...
bremen1984 Posted May 24, 2011 Author Share Posted May 24, 2011 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>'; } ?> Quote Link to comment Share on other sites More sharing options...
Drummin Posted May 24, 2011 Share Posted May 24, 2011 Well you haven't posted any code that would INSERT or UPDATE the DB so we can't help you. If you refresh a POST, sure it will send the data again and will be processed again. But as far as code shown, I don't see it. Quote Link to comment Share on other sites More sharing options...
bremen1984 Posted May 24, 2011 Author Share Posted May 24, 2011 can some one direct me to a good tut on echoing the form data i have looked on yahoo shearch, youtub, google, and many more so i do not know what else to do. Quote Link to comment Share on other sites More sharing options...
bremen1984 Posted May 24, 2011 Author Share Posted May 24, 2011 ok thanks i got the echo scropt working, but i need help with it echoing in the textarea, can get more help pleas. Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 24, 2011 Share Posted May 24, 2011 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? Quote Link to comment Share on other sites More sharing options...
Drummin Posted May 24, 2011 Share Posted May 24, 2011 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"; } Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 24, 2011 Share Posted May 24, 2011 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. Quote Link to comment Share on other sites More sharing options...
bremen1984 Posted May 25, 2011 Author Share Posted May 25, 2011 ok so i have tried to echo out all of it in a textarea but it is not working can someone help pleas. Quote Link to comment Share on other sites More sharing options...
Drummin Posted May 25, 2011 Share Posted May 25, 2011 Is the textarea within your $result array? You should be able to see the description by just echoing the line without a textarea. Can you see the "description"? echo '<p>Description: ' . $_result['description'] . '</p>'; Quote Link to comment Share on other sites More sharing options...
bremen1984 Posted May 25, 2011 Author Share Posted May 25, 2011 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>'; } ?> Quote Link to comment Share on other sites More sharing options...
bremen1984 Posted May 25, 2011 Author Share Posted May 25, 2011 never mind i got it using this code thanks. <div style="width: 190px; height: 190px; overflow: auto; padding: 5px"> content in here </div> Quote Link to comment 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.