MySQL Error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

violentj
Forum Newbie
Posts: 8
Joined: Thu Mar 27, 2008 5:04 pm

MySQL Error

Post by violentj »

I am having trouble with my mysql setup in the setup.php of my mmorpg script (see below). I have tried to find the error but cannot find out what is wrong!!

my site is virus-mafia.com

my MySQL data,

username=<Removed by mod>
pass=<Removed by mod>
name=<Removed by mod>

This is the script im having problems with.

ANY HELP WOULD BE GREATLY APPRECIATED

If u can get it sorted i have a spare script too 8)

Code: Select all

 
<?
$time=time();
 
 
$site[location] = 'http://www.virus-mafia.com/'; ///SITE LOCATION
$site[img] = 'http://virus-mafia.com/images/';   ///SITE IMAGES
 
 
$dir="../images/icons/$tru/";
$arr_allow_ex=array("gif","jpg","png");
$maxupload[sup] = '5000'; //supporter upload in bytes
$maxupload[nor] = '2500'; //normal upload in bytes
 
 
$db[host] = 'insert';      //DATABASE HOST "mysql4.namesco.net"
$db[user] = 'insert';    //DATABASE USERNAME
$db[pass] = 'insert';        //DATABASE PASSWORD
$db[name] = 'insert';   //DATABASE NAME
 
$connect = mysql_connect($db[host],$db[user], $db[pass]);
mysql_select_db("$db[name]") or die ("Could not connect to database");
 
$tab[user] = 'users';
$tab[html] = 'html';
$tab[news] = 'news';
$tab[game] = 'games';
$tab[stat] = 'stats';
$tab[censor] = 'censors';
$tab[banned] = 'bans';
$tab[paypal] = 'paypal';
 
 
$tab[board] = "board";
$tab[clist] = "contacts";
$tab[city] = "city";
$tab[crew] = "crew";
$tab[invite] = "invites";
$tab[mail] = "mailbox";
$tab[pimp] = "pimp";
$tab[revenge] = "revenges";
$tab[cron] = "cronjobs";
 
if(($tru) && (!mysql_fetch_row(mysql_query("SELECT round FROM $tab[game] WHERE round='$tru' AND starts<$time AND ends>$time;"))))
  { header("Location: $site[location]play.php"); }
 
if($tru){
  $tab[board] = "r".$tru."_board";
  $tab[clist] = "r".$tru."_contacts";
   $tab[city] = "r".$tru."_city";
   $tab[crew] = "r".$tru."_crew";
 $tab[invite] = "r".$tru."_invites";
   $tab[mail] = "r".$tru."_mailbox";
   $tab[pimp] = "r".$tru."_$tab[pimp]";
$tab[revenge] = "r".$tru."_revenges";
   $tab[cron] = "r".$tru."_cronjobs";
 
}
 
$getcensors = mysql_query("SELECT censor FROM $tab[censor];");
$censorwords = array();
while($censor=mysql_fetch_array($getcensors)) {
  array_push($censorwords, $censor[0]);
}
 
if($tru){ $id = mysql_fetch_array(mysql_query("SELECT id FROM $tab[pimp] WHERE code='$trupimpn';")); }
    else{ $id = mysql_fetch_array(mysql_query("SELECT id FROM $tab[user] WHERE code='$trupimp';")); }
$id=$id[0];
?>
 
Hawleyjr: Username & Password Removed. Please use PHP tags when posting.
Last edited by violentj on Fri Mar 28, 2008 12:01 pm, edited 1 time in total.
User avatar
EverLearning
Forum Contributor
Posts: 282
Joined: Sat Feb 23, 2008 3:49 am
Location: Niš, Serbia

Re: MySQL Error

Post by EverLearning »

In your SQL statement you have array elements in a double quoted string. You can't access them with

Code: Select all

"... $tab[game] ..."
,
since interpreter will only resolve the '$tab' part and $tab is an array.

Put curly braces around them, and your statement should work. And I suggest you put quotes around the array keys

Code: Select all

"... {$tab['game']} ..."
.

You should've echoed the SQL statement, it would've shown you whats wrong with your statement values. Also use mysql_error() to show you error MySql server returned.
kryles
Forum Contributor
Posts: 114
Joined: Fri Feb 01, 2008 7:52 am

Re: MySQL Error

Post by kryles »

I hope the Mod also removed the host/user/password information from the PHP code also 8O
violentj
Forum Newbie
Posts: 8
Joined: Thu Mar 27, 2008 5:04 pm

Re: MySQL Error

Post by violentj »

Ok now i have edited it and am now getting this error message,

Parse error: syntax error, unexpected T_STRING, expecting '}' in /www/110mb.com/v/i/o/l/e/n/t/j/violentj/htdocs/setup.php on line 45

