PDA

View Full Version : Small problem at mafia script!


nasir91
04-06-2008, 03:12 PM
Hello, my business.php isnt working properly, it gives me these errors.


Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/beaclan/public_html/game/buisness.php on line 49

It says same error in line 7 too!


It says error in line 7:
$secondcheck = mysql_num_rows(mysql_query("SELECT * FROM buisnesses WHERE owner='$username'"));


and line 49:
$secondcheck = mysql_num_rows(mysql_query("SELECT * FROM buisnesses WHERE owner='$username'"));



Whole snippet:
<?
session_start();
include "includes/functions.php";
logincheck();
$username=$_SESSION['username'];
include "includes/db_connect.php";
$secondcheck = mysql_num_rows(mysql_query("SELECT * FROM buisnesses WHERE owner='$username'"));
if ($secondcheck != "0"){
require_once "buisness/shopCP.php";
exit();
}elseif ($secondcheck == "0"){

$fetch=mysql_fetch_object(mysql_query("SELECT * FROM users WHERE username='$username'"));

if (strip_tags($_POST['submit'])){
$color1 = strip_tags($_POST['color1']);
$color2=strip_tags($_POST['color2']);
$name=strip_tags($_POST['name']);
$logo = strip_tags($_POST['logo']);
$slogan=strip_tags($_POST['slogan']);

if ($slogan =="" || $logo =="" || $name =="" || $color2 =="" || $color1 ==""){
echo "You need to enter all the information. You missed out:<p>";
if ($slogan ==""){
echo "Your companies slogan<br>";
}
if ($logo ==""){
echo "Your companies logo<br>";
}
if ($name ==""){
echo "You companies name<br>";
}
}else{
if ($size == "1"){
$price = "10000";
}elseif ($size == "2"){
$price= "200000";
}elseif ($size == "3"){
$price= "400000";
}elseif ($size == "4"){
$price= "1000000";
}elseif ($size == "5"){
$price= "2000000";
}
$price = $price + 10000;
if ($fetch->money < $price){
echo "You dont have enough money";
}elseif ($fetch->money >= $price){
$secondcheck = mysql_num_rows(mysql_query("SELECT * FROM buisnesses WHERE owner='$username'"));
if ($secondcheck == "0"){


mysql_query*("UPDATE users SET money=money-$price WHERE username='$username'");

echo "Success you can now start making money.";
mysql_query("INSERT INTO `buisnesses` ( `id` , `owner` , `size` , `profit` , `slogan` , `logo` , `color1` , `color2` )
VALUES (
'', '$username', '$size', '0', '$slogan', '$logo', '$color1', '$color2'
)");

}}}}
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<?php echo "$style"; ?>
<body>
<table width="48%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="<?php echo "$td_border"; ?>" bgcolor="<?php echo "$td_bg"; ?>">
<tr>
<td background =<?php echo "$gradient"; ?>><center class=TableHeading>Downtown</center></td>
</tr>
<tr class=title>
<td height="209" colspan=2><div align=center><img src="images/business.jpg" width="300" height="286"></div></td>
</tr>
<tr>
<td height="80">I thought I would see you here soon, welcome to the richest and cleanest part of <?php echo "$fetch->location"; ?>,
this is the place where the wealthy peoples walk. As I can see, you have a desire to start a business. Well, it's hard to start your own
business and keep it going, you need to buy an apartment, but be sure that this will include an investment. From everything came nothing and vice versa!.</td>
</tr>
</table>
<br>
<form name="form1" method="post" action="">
<table width="58%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="<?php echo "$td_border"; ?>" bgcolor="<?php echo "$td_bg"; ?>">
<tr>
<td background=<?php echo "$gradient"; ?>><center class=Tableheading>
Starting up a business</center></td>
</tr>
<tr>
<td><table width="100%" height="162" border="0" cellpadding="0" cellspacing="3">
<tr>
<td width="55%">Company name:</td>
<td width="45%"><input name="name" type="text" id="name2"></td>
</tr>
<tr>
<td>Shop size:</td>
<td><select name="size" id="select">
<option value="1">Small house-&pound;10,000</option>
<option value="2">Large house-&pound;200,000</option>
<option value="3">Small office-&pound;400,000</option>
<option value="4">Large office-&pound;1,000,000</option>
<option value="5">Huge office-&pound;2,000,000</option>
</select> </td>
</tr>
<tr>
<td>Company slogan:</td>
<td><input name="slogan" type="text" id="slogan2"></td>
</tr>
<tr>
<td>Company logo:</td>
<td><input name="logo" type="text" id="logo2"></td>
</tr>
<tr>
<td>Company color scheme:</td>
<td><input name="color1" type="text" id="color1"></td>
</tr>
<tr>
<td>Company color scheme 2:</td>
<td><input name="color2" type="text" id="color2"></td>
</tr>
<tr>
<td>Note: <font color="#FF0000">theres is a &pound;10,000 setup fee</font>
<u>Not inc size.</u></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><div align="right">
<input name="submit" type="submit" id="submit" value="Create company">
</div></td>
</tr>
</table></td>
</tr>
</table>
</form>
<br>
<br>
</body>
</html><?php } ?>

abduraooft
04-06-2008, 03:38 PM
Try
$secondcheck = mysql_num_rows(mysql_query("SELECT * FROM buisnesses WHERE owner='$username'")) or die(mysql_error());
...it is your responsibility to die() if necessary.

mjlorbet
04-06-2008, 04:04 PM
hahah, that's a great quote!
also, if you keep getting this mystery error, try businesses instead of buisnesses as you have it written, typos will getcha if you don't keep them consistent. or

$secondcheck = mysql_num_rows(mysql_query("SELECT * FROM buisnesses WHERE owner='".$username."'"))

again, use the try/die method, it's a section than can/will cause errors eventually, just better to handle said errors than not to

nasir91
04-06-2008, 04:10 PM
Now I get this:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/beaclan/public_html/game/buisness.php on line 7
Table 'beaclan_mafia.buisnesses' doesn't exist

nasir91
04-06-2008, 04:11 PM
Check it at: www.beaclan.com/game

You guys are really helpful, thanks!

mjlorbet
04-06-2008, 04:36 PM
good stuff man, might be nice if you could train more than once in the first 10 minutes though, i've got a 1% chance of stealing from a small child & no chance to do anything else. :)

abduraooft
04-06-2008, 04:50 PM
Have you put the die statements ?
$secondcheck = mysql_num_rows(mysql_query("SELECT * FROM buisnesses WHERE owner='$username'")) or die(mysql_error());

mjlorbet
04-06-2008, 05:00 PM
$secondcheck = mysql_num_rows(mysql_query("SELECT * FROM buisnesses WHERE owner='$username'") or die(-1)) or die(-1)