Jump to content
MakeWebGames

Recommended Posts

Posted

good morning, im having problems with my gangs, iv tried fixing it but dont seem to be getting anywhere!! the problem is that you can create a gang with the same name that someone else has, so i have two gangs with the same name, which, as you can guess is kind of annoying!!

any help will be welcomed as i cant fix it.

thanks

 

<?php
include(DIRNAME(__FILE__) . '/globals.php');

function format($str)
{
if(is_numeric($str))
{
$str = number_format($str);
}
else
{
$str = nl2br($str);
$str = stripslashes($str);
}
return $str;
}

function clean($string)
{
$string = mysql_real_escape_string($string);
$string = htmlspecialchars($string);
return $string;
}

if($ir['money'] < 1000)
{
echo "You don't have enough money. You need \$1,000.";
$h->endpage();
exit;
}
if($ir['gang'])
{
echo "You're already in a gang!";
$h->endpage();
exit;
}
if(isset($_POST['name']))
{
$name = clean($_POST['name']);
$desc = clean($_POST['desc']);
$sql = sprintf("INSERT INTO gangs (gangNAME, gangDESC, gangPREF, gangSUFF, gangMONEY, gangCRYSTALS, gangRESPECT, gangPRESIDENT, gangVICEPRES, gangCAPACITY) VALUES ('%s', '%s', '', '', 0, 0, 100, %u, %u, 5)", $name, $desc, $userid, $userid);
$db->query($sql);
$i = $db->insert_id();
$gang = sprintf("UPDATE users SET gang = %u, money = money - 1000 WHERE (userid = %u)", $i, $userid);
$db->query($gang);
echo "Gang created!";
}
else
{
echo "<h3>Create A Gang</h3>";
echo "<form action='creategang.php' method='post'>";
echo "<input type='hidden' name='submit' value='1' />";
echo "Name:<input type='text' name='name' />
";
echo "Description:
";
echo "<textarea name='desc' cols='40' rows='7'></textarea>";
echo "
<input type='submit' value='Create Gang for \$1,000' />";
echo "</form>";
}
$h->endpage();
?>

Posted

Re: Gangs with same names

$dumbcheck = mysql_query("SELECT `gangNAME` FROM `gangs` WHERE `gangNAME` = '{$name}'");

if (mysql_num_rows($dumbcheck))

{ echo "no dupped gang names"; exit }

try something along these lines and it might do the trick, place inside the if(isset($_POST['name']))

Posted

Re: Gangs with same names

ok haven't been able to get on for a few days, but still no luck, the way you posted wouldnt let me create any gangs!! heres what i got, its like it wont check !!

 

<?php
include(DIRNAME(__FILE__) . '/globals.php');

function format($str)
{
if(is_numeric($str))
{
$str = number_format($str);
}
else
{
$str = nl2br($str);
$str = stripslashes($str);
}
return $str;
}

function clean($string)
{
$string = mysql_real_escape_string($string);
$string = htmlspecialchars($string);
return $string;
}

if($ir['money'] < 1000)
{
echo "You don't have enough money. You need \$1,000.";
$h->endpage();
exit;
}
if($ir['gang'])
{
echo "You're already in a gang!";
$h->endpage();
exit;
}
if(isset($_POST['name']))
{
$check=$db->query("SELECT `gangNAME` FROM `gangs` WHERE `gangNAME` = '{$name}'");
if($db->num_rows($check))
{
print "ERROR.

[url='creategang.php']> Back[/url]";
$h->endpage();
exit;
}

$name = clean($_POST['name']);
$desc = clean($_POST['desc']);
$sql = sprintf("INSERT INTO gangs (gangNAME, gangDESC, gangPREF, gangSUFF, gangMONEY, gangCRYSTALS, gangRESPECT, gangPRESIDENT, gangVICEPRES, gangCAPACITY) VALUES ('%s', '%s', '', '', 0, 0, 100, %u, %u, 5)", $name, $desc, $userid, $userid);
$db->query($sql);
$i = $db->insert_id();
$gang = sprintf("UPDATE users SET gang = %u, money = money - 1000 WHERE (userid = %u)", $i, $userid);
$db->query($gang);
echo "Gang created!";
}
else
{
echo "<h3>Create A Gang</h3>";
echo "<form action='creategang.php' method='post'>";
echo "<input type='hidden' name='submit' value='1' />";
echo "Name:<input type='text' name='name' />
";
echo "Description:
";
echo "<textarea name='desc' cols='40' rows='7'></textarea>";
echo "
<input type='submit' value='Create Gang for \$1,000' />";
echo "</form>";
}
$h->endpage();
?>
Posted

Re: Gangs with same names

because you put the code in wrong place......Look at the code...

put the code AFTER

$name = clean($_POST['name']);

$desc = clean($_POST['desc']);

 

Why would you put it above that? The code is using $name. So obviously it has to be after where the variable is set.

Posted

Re: Gangs with same names

iv tried here, there and everywhere lol even putting it after the :

$name = clean($_POST['name']);

$desc = clean($_POST['desc']);

it returns "no duupped gang names"

Posted

Re: Gangs with same names

Does that work ?

 

<?php
include(DIRNAME(__FILE__) . '/globals.php');

function format($str)
{
if(is_numeric($str))
{
$str = number_format($str);
}
else
{
$str = nl2br($str);
$str = stripslashes($str);
}
return $str;
}

function clean($string)
{
$string = mysql_real_escape_string($string);
$string = htmlspecialchars($string);
return $string;
}

if($ir['money'] < 1000)
{
echo "You don't have enough money. You need \$1,000.";
$h->endpage();
exit;
}
if($ir['gang'])
{
echo "You're already in a gang!";
$h->endpage();
exit;
}
if(isset($_POST['name']))
{
$check=$db->query(sprintf("SELECT `gangNAME` FROM `gangs` WHERE `gangNAME` = '%s'", clean($_POST['name'])));
if($db->num_rows($check))
{
print "ERROR.

[url='creategang.php']> Back[/url]";
$h->endpage();
exit;
}

$name = clean($_POST['name']);
$desc = clean($_POST['desc']);
$sql = sprintf("INSERT INTO gangs (gangNAME, gangDESC, gangPREF, gangSUFF, gangMONEY, gangCRYSTALS, gangRESPECT, gangPRESIDENT, gangVICEPRES, gangCAPACITY) VALUES ('%s', '%s', '', '', 0, 0, 100, %u, %u, 5)", $name, $desc, $userid, $userid);
$db->query($sql);
$i = $db->insert_id();
$gang = sprintf("UPDATE users SET gang = %u, money = money - 1000 WHERE (userid = %u)", $i, $userid);
$db->query($gang);
echo "Gang created!";
}
else
{
echo "<h3>Create A Gang</h3>";
echo "<form action='creategang.php' method='post'>";
echo "<input type='hidden' name='submit' value='1' />";
echo "Name:<input type='text' name='name' />
";
echo "Description:
";
echo "<textarea name='desc' cols='40' rows='7'></textarea>";
echo "
<input type='submit' value='Create Gang for \$1,000' />";
echo "</form>";
}
$h->endpage();
?>
Posted

Re: Gangs with same names

 

because you put the code in wrong place......Look at the code...

put the code AFTER

$name = clean($_POST['name']);

$desc = clean($_POST['desc']);

 

Why would you put it above that? The code is using $name. So obviously it has to be after where the variable is set.

yeah but you told me to put it after that, which i tried, didnt work, josh put it before and wow, it worked. but thanks for your input.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...