I think that 'SET' is only used when updating a record - I may be wrong though. $sql = "insert into results set username = \"" . addslashes(strip_tags(htmlspecialchars($_POST["username"]))) . "\", whattime = \"" . time() . "\""; PHP: I replaced the statement with this: $sql = "insert into results (username,whattime) VALUES ('" . mysql_real_escape_string($_POST["username"]) . "','" . time() . "')"; PHP: I also put some more error checking in so you can see where the error comes from. Brew
Using SET on insert's is valid and extremely useful, the insert string is far easier to read and debug. Try it sometime. Thanks for putting in some debug although I notice you removed my cleansing of the $_POST["username"], I always scrub clean anything a user sends
YOU ARE A GOD. It WORKS! One final question how can I arrange the list so that the latest entry appears at the bottom of the list and the earliest at the top? oh and how do I delete all the current usernames because they were used just for testing I will use all the links (of your company etc) in the website. Thank you
I'll try it! Thanks for the tip. Have a look at the function mysql_real_escape_string - you may find it is a better alternative than add_slashes. Brew
heh heh - GOD, that is a promotion This will reverse your results, not sure it is the most efficient way but it works... if ($_POST["action"] == "record_time") { $sql = "insert into results set username = \"" . addslashes(strip_tags(htmlspecialchars($_POST["username"]))) . "\", whattime = \"" . time() . "\""; $update = mysql_query($sql); echo "<br><br>"; echo "Thank you " . addslashes(strip_tags(htmlspecialchars($_POST["username"]))) . " we have recorded your result."; echo "<br><br>"; echo "Please <a href=\"record.php\"></a>click here</a> to see the latest results"; } else { $get_res = mysql_query("select * from results order by whattime desc limit 10"); $backloop = mysql_num_rows($get_res); if ($backloop > 0) { echo "<table>"; echo "<th>Username</th>"; echo "<th>Date & Time</th>"; for($i=$backloop-1;$i>=0;$i--) { echo "<tr>"; echo "<td>" . mysql_result($get_res,$i,1) . "</td>"; echo "<td>" . date("d/m/Y H:i",mysql_result($get_res,$i,2)) . "</td>"; echo "</tr>"; } #while ($row = mysql_fetch_array($get_res)) { # $resarray[] = "<tr>"; # echo "<td>" . $row["username"] . "</td>"; # echo "<td>" . date("d/m/Y H:i",$row["whattime"]) . "</td>"; # echo "</tr>"; #} echo "</table>"; } else { echo "No results to show"; } } PHP:
It works but there is a small problem with this, each time a new entry is added, the top (earliest) entry is erased. The purpose should be to keep just the 10 best times, earliest at the top, later entries should not be at the top 10. for example the database has currently stored 20 entries. Only the top 10 (earliest) should appear. Is there a way to show just the 10 earliest times? Thank you
I must buy you a present for all your great help. It is working perfectly. Thank you, Thank you, Thank you!