again ive tried looking to see wtf is wrong but i cant find out! :banghead: ive tried backslashing but that dont work, and i dont fully understand the echoing thing :cry:

Code: Select all

<?
//Good ol' time
$time=time();
 
//////PRETTY SIMPLE, MAKE SURE URL LOCATIONS END WITH "/"
$site[location] = 'http://violentj.110mb.com/'; ///SITE LOCATION
$site[img] = 'http://virus-mafia.com/images/';   ///SITE IMAGES
 
//////UPLOAD SETTINGS
$dir="../images/icons/$tru/";
$arr_allow_ex=array("gif","jpg","png");
$maxupload[sup] = '5000'; //supporter upload in bytes
$maxupload[nor] = '2500'; //normal upload in bytes
 
//////DATABASE CONFIG, AND CONNECTION
$db[host] = 'insert';      //DATABASE HOST "mysql4.namesco.net"
$db[user] = 'insert';    //DATABASE USERNAME
$db[pass] = 'insert';        //DATABASE PASSWORD
$db[name] = 'insert';   //DATABASE NAME
 
$connect = mysql_connect($db[host],$db[user], $db[pass]);
mysql_select_db("$db[name]") or die ("Could not connect to database");
 
//////DATABASE TABLES
$tab[user] = 'users';
$tab[html] = 'html';
$tab[news] = 'news';
$tab[game] = 'games';
$tab[stat] = 'stats';
$tab[censor] = 'censors';
$tab[banned] = 'bans';
$tab[paypal] = 'paypal';
 
/////GAME DATABASE TABLES
$tab[board] = "board";
$tab[clist] = "contacts";
$tab[city] = "city";
$tab[crew] = "crew";
$tab[invite] = "invites";
$tab[mail] = "mailbox";
$tab[pimp] = "pimp";
$tab[revenge] = "revenges";
$tab[cron] = "cronjobs";
 
if(($tru) && (!mysql_fetch_row(mysql_query("SELECT round FROM {$tab['game'] WHERE round='$tru' AND starts<$time AND ends>$time;"))))
  { header(/"Location: $site[location]play.php/"); }
 
if($tru){
  $tab[board] = "r".$tru."_board";
  $tab[clist] = "r".$tru."_contacts";
   $tab[city] = "r".$tru."_city";
   $tab[crew] = "r".$tru."_crew";
 $tab[invite] = "r".$tru."_invites";
   $tab[mail] = "r".$tru."_mailbox";
   $tab[pimp] = "r".$tru."_$tab[pimp]";
$tab[revenge] = "r".$tru."_revenges";
   $tab[cron] = "r".$tru."_cronjobs";
 
}
 
//////CENSORS
$getcensors = mysql_query("SELECT censor FROM $tab[censor];");
$censorwords = array();
while($censor=mysql_fetch_array($getcensors)) {
  array_push($censorwords, $censor[0]);
}
 
//GRAB THEY MASTER AND GAME ID
if($tru){ $id = mysql_fetch_array(mysql_query("SELECT id FROM $tab[pimp] WHERE code='$trupimpn';")); }
    else{ $id = mysql_fetch_array(mysql_query("SELECT id FROM $tab[user] WHERE code='$trupimp';")); }
$id=$id[0];
?>
 
User avatar
EverLearning
Forum Contributor
Posts: 282
Joined: Sat Feb 23, 2008 3:49 am
Location: Niš, Serbia

Re: MySQL Error

Post by EverLearning »

This is what I see at a glance, maybe there are more errors:

1. you forgot the closing curly brace around $tab['game'](as much is said in the error message you got)
2. you also have '/' sign in the next line which has no place there, and would cause php interpreter to throw a syntax error if you already didn't have one
3. $site[location] in the 46. line should also be enclosed in curly braces

Correct code should be:

Code: Select all

 
if(($tru) && (!mysql_fetch_row(mysql_query("SELECT round FROM {$tab['game']} WHERE round='$tru' AND starts<$time AND ends>$time;"))))
  { header("Location: {$site[location]}play.php/"); }
 
violentj
Forum Newbie
Posts: 8
Joined: Thu Mar 27, 2008 5:04 pm

Re: MySQL Error

Post by violentj »

I have now encountered the following error but my MySQL statement (im sure) are correct (unless its me being naive)

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /content/StartupHostPlus/v/i/virus-mafia.com/web/setup.php on line 63

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /content/StartupHostPlus/v/i/virus-mafia.com/web/setup.php on line 69

Code: Select all

 
<?
 
$time=time();
 
$site[location] = 'http://virus-mafia.com/'; ///SITE LOCATION
$site[img] = 'http://virus-mafia.com/images/';   ///SITE IMAGES
 
