Chaori Posted December 1, 2008 Share Posted December 1, 2008 I'm making an online text based game with a Latitude and Longitude movement system, and I'm quite n00b at PHP so I thought I'd ask here about an error I'm getting. The code below should connect to MySQL, go to the Latitude and Longitude and add 1 to the Longitude. <?php $con = mysql_connect($CONFIG['server_ip'],$CONFIG['database_user'],$CONFIG['database_password']); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql query ("UPDATE characters SET longitude=longitude+'1' WHERE account_id='$accid'"); ?> <meta http-equiv="Refresh"; URL=http://neverbeast.com/valdellaknights/main.php"> But I get the following error: Parse error: syntax error, unexpected T_STRING in /hermes/bosweb/web008/b87/d5.beanonym/public_html/subdomain/Steve/neverbeast.com/valdellaknights/north.php on line 7 If anyone could tell me what's wrong I'd really appreciate it! Thanks in advance. Quote Link to comment Share on other sites More sharing options...
trq Posted December 1, 2008 Share Posted December 1, 2008 Your query is incorrect but should'nt be throwing any php parse error. mysql query ("UPDATE characters SET longitude=longitude+1 WHERE account_id='$accid'"); Quote Link to comment Share on other sites More sharing options...
Chaori Posted December 1, 2008 Author Share Posted December 1, 2008 mysql query ("UPDATE characters SET longitude=longitude+1 WHERE account_id='$accid'"); Doesn't work either. Quote Link to comment Share on other sites More sharing options...
trq Posted December 1, 2008 Share Posted December 1, 2008 Same error? I don't see anything in that code that would throw that error, is there more code? Quote Link to comment Share on other sites More sharing options...
Chaori Posted December 1, 2008 Author Share Posted December 1, 2008 Well I added a close connection, but the final thing is: <?php $con = mysql_connect($CONFIG['server_ip'],$CONFIG['database_user'],$CONFIG['database_password']); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql query ("UPDATE characters SET longitude=longitude+1 WHERE account_id='$accid'"); mysql_close($con); ?> <meta http-equiv="Refresh"; URL=http://neverbeast.com/valdellaknights/main.php"> All of my friends that know PHP can't find anything wrong with it either... It's really weird. *EDIT* $accid is already defined in the page that has the North button on it, so it shouldn't need to be defined again. And yes, same error as above. Quote Link to comment Share on other sites More sharing options...
trq Posted December 1, 2008 Share Posted December 1, 2008 That code doesn't have any syntax errors in it so it shouldn't throw the erros your seeing. It won't work however because the $CONFIG array and $accid variables are not set anywhere. Is there more code? Quote Link to comment Share on other sites More sharing options...
Chaori Posted December 1, 2008 Author Share Posted December 1, 2008 Read my last post's edit. No, no more code. Quote Link to comment Share on other sites More sharing options...
trq Posted December 1, 2008 Share Posted December 1, 2008 Variables are not simply carried from page to page, so if there is no more code in that page $CONFIG and $accid are NOT set anywhere. Even if they where, they would throw a different error, not the one you are getting. Quote Link to comment Share on other sites More sharing options...
Chaori Posted December 1, 2008 Author Share Posted December 1, 2008 Okay thanks, I'll set them anyway and test it. Quote Link to comment Share on other sites More sharing options...
dimond345 Posted December 1, 2008 Share Posted December 1, 2008 Try this: <?php //Will display all errors ini_set("display_errors",1); error_reporting(E_ALL); //!!!---!!! $con = mysql_connect($CONFIG['server_ip'],$CONFIG['database_user'],$CONFIG['database_password']); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_query ("UPDATE characters SET longitude=longitude+'1' WHERE account_id='$accid'"); mysql_close($con); ?> <meta http-equiv="Refresh"; URL=http://neverbeast.com/valdellaknights/main.php"> There was error in php code. Quote Link to comment Share on other sites More sharing options...
Chaori Posted December 1, 2008 Author Share Posted December 1, 2008 Ahhh I think I know! I need to select the table first don't I? Quote Link to comment Share on other sites More sharing options...
trq Posted December 1, 2008 Share Posted December 1, 2008 Yeah, you need to select the database. Did'nt even see that. Still, that does not fix the error you describe. Are you still getting the same error as your first post? Quote Link to comment Share on other sites More sharing options...
Chaori Posted December 1, 2008 Author Share Posted December 1, 2008 Okay, the final code is below: <?php //Will display all errors ini_set("display_errors",1); error_reporting(E_ALL); //!!!---!!! $con = mysql_connect("beanonym.dot5hostingmysql.com","****","****"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db($CONFIG['database'], $con); $accid = GETWHERE("account","account_id","account_name",$user,"0"); mysql query ("UPDATE characters SET longitude=longitude+1 WHERE account_id='$accid'"); mysql_close($con); ?> <meta http-equiv="Refresh"; URL=http://neverbeast.com/valdellaknights/main.php"> And the error message is below: Parse error: syntax error, unexpected T_STRING in /hermes/bosweb/web008/b87/d5.beanonym/public_html/subdomain/Steve/neverbeast.com/valdellaknights/north.php on line 13 edited: Don't post your username / passowrd combinations. Quote Link to comment Share on other sites More sharing options...
trq Posted December 1, 2008 Share Posted December 1, 2008 Where is this GETWHERE function and the $user variable defined? And still that code has no parse errors. Quote Link to comment Share on other sites More sharing options...
Chaori Posted December 1, 2008 Author Share Posted December 1, 2008 My friend has been fiddling around with functions, I'll just ask him when he gets back. Quote Link to comment Share on other sites More sharing options...
dimond345 Posted December 1, 2008 Share Posted December 1, 2008 Did you use Zend to create php code? In previows post and in this post you have problem in mysql query function syntax. you have forgot _ berween mysql and query. your code mysql query ("UPDATE characters SET longitude=longitude+1 WHERE account_id='$accid'"); change it to mysql_query ("UPDATE characters SET longitude=longitude+1 WHERE account_id='$accid'"); Quote Link to comment Share on other sites More sharing options...
Chaori Posted December 1, 2008 Author Share Posted December 1, 2008 Okay I've re-done the whole script. Instead of having four different scripts for North, South, East and West, I've simply made a 'travel.php' in which each button redirects to. <?php $con = mysql_connect("beanonym.dot5hostingmysql.com","*****","******"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("steve", $con); if($POST['north']){ $accid = GETWHERE("account","account_id","account_name",$user,"0"); mysql_query ("UPDATE characters SET longitude=longitude+1 WHERE account_id='$accid'"); } else if($post['west']){ $accid = GETWHERE("account","account_id","account_name",$user,"0"); mysql_query ("UPDATE characters SET latitude=latitude+1 WHERE account_id='$accid'"); } else if($post['east']){ $accid = GETWHERE("account","account_id","account_name",$user,"0"); mysql_query ("UPDATE characters SET latitude=latitude-1 WHERE account_id='$accid'"); } else if($post['south']){ $accid = GETWHERE("account","account_id","account_name",$user,"0"); mysql_query ("UPDATE characters SET longitude=longitude-1 WHERE account_id='$accid'"); } mysql_close($con); header("location: main.php"); ?> And I'm getting the following error: Parse error: syntax error, unexpected T_STRING in /hermes/bosweb/web008/b87/d5.beanonym/public_html/subdomain/Steve/neverbeast.com/valdellaknights/travel.php on line 10 Quote Link to comment Share on other sites More sharing options...
Chaori Posted December 1, 2008 Author Share Posted December 1, 2008 I also have a 'functions.php' which has the following: <?php require_once 'config.php'; function Connect(){ global $CONFIG; $con = mysql_connect($CONFIG['server_ip'],$CONFIG['database_user'],$CONFIG['database_password']) or die("Could not connect to MySQL."); $db = mysql_select_db($CONFIG['database']) or die("Could not select database."); } function ADD($table,$field,$value){ mysql_query("INSERT INTO $table ($field) VALUES ('$value')"); } function UPDATE($table,$field,$value){ mysql_query("UPDATE $table SET $field = '$value'"); } function UPDATEWHERE($table,$field,$value,$where,$whereequals){ mysql_query("UPDATE $table SET $field = '$value' WHERE $where = '$whereequals'"); } function GET($table,$field,$row){ $query = mysql_query("SELECT $field FROM $table"); $data = mysql_fetch_row($query); $return = $data[$row]; return $return; } function GETWHERE($table,$field,$where,$whereequals,$row) { $query = mysql_query("SELECT $field FROM $table WHERE $where ='$whereequals'"); $data = mysql_fetch_row($query); $return = $data[$row]; return $return; } ?> Quote Link to comment Share on other sites More sharing options...
Chaori Posted December 1, 2008 Author Share Posted December 1, 2008 Ignore all that, I fixed it Quote Link to comment Share on other sites More sharing options...
trq Posted December 1, 2008 Share Posted December 1, 2008 Again GETWHERE is not defined anywhere. Niether are the variables $accid or $user and niether is the array $post. Still, these errors will not produce the error you describe. Quote Link to comment Share on other sites More sharing options...
trq Posted December 1, 2008 Share Posted December 1, 2008 So, is it all fixed? Please hit the topic solved button, bottom left. Quote Link to comment Share on other sites More sharing options...
Chaori Posted December 1, 2008 Author Share Posted December 1, 2008 One more thing! <?php require 'functions.php'; connect(); $latitude = GETWHERE("characters","latitude","account_id","$accid","0"); $longitude = GETWHERE("characters","longitude","account_id","$accid","0"); if($POST['north']){ $accid = GETWHERE("account","account_id","character_name",$user,"0"); $longitude +=1; mysql_query ("UPDATE characters SET longitude='$longitude' WHERE account_id='$accid'"); } else if($post['west']){ $accid = GETWHERE("account","account_id","character_name",$user,"0"); $latitude -=1; mysql_query ("UPDATE characters SET latitude='$latitude' WHERE account_id='$accid'"); } else if($post['east']){ $accid = GETWHERE("account","account_id","character_name",$user,"0"); $latitude +=1; mysql_query ("UPDATE characters SET latitude='$latitude' WHERE account_id='$accid'"); } else if($post['south']){ $accid = GETWHERE("account","account_id","character_name",$user,"0"); $longitude -=1; mysql_query ("UPDATE characters SET longitude='$longitude' WHERE account_id='$accid'"); } mysql_close($con); header("location: main.php"); ?> Gets the following errors: Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in /hermes/bosweb/web008/b87/d5.beanonym/public_html/subdomain/Steve/neverbeast.com/valdellaknights/travel.php on line 29 Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosweb/web008/b87/d5.beanonym/public_html/subdomain/Steve/neverbeast.com/valdellaknights/travel.php:29) in /hermes/bosweb/web008/b87/d5.beanonym/public_html/subdomain/Steve/neverbeast.com/valdellaknights/travel.php on line 30 And functions.php is below: <?php require_once 'config.php'; function Connect(){ global $CONFIG; $con = mysql_connect($CONFIG['server_ip'],$CONFIG['database_user'],$CONFIG['database_password']) or die("Could not connect to MySQL."); $db = mysql_select_db($CONFIG['database']) or die("Could not select database."); } function ADD($table,$field,$value){ mysql_query("INSERT INTO $table ($field) VALUES ('$value')"); } function UPDATE($table,$field,$value){ mysql_query("UPDATE $table SET $field = '$value'"); } function UPDATEWHERE($table,$field,$value,$where,$whereequals){ mysql_query("UPDATE $table SET $field = '$value' WHERE $where = '$whereequals'"); } function GET($table,$field,$row){ $query = mysql_query("SELECT $field FROM $table"); $data = mysql_fetch_row($query); $return = $data[$row]; return $return; } function GETWHERE($table,$field,$where,$whereequals,$row) { $query = mysql_query("SELECT $field FROM $table WHERE $where ='$whereequals'"); $data = mysql_fetch_row($query); $return = $data[$row]; return $return; } ?> Quote Link to comment Share on other sites More sharing options...
dimond345 Posted December 1, 2008 Share Posted December 1, 2008 Hello again. You use $con parameter, that accesebly only from function connect(); To always have the way to close sql connection you may use class. for example like this: class my_sql_db { var $db_connect_id; var $query_result; var $row = array(); var $rowset = array(); var $num_queries = 0; // // Constructor // function my_sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true) { $this->persistency = $persistency; $this->user = $sqluser; $this->password = $sqlpassword; $this->server = $sqlserver; $this->dbname = $database; if($this->persistency) { $this->db_connect_id = @mysql_pconnect($this->server, $this->user, $this->password); } else { $this->db_connect_id = @mysql_connect($this->server, $this->user, $this->password); } if($this->db_connect_id) { if($database != "") { $this->dbname = $database; $dbselect = @mysql_select_db($this->dbname); if(!$dbselect) { @mysql_close($this->db_connect_id); $this->db_connect_id = $dbselect; } } return $this->db_connect_id; } else { return false; } } // // Other base methods // function sql_close() { if($this->db_connect_id) { if($this->query_result) { @mysql_free_result($this->query_result); } $result = @mysql_close($this->db_connect_id); return $result; } else { return false; } } // // Base query method // function sql_query($query = "", $transaction = FALSE) { // Remove any pre-existing queries unset($this->query_result); if($query != "") { $this->num_queries++; $this->query_result = @mysql_query($query, $this->db_connect_id); } if($this->query_result) { unset($this->row[$this->query_result]); unset($this->rowset[$this->query_result]); return $this->query_result; } else { return ( $transaction == END_TRANSACTION ) ? true : false; } } // // Other query methods // function sql_list_fields($table) { if($this->db_connect_id) { $result = @mysql_list_fields($this->dbname, $table, $this->db_connect_id) or die('DB, table or connection error.'); return $result; } else { return false; } } function sql_numrows($query_id = 0) { if(!$query_id) { $query_id = $this->query_result; } if($query_id) { $result = @mysql_num_rows($query_id); return $result; } else { return false; } } function sql_affectedrows() { if($this->db_connect_id) { $result = @mysql_affected_rows($this->db_connect_id); return $result; } else { return false; } } function sql_numfields($query_id = 0) { if(!$query_id) { $query_id = $this->query_result; } if($query_id) { $result = @mysql_num_fields($query_id); return $result; } else { return false; } } function sql_fieldname($offset, $query_id = 0) { if(!$query_id) { $query_id = $this->query_result; } if($query_id) { $result = @mysql_field_name($query_id, $offset); return $result; } else { return false; } } function sql_fieldtype($offset, $query_id = 0) { if(!$query_id) { $query_id = $this->query_result; } if($query_id) { $result = @mysql_field_type($query_id, $offset); return $result; } else { return false; } } function sql_fieldlen($offset, $query_id = 0) { if(!$query_id) { $query_id = $this->query_result; } if($query_id) { $result = @mysql_field_len($query_id, $offset); return $result; } else { return false; } } function sql_fieldflags($offset, $query_id = 0) { if(!$query_id) { $query_id = $this->query_result; } if($query_id) { $result = @mysql_field_flags($query_id, $offset); return $result; } else { return false; } } function sql_fetchrow($query_id = 0) { if(!$query_id) { $query_id = $this->query_result; } if($query_id) { $this->row[$query_id] = @mysql_fetch_array($query_id); return $this->row[$query_id]; } else { return false; } } function sql_fetchassoc($query_id = 0) { if(!$query_id) { $query_id = $this->query_result; } if($query_id) { $this->row[$query_id] = @mysql_fetch_assoc($query_id); return $this->row[$query_id]; } else { return false; } } function sql_fetchrowset($query_id = 0) { if(!$query_id) { $query_id = $this->query_result; } if($query_id) { unset($this->rowset[$query_id]); unset($this->row[$query_id]); while($this->rowset[$query_id] = @mysql_fetch_array($query_id)) { $result[] = $this->rowset[$query_id]; } return $result; } else { return false; } } function sql_fetchfield($field, $rownum = -1, $query_id = 0) { if(!$query_id) { $query_id = $this->query_result; } if($query_id) { if($rownum > -1) { $result = @mysql_result($query_id, $rownum, $field); } else { if(empty($this->row[$query_id]) && empty($this->rowset[$query_id])) { if($this->sql_fetchrow()) { $result = $this->row[$query_id][$field]; } } else { if($this->rowset[$query_id]) { $result = $this->rowset[$query_id][0][$field]; } else if($this->row[$query_id]) { $result = $this->row[$query_id][$field]; } } } return $result; } else { return false; } } function sql_rowseek($rownum, $query_id = 0){ if(!$query_id) { $query_id = $this->query_result; } if($query_id) { $result = @mysql_data_seek($query_id, $rownum); return $result; } else { return false; } } function sql_nextid(){ if($this->db_connect_id) { $result = @mysql_insert_id($this->db_connect_id); return $result; } else { return false; } } function sql_freeresult($query_id = 0){ if(!$query_id) { $query_id = $this->query_result; } if ( $query_id ) { unset($this->row[$query_id]); unset($this->rowset[$query_id]); @mysql_free_result($query_id); return true; } else { return false; } } function sql_error($query_id = 0) { $result["message"] = @mysql_error($this->db_connect_id); $result["code"] = @mysql_errno($this->db_connect_id); return $result; } } // class sql_db to have access every there you may also use some thing like this: function connect() { global $con; $con = .... //your code here } there you want to access $con use this: global $con; mysql_close($con); About header error. You recive it cause you have some information already send to browser($con error message); After full debug of you scripts use this: ini_set("display_errors",0); error_reporting(E_ERROR);//or any other error level that you want to write in you server logs. Quote Link to comment Share on other sites More sharing options...
dimond345 Posted December 1, 2008 Share Posted December 1, 2008 Use include insted of requare and requare_once , it much faster. Like print instead of echo; Quote Link to comment Share on other sites More sharing options...
Chaori Posted December 1, 2008 Author Share Posted December 1, 2008 <html><head><meta http-equiv="Refresh" content="0; URL=http://neverbeast.com/valdellaknights/main.php"></head><body <?php include 'functions.php'; connect(); $latitude = GETWHERE("characters","latitude","account_id","$accid","0"); $longitude = GETWHERE("characters","longitude","account_id","$accid","0"); if($_POST['north']){ $accid = GETWHERE("account","account_id","character_name",$user,"0"); $longitude +=1; mysql_query ("UPDATE characters SET longitude='$longitude' WHERE account_id='$accid'"); } else if($_POST['west']){ $accid = GETWHERE("account","account_id","character_name",$user,"0"); $latitude -=1; mysql_query ("UPDATE characters SET latitude='$latitude' WHERE account_id='$accid'"); } else if($_POST['east']){ $accid = GETWHERE("account","account_id","character_name",$user,"0"); $latitude +=1; mysql_query ("UPDATE characters SET latitude='$latitude' WHERE account_id='$accid'"); } else if($_POST['south']){ $accid = GETWHERE("account","account_id","character_name",$user,"0"); $longitude -=1; mysql_query ("UPDATE characters SET longitude='$longitude' WHERE account_id='$accid'"); } ?> </body> </html> Can you tell me exactly what to change in that? Get's the following error: Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /hermes/bosweb/web008/b87/d5.beanonym/public_html/subdomain/Steve/neverbeast.com/valdellaknights/functions.php on line 30 Quote Link to comment Share on other sites More sharing options...
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.