tsilenzio Posted July 25, 2007 Share Posted July 25, 2007 Okay i been working on this install script for longer then i wanted to, I keep running into endless errors and its starting to really frustrate me i will post the script below and the errors i keep getting <?php /********************************************************** * This code is the majority of the script, all abstract * code has been removed, if for whatever reason you * need to see the rest of the code because I missed * something then just say so other then that i think * that i got all the code that you needed to understand * how it works. **********************************************************/ //-------- FUNCTIONS --- BEGIN ----------// function dbConnect() { global $db_hostname, $db_password, $db_username, $db_database; if ($conn = mysql_connect($db_hostname, $db_username, $db_password)) { if(!mysql_select_db($db_database, $conn)) { die("Couldnt select database:<br><br>" . mysql_error()); } else { return $conn; } } else { die("Couldnt connect to MySQL:<br><br>" . mysql_error()); } } function processQuery($query) { global $db_hostname, $db_password, $db_username, $db_database; $conn = dbConnect(); if($result = mysql_query($query, $conn)) { return $result; } else { die("Couldnt send query:<br><br>" . mysql_error()); } mysql_close($result); } function injectSQL($fileName) { $filePath = $_SERVER["DOCUMENT_ROOT"] . '/install/data/' . $fileName; if(!($handle = fopen($filePath, "r"))); { die("Failed to open file: " . $filePath); } $query = ""; $lines = explode("\n", fread($handle, filesize($filePath))); if(!(fclose($handle))) { die("Failed to close file: " . $filePath); } foreach($lines as $line) { if(!(strpos($line,"//") == 0) && $line != "") //check for commented lines or blanks { $query .= $line; if(!(strpos($line, ";") == false)) { if($fileName = "sql_data.sql") { $query = str_replace(array('admin_username', 'admin_password', 'admin_email', 'admin_race', '00000000000000'), array($loginName, $password, $email, $race, time()), $query); } processQuery($query); $query = ""; } } } } //------ FUNCTIONS --- END ------// // // Empty database then drop it // ---------------------------------------------------------------------------- // For those of u wondering i empty the db first because when it recreats it, // it will put all the values alreay in it back into it. I dont know why it just does. // ---------------------------------------------------------------------------- // dbConnect(); if($result = mysql_list_tables($db_database)) { while ($row = mysql_fetch_row($result)) { print_r($row); $table = $row[0]; $query = "TRUNCATE TABLE $table"; processQuery($query); $query = "DROP TABLE $table"; processQuery($query); } } else { die("MySQL Error: " . mysql_error()); } // // Create all needed tables // injectSQL("sql_tables.sql"); echo("Tables installed."); //Seee if it will even make it this far - Remove once working.. // // Load values into new tables // injectSQL("sql_data.sql"); echo("Data installed."); //Seee if it will even make it this far - Remove once working.. Result as of now: Failed to open file: /home/deathsea/domains/dsunlimited.info/public_html/install/data/sql_tables.sql and I cant figure out how to fix it any help would be MUCH MUCH MUCH appreciated!!! Thanks SOOO much in advance! - tsilenzio Quote Link to comment Share on other sites More sharing options...
rlindauer Posted July 25, 2007 Share Posted July 25, 2007 Does the file exist at that location? Quote Link to comment Share on other sites More sharing options...
tsilenzio Posted July 25, 2007 Author Share Posted July 25, 2007 Yea im looking at it on my ftp lol, also forgot to mension i chmod it to 777 Quote Link to comment Share on other sites More sharing options...
tsilenzio Posted July 26, 2007 Author Share Posted July 26, 2007 is anyone able to help lol plz before i kill myself from getting soo angry lmao Quote Link to comment Share on other sites More sharing options...
ThumpernetRyan Posted July 26, 2007 Share Posted July 26, 2007 Try this: function injectSQL($fileName) { $filePath = $_SERVER["DOCUMENT_ROOT"] . '/install/data/' . $fileName; echo "$filePath<br>"; if(!($handle = fopen($filePath, "r"))); That should help you determine if your filepath is getting set correctly. Be sure you can get to the file from that actual path. Quote Link to comment Share on other sites More sharing options...
tsilenzio Posted July 26, 2007 Author Share Posted July 26, 2007 ill try it but i kinda did that it shows up in the error... ill highligh the part for you, if its a diffrent story then let me know: //<?php -- Just to make it have pretty colors (Syntax Highlight) function injectSQL($fileName) { $filePath = $_SERVER["DOCUMENT_ROOT"] . '/install/data/' . $fileName; if(!($handle = fopen($filePath, "r"))); { die("Failed to open file: " . $filePath); //<?php -- Just to make it have pretty colors (Syntax Highlight) } $query = ""; $lines = explode("\n", fread($handle, filesize($filePath))); if(!(fclose($handle))) { die("Failed to close file: " . $filePath); //Shows what the filepath is //<?php -- Just to make it have pretty colors (Syntax Highlight) } foreach($lines as $line) { if(!(strpos($line,"//") == 0) && $line != "") //check for commented lines or blanks { $query .= $line; if(!(strpos($line, ";") == false)) { if($fileName = "sql_data.sql") { $query = str_replace(array('admin_username', 'admin_password', 'admin_email', 'admin_race', '00000000000000'), array($loginName, $password, $email, $race, time()), $query); } processQuery($query); $query = ""; } } } } and it outputes Failed to open file: /home/deathsea/domains/dsunlimited.info/public_html/install/data/sql_tables.sql Quote Link to comment Share on other sites More sharing options...
tsilenzio Posted July 26, 2007 Author Share Posted July 26, 2007 Okay me and my friend ran this over all the code and we still can't figure out what is wrong =/ anyone have any ideas? Quote Link to comment Share on other sites More sharing options...
tsilenzio Posted July 26, 2007 Author Share Posted July 26, 2007 OKAY I finally found the problem it was one character out of place lol when i copied and pasted forgot to get rid of a semicolon ; //<?php // <-- Just to make it have pretty colors (Syntax Highlight) // if(!($handle = fopen($filePath, "r"))); { die("Failed to open file: " . $filePath); } Thank you everyone who tried to help!! 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.