////UPLOAD SETTINGS
$dir="../images/icons/$tru/";
$arr_allow_ex=array("gif","jpg","png");
$maxupload[sup] = '5000'; //supporter upload in bytes
$maxupload[nor] = '2500'; //normal upload in bytes
 
//////DATABASE CONFIG, AND CONNECTION
$db[host] = '***';      //DATABASE HOST "mysql4.namesco.net"
$db[user] = '***';    //DATABASE USERNAME
$db[pass] = '***';        //DATABASE PASSWORD
$db[name] = '***';   //DATABASE NAME
 
$connect = mysql_connect($db[host],$db[user], $db[pass]);
mysql_select_db("$db[name]") or die ("Could not connect to database");
 
//////DATABASE TABLES
$tab[user] = 'users';
$tab[html] = 'html';
$tab[news] = 'news';
$tab[game] = 'games';
$tab[stat] = 'stats';
$tab[censor] = 'censors';
$tab[banned] = 'bans';
$tab[paypal] = 'paypal';
 
/////GAME DATABASE TABLES
$tab[board] = "board";
$tab[clist] = "contacts";
$tab[city] = "city";
$tab[crew] = "crew";
$tab[invite] = "invites";
$tab[mail] = "mailbox";
$tab[pimp] = "pimp";
$tab[revenge] = "revenges";
$tab[cron] = "cronjobs";
 
if(($tru) && (!mysql_fetch_row(mysql_query("SELECT round FROM {$tab['game']} WHERE round='$tru' AND starts<$time AND ends>$time;")))) { header("Location: {$site[location]}play.php/"); }
 
 
if($tru){
  $tab[board] = "r".$tru."_board";
  $tab[clist] = "r".$tru."_contacts";
   $tab[city] = "r".$tru."_city";
   $tab[crew] = "r".$tru."_crew";
 $tab[invite] = "r".$tru."_invites";
   $tab[mail] = "r".$tru."_mailbox";
   $tab[pimp] = "r".$tru."_$tab[pimp]";
$tab[revenge] = "r".$tru."_revenges";
   $tab[cron] = "r".$tru."_cronjobs";
 
}
 
//////CENSORS
$getcensors = mysql_query("SELECT censor FROM $tab[censor];");
$censorwords = array();
while($censor=mysql_fetch_array($getcensors)) {
  array_push($censorwords, $censor[0]);
}
 
//GRAB THEY MASTER AND GAME ID
if($tru){ $id = mysql_fetch_array(mysql_query("SELECT id FROM $tab[pimp] WHERE code='$trupimpn';")); }
    else{ $id = mysql_fetch_array(mysql_query("SELECT id FROM $tab[user] WHERE code='$trupimp';")); }
$id=$id[0];
?>
 
plz tell me if there is a fault, as ive checked it several time and again cant find anything wrong!
Last edited by violentj on Sat Mar 29, 2008 4:41 pm, edited 1 time in total.
User avatar
EverLearning
Forum Contributor
Posts: 282
Joined: Sat Feb 23, 2008 3:49 am
Location: Niš, Serbia

Re: MySQL Error

Post by EverLearning »

Curly braces. AGAIN. :roll:
violentj
Forum Newbie
Posts: 8
Joined: Thu Mar 27, 2008 5:04 pm

Re: MySQL Error

Post by violentj »

ive put them there havent i?!
User avatar
EverLearning
Forum Contributor
Posts: 282
Joined: Sat Feb 23, 2008 3:49 am
Location: Niš, Serbia

Re: MySQL Error

Post by EverLearning »

Code: Select all

 
//////CENSORS
$getcensors = mysql_query("SELECT censor FROM $tab[censor];");
$censorwords = array();
while($censor=mysql_fetch_array($getcensors)) {
  array_push($censorwords, $censor[0]);
}
 
//GRAB THEY MASTER AND GAME ID
if($tru){ $id = mysql_fetch_array(mysql_query("SELECT id FROM $tab[pimp] WHERE code='$trupimpn';")); }
    else{ $id = mysql_fetch_array(mysql_query("SELECT id FROM $tab[user] WHERE code='$trupimp';")); }
$id=$id[0];
Where are curly braces in this code?
violentj
Forum Newbie
Posts: 8
Joined: Thu Mar 27, 2008 5:04 pm

Re: MySQL Error

Post by violentj »

wat?

Code: Select all

//////CENSORS
$getcensors = mysql_query("SELECT censor FROM $tab[censor];");
$censorwords = array();
while($censor=mysql_fetch_array($getcensors)) {
  array_push($censorwords, $censor[0]);
}
 
//GRAB THEY MASTER AND GAME ID
if($tru){ $id = mysql_fetch_array(mysql_query("SELECT id FROM $tab[pimp] WHERE code='$trupimpn';")); }
    else{ $id = mysql_fetch_array(mysql_query("SELECT id FROM $tab[user] WHERE code='$trupimp';")); }
