If a user creates a group and that group doesn’t exist, then create that group; but if it already exists, send a message saying so.
This my code. It inserts into my database but cannot check if a group already exists.
<?php
mysql_connect('localhost','root','');
mysql_select_db('test');
$result = mysql_query('SELECT * FROM groups WHERE name!="'.misc::escape($_POST['name']).'"');
if(mysql_num_rows($result) == 0)
{
$sql="INSERT INTO groups(name) VALUES ('$_POST[name]')";
mysql_query($sql);
$select_result=mysql_query("SELECT * FROM groups WHERE name='$_POST[name]' ");
$row = mysql_fetch_assoc($select_result);
echo($row['id']);
}
else
{
echo("this group exist");
}
?>
You can use mysql_num_rows to count the number of rows returned by a query: