cbuck1989 Posted March 5, 2018 Share Posted March 5, 2018 (edited) So I am going to look like a complete noob (which i am haha) but I cannot for the life of me get these issues fixed. Warning: mysqli_query() expects at least 2 parameters, 1 given in /home1/cbuck1989/trav.flyingroadside.com/install/include/constant.php on line 4Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /home1/cbuck1989/trav.flyingroadside.com/install/include/constant.php on line 5 here is the code in constant.php <?php $boo = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS); mysqli_select_db($boo, SQL_DB); $sql = mysqli_query($boo, "SELECT * FROM ".TB_PREFIX."config"); $result = mysqli_fetch_array($sql); If anyone could please tell me what i am messing up here, would be much appreciated. Thank you Edited March 5, 2018 by cbuck1989 Quote Link to comment Share on other sites More sharing options...
requinix Posted March 5, 2018 Share Posted March 5, 2018 That code doesn't match up with the error message. Make sure you're looking at the right file and that the server isn't inexplicably running some different version of the file. Quote Link to comment Share on other sites More sharing options...
cbuck1989 Posted March 5, 2018 Author Share Posted March 5, 2018 (edited) Okay ill just post all the error messages and pages. Warning: mysqli_query() expects at least 2 parameters, 1 given in /home1/cbuck1989/trav.flyingroadside.com/install/include/constant.php on line 4Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /home1/cbuck1989/trav.flyingroadside.com/install/include/constant.php on line 5Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home1/cbuck1989/trav.flyingroadside.com/install/include/database.phpon line 25Warning: Cannot modify header information - headers already sent by (output started at /home1/cbuck1989/trav.flyingroadside.com/install/include/constant.php:4) in /home1/cbuck1989/trav.flyingroadside.com/install/process.php on line 80 Okay so you already see constant.php here is Database.php <?php set_time_limit(0); include("connection.php"); include("constant.php"); class MYSQLi_DB { var $connection; function MYSQLi_DB() { $this->connection = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS, SQL_DB) or die(mysqli_error()); } function query($query) { return $this->connection->query($query); } }; class MYSQL_DB { var $connection; function MYSQL_DB() { $this->connection = mysql_connect(SQL_SERVER, SQL_USER, SQL_PASS) or die(mysql_error()); mysql_select_db(SQL_DB, $this->connection) or die(mysql_error()); } function mysql_exec_batch ($p_query, $p_transaction_safe = true) { if ($p_transaction_safe) { $p_query = 'START TRANSACTION;' . $p_query . '; COMMIT;'; }; $query_split = preg_split ("/[;]+/", $p_query); foreach ($query_split as $command_line) { $command_line = trim($command_line); if ($command_line != '') { $query_result = mysql_query($command_line); if ($query_result == 0) { break; }; }; }; return $query_result; } function query($query) { return mysql_query($query, $this->connection); } }; if(DB_TYPE) { $database = new MYSQLi_DB; } else { $database = new MYSQL_DB; } ?> and here is process.php <?php date_default_timezone_set('Asia/Tehran'); if(file_exists("include/constant.php") && file_exists("include/connection.php")) { include ("include/database.php"); } class Process { function Process() { if(isset($_POST['subconst'])) { $this->constForm(); } else if(isset($_POST['substruc'])) { $this->createStruc(); } else if(isset($_POST['subwdata'])) { $this->createWdata(); } else if(isset($_POST['subacc'])) { $this->createAcc(); } else { header("Location: index.php"); } } function constForm() { global $database; $myFile = "include/constant.php"; $fh = fopen($myFile, 'w') or die("<br/><br/><br/>Can't open file: install\include\constant.php"); $text = file_get_contents("data/constant_format.tpl"); $text = preg_replace("'%TRADERCAP%'", $_POST['tradercap'], $text); $text = preg_replace("'%CRANNYCAP%'", $_POST['crannycap'], $text); $text = preg_replace("'%TRAPPERCAP%'", $_POST['trappercap'], $text); $text = preg_replace("'%UTRACK%'", $_POST['trackusers'], $text); $text = preg_replace("'%UTOUT%'", $_POST['timeout'], $text); $text = preg_replace("'%AUTOD%'", $_POST['autodel'], $text); $text = preg_replace("'%AUTODT%'", $_POST['autodeltime'], $text); $text = preg_replace("'%MAX%'", $_POST['wmax'], $text); $text = preg_replace("'%ANAME%'", $_POST['aname'], $text); $text = preg_replace("'%ARANK%'", $_POST['admin_rank'], $text); $text = preg_replace("'%STARTTIME%'", time(), $text); $text = preg_replace("'%LIMIT_MAILBOX%'", $_POST['limit_mailbox'], $text); $text = preg_replace("'%MAX_MAILS%'", $_POST['max_mails'], $text); $text = preg_replace("'%VILLAGE_EXPAND%'", $_POST['village_expand'], $text); $text = preg_replace("'%ERROR%'", $_POST['error'], $text); $text = preg_replace("'%GREAT_WKS%'", $_POST['great_wks'], $text); $text = preg_replace("'%TS_THRESHOLD%'", $_POST['ts_threshold'], $text); $text = preg_replace("'%SSTARTDATE%'", $_POST['start_date'], $text); $text = preg_replace("'%SSTARTTIME%'", $_POST['start_time'], $text); $text = preg_replace("'%REG_OPEN%'", $_POST['reg_open'], $text); $text = preg_replace("'%PEACE%'", $_POST['peace'], $text); $text = preg_replace("'%LIMIT_TROOPS%'", $_POST['limit_troops'], $text); $text = preg_replace("'%STORAGE_MULTIPLIER%'", $_POST['storage_multiplier'], $text); fwrite($fh, $text); fclose($fh); $myFile = "include/connection.php"; $fh = fopen($myFile, 'w') or die("<br/><br/><br/>Can't open file: install\include\connection.php"); $text = file_get_contents("data/connection.tpl"); $text = preg_replace("'%SSERVER%'", $_POST['sserver'], $text); $text = preg_replace("'%SUSER%'", $_POST['suser'], $text); $text = preg_replace("'%SPASS%'", $_POST['spass'], $text); $text = preg_replace("'%SDB%'", $_POST['sdb'], $text); $text = preg_replace("'%PREFIX%'", $_POST['prefix'], $text); $text = preg_replace("'%CONNECTT%'", $_POST['connectt'], $text); fwrite($fh, $text); if(file_exists("include/constant.php") && file_exists("include/connection.php")) { include 'include/database.php'; $str = file_get_contents("data/config.sql"); $str = preg_replace("'%PREFIX%'", TB_PREFIX, $str); if(DB_TYPE) { $database->connection->multi_query($str); } else { $database->mysql_exec_batch($str); } mysql_query("INSERT into ".$_POST['prefix']."config values ('".$_POST['servername']."', '".$_POST['lang']."', '".$_POST['speed']."', 'gpack/travian_Travian_4.0_41/', '".$_POST['incspeed']."', '".$_POST['evaspeed']."', '".$_POST['healspeed']."', '".$_POST['advspeed']."', '".$_POST['demolish']."', '".$_POST['quest']."', '".$_POST['beginner']."', '".$_POST['auction_time']."', '".$_POST['ww']."', '".$_POST['activate']."', '".$_POST['plus_time']."', '".$_POST['plus_production']."', '".$_POST['log_build']."', '".$_POST['log_tech']."', '".$_POST['log_login']."', '".$_POST['log_gold_fin']."', '".$_POST['log_admin']."', '".$_POST['log_war']."', '".$_POST['log_market']."', '".$_POST['log_illegal']."', '".$_POST['box1']."', '".$_POST['box2']."', '".$_POST['box3']."', '".$_POST['home1']."', '".$_POST['home2']."', '".$_POST['home3']."', '".$_POST['aemail']."', '".$_POST['homepage']."')"); header("Location: index.php?s=2"); } else { header("Location: index.php?s=1&c=1"); } fclose($fh); } function createStruc() { global $database; $str = file_get_contents("data/sql.sql"); $str = preg_replace("'%PREFIX%'", TB_PREFIX, $str); if(DB_TYPE) { $result = $database->connection->multi_query($str); } else { $result = $database->mysql_exec_batch($str); } if($result) { header("Location: index.php?s=3"); } else { header("Location: index.php?s=2&c=1"); } } function createWdata() { header("Location: include/wdata.php"); } } ; $process = new Process; ?> I mean ive looked over and tried to fix the things it listed but i get no where. I hate how SQL is removed and put in SQLI. Cause now all my old coding needs updated. I apologize for being so "dumb" about this. It used to be easier back in the day it seems. I haven't tinkered with coding in many years haha Edited March 5, 2018 by cbuck1989 Quote Link to comment Share on other sites More sharing options...
ginerjm Posted March 5, 2018 Share Posted March 5, 2018 Let's stay on the first post for now. How about checking the result of your connect call? Test the value of $boo. If that fails try this. Build the query statement in a var - say $q. Then echo out that variable $q to see what you have built and are actually executing. Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 5, 2018 Share Posted March 5, 2018 The first two errors are referring to the file constant.php. It states that mysqli_query() is only being provided one parameter, but it lookslike two are provided $sql = mysqli_query($boo, "SELECT * FROM ".TB_PREFIX."config"); Perhaps $boo is false/null? You should add some debugging code to the connection and database selection functions. $boo = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS); if (!$boo) { echo "Error: Unable to connect to MySQL.<br>"; echo "Debugging errno: " . mysqli_connect_errno() . ""; echo "Debugging error: " . mysqli_connect_error() . "<br>"; exit; } $selectDbResult = mysqli_select_db($boo, SQL_DB); if (!$selectDbResult) { echo "Error: Unable to Select DB.<br>"; exit; } As for the other errors - why are you using mysql_ extensions and not mysqli_? That is just a warning message - which you can suppress, but you should be using mysqli_ or, better yet, PDO. Quote Link to comment Share on other sites More sharing options...
cbuck1989 Posted March 5, 2018 Author Share Posted March 5, 2018 The first two errors are referring to the file constant.php. It states that mysqli_query() is only being provided one parameter, but it lookslike two are provided $sql = mysqli_query($boo, "SELECT * FROM ".TB_PREFIX."config"); Perhaps $boo is false/null? You should add some debugging code to the connection and database selection functions. $boo = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS); if (!$boo) { echo "Error: Unable to connect to MySQL.<br>"; echo "Debugging errno: " . mysqli_connect_errno() . ""; echo "Debugging error: " . mysqli_connect_error() . "<br>"; exit; } $selectDbResult = mysqli_select_db($boo, SQL_DB); if (!$selectDbResult) { echo "Error: Unable to Select DB.<br>"; exit; } As for the other errors - why are you using mysql_ extensions and not mysqli_? That is just a warning message - which you can suppress, but you should be using mysqli_ or, better yet, PDO. Okay so i did that and now the first 2 error messages went away. now i just have the last 2 Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home1/cbuck1989/trav.flyingroadside.com/install/include/database.phpon line 25 Warning: Cannot modify header information - headers already sent by (output started at /home1/cbuck1989/trav.flyingroadside.com/install/include/database.php:25) in /home1/cbuck1989/trav.flyingroadside.com/install/process.php on line 80 Quote Link to comment Share on other sites More sharing options...
requinix Posted March 5, 2018 Share Posted March 5, 2018 Fix the first message by making your code use mysqli functions instead of mysql functions. When you do that the second message will go away. Quote Link to comment Share on other sites More sharing options...
cbuck1989 Posted March 5, 2018 Author Share Posted March 5, 2018 now i get this error Fatal error: Cannot redeclare class mysqli_DB in /home1/cbuck1989/trav.flyingroadside.com/install/include/database.php on line 20 database.php: <?php set_time_limit(0); include("connection.php"); include("constant.php"); class MYSQLi_DB { var $connection; function MYSQLi_DB() { $this->connection = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS, SQL_DB) or die(mysqli_error()); } function query($query) { return $this->connection->query($query); } }; class mysqli_DB { var $connection; function mysqli_DB() { $this->connection = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS) or die(mysqli_error()); mysqli_select_db(SQL_DB, $this->connection) or die(mysqli_error()); } function mysqli_exec_batch ($p_query, $p_transaction_safe = true) { if ($p_transaction_safe) { $p_query = 'START TRANSACTION;' . $p_query . '; COMMIT;'; }; $query_split = preg_split ("/[;]+/", $p_query); foreach ($query_split as $command_line) { $command_line = trim($command_line); if ($command_line != '') { $query_result = mysqli_query($command_line); if ($query_result == 0) { break; }; }; }; return $query_result; } function query($query) { return mysqli_query($query, $this->connection); } }; if(DB_TYPE) { $database = new MYSQLi_DB; } else { $database = new mysqli_DB; } ?> this is frustrating. Quote Link to comment Share on other sites More sharing options...
requinix Posted March 5, 2018 Share Posted March 5, 2018 this is frustrating.Quite. What are you trying to do in that file? Why do you need two classes? Why are they identical except for that mysqli_exec_batch method in the second version? What is DB_TYPE supposed to control? Quote Link to comment Share on other sites More sharing options...
cbuck1989 Posted March 5, 2018 Author Share Posted March 5, 2018 It is a game. I downloaded it but as you can see the SQL stuff is not updated. So this is what ive been trying to figure out the past couple day haha. This is just to install the game with its install feature. But everything works up to this point. But when you type in all the information on the install page it asks for you know the database information, and then theirs a drop down list that has MySQL and MySQLI. But the SQLI one is greyed out and cant select it. So im guessing that means i have to figure out the mess on these pages. not sure if that helped at all xD Quote Link to comment Share on other sites More sharing options...
requinix Posted March 6, 2018 Share Posted March 6, 2018 No, actually it probably means you don't have mysqli installed. Don't mess with the code unless there are instructions that tell you to do so. So undo your changes and install/enable the mysqli extension. Quote Link to comment Share on other sites More sharing options...
maxxd Posted March 6, 2018 Share Posted March 6, 2018 When was the code you downloaded written? It's using old-style class constructors that are deprecated in 7.0 (if you scroll down a bit you'll see the warning about the deprecation). Also, the second declaration of query() isn't using mysqli_query() correctly - the connection and query are passing in the wrong order. Finally, I could be missing something here but the mysqli_exec_batch() method looks really very dangerous... Quote Link to comment Share on other sites More sharing options...
cbuck1989 Posted March 6, 2018 Author Share Posted March 6, 2018 I know the MySQLI is installed cause its through my web hosting provider which is using the new stuff.I have the same exact game but an older version of it that was converted over to mySQLI and it runs perfect. But the newer version of the game they didn't convert to the mysqli. Well bits and pieces are. It even said the installation is the buggiest part. So if i can get past the installation part ill be set. Quote Link to comment Share on other sites More sharing options...
requinix Posted March 6, 2018 Share Posted March 6, 2018 Blindly throwing code at the problem is not going to make it go away. Especially if you don't know what you're doing. Your first step should be to find out why the mysqli option was disabled. The second step is to address the underlying cause. Quote Link to comment Share on other sites More sharing options...
cbuck1989 Posted March 6, 2018 Author Share Posted March 6, 2018 Unless i just take the installer scripts from the old version and add anything new to the newer version. Cause at least the old one works. Quote Link to comment Share on other sites More sharing options...
requinix Posted March 6, 2018 Share Posted March 6, 2018 Yeah, and if you have a car that doesn't work, you can just take the engine from another car and drop it in. Cause at least the other one works. Quote Link to comment Share on other sites More sharing options...
cbuck1989 Posted March 6, 2018 Author Share Posted March 6, 2018 lol i sense a little sarcasm in that Quote Link to comment Share on other sites More sharing options...
dalecosp Posted March 6, 2018 Share Posted March 6, 2018 Did you change this: class MYSQL_DB { to this? class MYSQLi_DB { Because he said make your code use mysqli functions ... he didn't say to rename the classes. If you did, you created this error: Fatal error: Cannot redeclare class mysqli_DB in /home1/cbuck1989/trav.flyingroadside.com/install/include/database.php on line 20 Because the code in database.php already had THIS at line 20: class mysqli_DB { So I am going to look like a complete noob (which i am haha) I don't like to call people names, but unfortunately this is starting to look like a more & more accurate statement. If we ARE able to make you see any light, you might have to apologize for wasting somebody's time. Although we volunteer it, or we wouldn't be here ... still people shouldn't take advantage of others like that. Yeah, and if you have a car that doesn't work, you can just take the engine from another car and drop it in. Cause at least the other one works. Well ... it's kind of like that. But you don't try that unless you're a mechanic or a very avid DIY type. Same goes here. Quote Link to comment Share on other sites More sharing options...
cbuck1989 Posted March 7, 2018 Author Share Posted March 7, 2018 Alright well i appreciate all the help up to this point. I apologize for asking for help. Didnt mean to take advantage of anyone. I will just move on and figure it out then. Thanks 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.