$id=$id[0];
???
User avatar
EverLearning
Forum Contributor
Posts: 282
Joined: Sat Feb 23, 2008 3:49 am
Location: Niš, Serbia

Re: MySQL Error

Post by EverLearning »

This forum is a place of learning, and you should't expect others to do your work. Sooo... Read my first post and take a look at your SQL statements I quoted in my last post. Everything you need is there.
violentj
Forum Newbie
Posts: 8
Joined: Thu Mar 27, 2008 5:04 pm

Re: MySQL Error

Post by violentj »

ive looked at the cide and tried ti find the error but i cant (that was the point of coming to the forum). thanx anywayz
User avatar
EverLearning
Forum Contributor
Posts: 282
Joined: Sat Feb 23, 2008 3:49 am
Location: Niš, Serbia

Re: MySQL Error

Post by EverLearning »

You need curly braces around array elements in quoted strings.
I already provided examples in previous posts, you just need to go through the WHOLE of your code and apply what I've written above.
violentj
Forum Newbie
Posts: 8
Joined: Thu Mar 27, 2008 5:04 pm

Re: MySQL Error

Post by violentj »

curly braces have made NO difference to the error!

Code: Select all

//////CENSORS
$getcensors = mysql_query("SELECT censor FROM {$tab[censor]};");///this is the line im havin trouble with
$censorwords = array();
while($censor=mysql_fetch_array($getcensors)) {
  array_push($censorwords, $censor[0]);
}
 
//GRAB THEY MASTER AND GAME ID
if($tru){ $id = mysql_fetch_array(mysql_query("SELECT id FROM $tab[pimp] WHERE code='$trupimpn';")); }
    else{ $id = mysql_fetch_array(mysql_query("SELECT id FROM $tab[user] WHERE code='$trupimp';")); }
$id=$id[0];
 
suggestions!
kryles
Forum Contributor
Posts: 114
Joined: Fri Feb 01, 2008 7:52 am

Re: MySQL Error

Post by kryles »

Code: Select all

 
 
<?php
$time=time();
  
  
$site[location] = 'http://www.virus-mafia.com/'; ///SITE LOCATION
$site[img] = 'http://virus-mafia.com/images/';   ///SITE IMAGES
  
  
$dir="../images/icons/$tru/";
$arr_allow_ex=array("gif","jpg","png");
$maxupload[sup] = '5000'; //supporter upload in bytes
$maxupload[nor] = '2500'; //normal upload in bytes
   
$db[host] = 'insert';      //DATABASE HOST "mysql4.namesco.net"
$db[user] = 'insert';    //DATABASE USERNAME
$db[pass] = 'insert';        //DATABASE PASSWORD
$db[name] = 'insert';   //DATABASE NAME
  
$connect = mysql_connect($db[host],$db[user], $db[pass]);
mysql_select_db("$db[name]") or die ("Could not connect to database");
  
$tab[user] = 'users';
$tab[html] = 'html';
$tab[news] = 'news';
$tab[game] = 'games';
$tab[stat] = 'stats';
$tab[censor] = 'censors';
$tab[banned] = 'bans';
$tab[paypal] = 'paypal';
$tab[board] = "board";
$tab[clist] = "contacts";
$tab[city] = "city";
$tab[crew] = "crew";
$tab[invite] = "invites";
$tab[mail] = "mailbox";
$tab[pimp] = "pimp";
$tab[revenge] = "revenges";
$tab[cron] = "cronjobs";
  
if(($tru) && (!mysql_fetch_row(mysql_query("SELECT round FROM {$tab[game]} WHERE round='$tru' AND starts<$time AND ends>$time;"))))
{ header("Location: $site[location]play.php"); }
  
if($tru){
$tab[board] = "r".$tru."_board";
$tab[clist] = "r".$tru."_contacts";
$tab[city] = "r".$tru."_city";
$tab[crew] = "r".$tru."_crew";
$tab[invite] = "r".$tru."_invites";
$tab[mail] = "r".$tru."_mailbox";
$tab[pimp] = "r".$tru."_$tab[pimp]";
$tab[revenge] = "r".$tru."_revenges";
$tab[cron] = "r".$tru."_cronjobs";
}
  
$getcensors = mysql_query("SELECT censor FROM {$tab[censor]};");
$censorwords = array();
while($censor=mysql_fetch_array($getcensors)) {
array_push($censorwords, $censor[0]);
}
 
if($tru){ $id = mysql_fetch_array(mysql_query("SELECT id FROM {$tab[pimp]} WHERE code='$trupimpn';")); }
else{ $id = mysql_fetch_array(mysql_query("SELECT id FROM {$tab[user]} WHERE code='$trupimp';")); }
$id=$id[0];
?>
 
 
try that.
Post Reply