andyt_2005 Posted June 16, 2009 Posted June 16, 2009 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(); ?> Quote
Lithium Posted June 16, 2009 Posted June 16, 2009 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'])) Quote
andyt_2005 Posted June 16, 2009 Author Posted June 16, 2009 Re: Gangs with same names :) thank you, this has been on my mind all day ! Quote
andyt_2005 Posted June 20, 2009 Author Posted June 20, 2009 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(); ?> Quote
AlabamaHit Posted June 20, 2009 Posted June 20, 2009 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. Quote
andyt_2005 Posted June 21, 2009 Author Posted June 21, 2009 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" Quote
Josh23 Posted June 24, 2009 Posted June 24, 2009 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(); ?> Quote
andyt_2005 Posted June 24, 2009 Author Posted June 24, 2009 Re: Gangs with same names +1 josh thank you very much !! Quote
AlabamaHit Posted June 24, 2009 Posted June 24, 2009 Re: Gangs with same names LMAO omg that was the exact same thing that Lithium and I was telling him to do. Guess he just wanted someoen to add it for him. Quote
andyt_2005 Posted June 24, 2009 Author Posted June 24, 2009 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. Quote
AlabamaHit Posted June 24, 2009 Posted June 24, 2009 Re: Gangs with same names I said after becaue he used the $name varible. Now. He put before. because he used $_POST['name'] Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.