Jump to content

user submit into the database at least after another 2 users do


npsari

Recommended Posts

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

<?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.

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.