npsari Posted March 21, 2007 Share Posted March 21, 2007 How can I make each user submit into the database at least after another 2 users do So, if a user ads his reply at a certain time, he cannot reply again unless 2 other people reply Anyone know how This is the code I currently use <? $con = mysql_connect("localhost","name","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("shyness_other", $con); $query="INSERT INTO story (username, reply) VALUES ('$username', '$reply')"; $result=mysql_query($query,$con) or die("error:".mysql_error()); if(mysql_affected_rows($con)>0){ echo "data has been inserted sucessfully!" ; }else{ echo "failed to insert data!" ; } mysql_close($con); ?> Does anyone know the extra bit I need to add Link to comment https://forums.phpfreaks.com/topic/43589-user-submit-into-the-database-at-least-after-another-2-users-do/ Share on other sites More sharing options...
per1os Posted March 21, 2007 Share Posted March 21, 2007 <?php $con = mysql_connect("localhost","name","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("shyness_other", $con); $query = "SELECT username FROM story WHERE reply = '".$reply."' ORDER BY reply LIMIT 2"; $result=mysql_query($query,$con) or die("error:".mysql_error()); while ($row = mysql_fetch_array($result)) { if ($username == $row['username']) die("You just replied, please wait"); } $query="INSERT INTO story (username, reply) VALUES ('$username', '$reply')"; $result=mysql_query($query,$con) or die("error:".mysql_error()); if(mysql_affected_rows($con)>0){ echo "data has been inserted sucessfully!" ; }else{ echo "failed to insert data!" ; } mysql_close($con); ?> That should work as long as reply is the unique id. But yea that is the concept either way. Link to comment https://forums.phpfreaks.com/topic/43589-user-submit-into-the-database-at-least-after-another-2-users-do/#findComment-211709 Share on other sites More sharing options...
npsari Posted March 21, 2007 Author Share Posted March 21, 2007 I like the part where it says: you just replied, please wait I will try it now, I hope it works Link to comment https://forums.phpfreaks.com/topic/43589-user-submit-into-the-database-at-least-after-another-2-users-do/#findComment-211715 Share on other sites More sharing options...
npsari Posted March 21, 2007 Author Share Posted March 21, 2007 I didn't work actually It kept adding data continuosly even for the same usernames this is the real code I am dealing with: mysql_select_db("shyness_other", $con); $query="INSERT INTO story (name, title, body) VALUES ('$name', 'story1', '$body')"; $result=mysql_query($query,$con) or die("error:".mysql_error()); if(mysql_affected_rows($con)>0){ echo Your story was submitted successfully; }else{ echo "failed to insert data!" ; } mysql_close($con); Any ideas what should i do deferently to the code which will allow a user to submit after two other people Link to comment https://forums.phpfreaks.com/topic/43589-user-submit-into-the-database-at-least-after-another-2-users-do/#findComment-211724 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.