deets52 Posted January 15, 2010 Share Posted January 15, 2010 Hello, first off I am not an expert by any means, so this question might be a little too simple (as well as the code included). Here is the background. I am trying to put a simple feedback form on my website. I am doing 'INSERT INTO' SQL calls to store the name, email, text and date (native DB date function/row). $getname = htmlentities($_POST['name']); $getmail = htmlentities($_POST['email']); $gettext = htmlentities($_POST['feedback']); mysql_query("INSERT INTO comnt (name, email, text) VALUES( '$getname', '$getmail', '$gettext') ") or die(mysql_error()); I can look in the db and see that it is getting put in there with no problems. So, this part is working. The part that is the issue is getting the data back out of the db. For the more part I am getting back data, just not the last entry. Here is how I am getting the data back out. $result = mysql_query("SELECT name, date, email, text FROM comnt ORDER BY date desc") or die(mysql_error()); So, I have run this 8 times. The db looks like test1 test1@localhost This is a test test2 test2@localhost This is a test ... test8 test8@localhost This is a test When I go to the db and do the query I get back all 8 rows. When I do the query from the db I only get back 7 rows (7 - 1) back. If I add another row with test9 I get back 8 rows (8 - 1). If I leave the ORDER BY off I get back the same, only the last rows (2 -. Once again, I see all of them in the db. So far, I have tried removing the AI row I had to sort these out. Also, I have made several changes (replacing * with the fields, etc) to the query to try to get it working. Below is the info for my system. Please help, I don't have much more hair to pull out! Apache/2.2.11 (Ubuntu) PHP/5.2.6-3ubuntu4.4 with Suhosin-Patch mod_perl/2.0.4 Perl/v5.10.0 MySQL client version: 5.0.75 PHP extension: mysqli MySQL charset: UTF-8 Unicode (utf8) CREATE TABLE `comnt` ( `date` timestamp NOT NULL default CURRENT_TIMESTAMP, `name` text NOT NULL, `email` varchar(42) NOT NULL, `text` text NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 Link to comment https://forums.phpfreaks.com/topic/188609-mysql-select-statement-issues/ Share on other sites More sharing options...
trq Posted January 15, 2010 Share Posted January 15, 2010 Post your code that loops through your results, its likely your calling mysql_fetch_* prior to initializing the loop. Link to comment https://forums.phpfreaks.com/topic/188609-mysql-select-statement-issues/#findComment-995800 Share on other sites More sharing options...
deets52 Posted January 16, 2010 Author Share Posted January 16, 2010 Thanks for looking at this. Here is the code. In here I have that the db is NOT being closed and that the order is done on the date field. The original script was not like that, this was done during troubleshooting this issue. I even built a new db to test with. $conn= mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error()); // Connect to the comments table mysql_select_db($dbname) or die(mysql_error()); // echo "Connected to Database<br />"; $result = mysql_query("SELECT name, date, email, text FROM comnt ORDER BY date desc") or die(mysql_error()); // store the record of the "feedback" table into $row $row = mysql_fetch_array($result); // Print out the contents of the entry while($row = mysql_fetch_array($result)) { echo "<table class=\"fbtable\" RULES=NONE FRAME=BOX>"; echo "<tr><th class=\"header1\" width=60%>". $row['name']. "</th><th class=\"header2\">". $row['date']. "</th></tr>"; echo "<tr colspan=2><td class=\"text1\" colspan=2>". $row['text']. "</td></tr></table><br />"; } //Close up the db and clean up after yourself //clear memory mysql_free_result($result); Link to comment https://forums.phpfreaks.com/topic/188609-mysql-select-statement-issues/#findComment-995968 Share on other sites More sharing options...
trq Posted January 16, 2010 Share Posted January 16, 2010 Remove these lines..... // store the record of the "feedback" table into $row $row = mysql_fetch_array($result); Link to comment https://forums.phpfreaks.com/topic/188609-mysql-select-statement-issues/#findComment-995969 Share on other sites More sharing options...
deets52 Posted January 16, 2010 Author Share Posted January 16, 2010 That did it! I can't believe that I overlooked that. This can be marks as solved. Once again Thorpe, thanks for your help in this. Link to comment https://forums.phpfreaks.com/topic/188609-mysql-select-statement-issues/#findComment-996091 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.