Jump to content

wildteen88

Staff Alumni
  • Posts

    10,480
  • Joined

  • Last visited

    Never

Everything posted by wildteen88

  1. Use this instead: $line_data = str_replace(' -', ' -', $line_data); $field_data = explode(' ', $line_data);
  2. That code goes within a file called .htaccess (that is the full name). This file should be placed in your websites root folder (eg C:/wamp/www). For a production environment then I do not recommend any sort of all-in-one solution, such as WAMP, XAMPP etc. These should only be used for development/testing purposes only. For a production environment IMO you should setup Apache, PHP and MySQL separately.
  3. Use preg_match. Do note that preg_* based functions require you to use regex.
  4. You can use mod_rewrite to redirect all urls in ending .asp or .aspx to the corresponding .php file. Like so RewriteEngine On RewriteCond %{REQUEST_URI} !-f RewriteCond %{REQUEST_URI} !-d RewriteRule ^(.*).aspx?$ $1.php [R=301,QSA,L] As for porting your MSSQL databases to MySQL I'd keep to MSSQL. PHP is capable of using MSSQL databases However I do not recommend using WAMP as a production server. It is recommended to use it as a development server.
  5. Im guessing log_id is an auto_increment key? If its don't include it in your query. $string = "INSERT INTO logreport (gblogin_id, page, browser, datetime, ipaddress) VALUES ('$loginid', '$gblogin_id', '$browser', NOW(), '$ipad')";
  6. It probably because your getDocument() method returns an object. So you cant place $client->getDocument(blah) within print(). Mayeb you want to use print_r Can we see your getDocument() method.
  7. Please read the follwing FAQ post.
  8. Have a read of this Pagination tutorial. It will help you with what you're trying to do.
  9. This code //if the login form is submitted if (isset($_POST['submit'])) { // if form has been submitted // makes sure they filled it in if(!$_POST['username'] | !$_POST['pass']) { die('You did not fill in a required field.'); } // checks it against the database if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $check = mysql_query("SELECT * FROM hotelsignup WHERE username = '".$_POST['username']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { die('That user does not exist in our database. <a href=add.php>Click Here to Register</a>'); } while($info = mysql_fetch_array( $check )) { $_POST['pass'] = stripslashes($_POST['pass']); $info['password'] = stripslashes($info['password']); $_POST['pass'] = md5($_POST['pass']); //gives error if the password is wrong if ($_POST['pass'] != $info['password']) { die('Incorrect password, please try again.'); } else { // if login is ok then we add a cookie $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(ID_my_site, $_POST['username'], $hour); setcookie(Key_my_site, $_POST['pass'], $hour); //then redirect them to the members area header("Location: members.php"); } } } Can be reduced down to //if the login form is submitted if (isset($_POST['submit'])) { // get the login details $username = mysql_real_escape_string($_POST['username']); // encrypt the users password $password = md5($_POST['pass']); // Perform a single query to see if a record in the table has the same username and password $query = "SELECT username FROM hotelsignup WHERE username = '" . $username . "' AND password = '" . $password . "'"; $result = mysql_query($query)or die(mysql_error()); // check that the query returned one result // if it does user is logged if(mysql_num_rows($result) == 1) { // user has logged in successfully! // set a cookie $hour = time() + 3600; setcookie('ID_my_site', $username, $hour); // redirect user header("Location: members.php"); } // inavlid user. Login failed else { echo 'Invalid Login'; } }
  10. I guess in your landline_anynetwork_mins() and landline_anynetwork_price() functions you're using echo? You should instead use return.
  11. What steps does the book take you through to install PHP on windows?
  12. Your code uses a functions called escape() where is this function defined? Whats the code for showing the result?
  13. Oh sorry I though you where using Windows. I forgot to ask what OS you where using. How does the book describe how to install PHP on linux?
  14. You can ignore that. I get a similar message too and I cant seem to shift that error. This is a simple error to solve. In your php.ini change this line ;extension=php_mbstring.dll to extension=php_mbstring.dll Save the php.ini and restart your HTTP Server eg Apache, IIS etc. That error should go away.[/code]
  15. Are you using the new code I supplied here? Do you get any errors? If you do post them here.
  16. Change this if (!empty(escape($_POST['title']))) { to if (!empty($_POST['title'])) {
  17. Should be $$dxx= $p13[$doc_path . '_dx'];
  18. The background color is defined by this line $bg_color = imagecolorallocate($im, 255, 255, 255); The color is set using RGB values. In your case you're setting the background color as white. For black use 0, 0, 0 instead of 255, 255, 255 Read the manual on using the imagecolorallocate function.
  19. Remove this line: $bigArray[$i] = $valsOne[$i]; from your loop Alternatively use array_combine
  20. How did you install PHP in the first place? If you used the PHP installer you need to go to Add/remove programs and reconfigure the PHP installation. During the process you'll be asked what items to install. From the list choose PHP > Extensions. From the list of extensions choose which extension(s) you wish to install/use. Finish the installation by clicking next. Stop/Start IIS and the extensions you choose during installation should be available.
  21. EDIT Before running the new code delete your players table first. Otherwise the script wont run properly. Yep I can confirm the script is now fully functional, here is the fixed code <?php function sql_safe($value) { $value = trim($value); if(is_numeric($value)) return $value; else return "'$value'"; } // DONT FORGET TO CONNECT TO MYSQL! $conn = mysql_connect('localhost', 'liguehs_ara', '1992arayugi'); mysql_select_db('liguehs_league'); $player_table_name = 'players'; $make_table = 'CREATE TABLE IF NOT EXISTS `'.$player_table_name.'` (`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY, `shooting` INT(5) NOT NULL, `playmaking` INT(5) NOT NULL, `stickhandling` INT(5) NOT NULL, `checking` INT(5) NOT NULL, `marking` INT(5) NOT NULL, `hitting` INT(5) NOT NULL, `skating` INT(5) NOT NULL, `endurance` INT(5) NOT NULL, `penalty` INT(5) NOT NULL, `faceoffs` INT(5) NOT NULL, `leadership` INT(5) NOT NULL, `strength` INT(5) NOT NULL, `potentiel` INT(5) NOT NULL, `consistency` INT(5) NOT NULL, `greed` INT(5) NOT NULL, `fighting` INT(5) NOT NULL, `click` INT(5) NOT NULL, `team` INT(5) NOT NULL, `main_position` INT(5) NOT NULL, `country` INT(5) NOT NULL, `handed` INT(5) NOT NULL, `birth_year` INT(5) NOT NULL, `birth_day` INT(5) NOT NULL, `birth_month` INT(5) NOT NULL, `salary` INT(11) NOT NULL, `contract_lenght` INT(5) NOT NULL, `draft_year` INT(5) NOT NULL, `draft_round` INT(5) NOT NULL, `drafted_by` INT(5) NOT NULL, `rights` INT(5) NOT NULL, `week_games` INT(5) NOT NULL, `week_goals` INT(5) NOT NULL, `week_assists` INT(5) NOT NULL, `week_points` INT(5) NOT NULL, `month_games` INT(5) NOT NULL, `month_goals` INT(5) NOT NULL, `month_assists` INT(5) NOT NULL, `month_points` INT(5) NOT NULL, `record_goals` INT(5) NOT NULL, `record_assists` INT(5) NOT NULL, `record_points` INT(5) NOT NULL, `no_trade_switch` INT(5) NOT NULL, `two-way_switch` INT(5) NOT NULL, `player-team_option` INT(5) NOT NULL, `status` INT(5) NOT NULL, `rookie` INT(5) NOT NULL, `considering_offer_data` INT(11) NOT NULL, `team_offering` INT(5) NOT NULL, `amount_time_spent_considering` INT(5) NOT NULL, `injury` INT(5) NOT NULL, `line8` VARCHAR(50) NOT NULL, `line9` VARCHAR(50) NOT NULL, `line10` VARCHAR(50) NOT NULL, `goal_streak` INT(5) NOT NULL, `point_streak` INT(5) NOT NULL, `total_gp` INT(5) NOT NULL, `suspended_game` INT(5) NOT NULL, `training` INT(5) NOT NULL, `weight` INT(5) NOT NULL, `height` INT(5) NOT NULL, `status_in_organization` INT(5) NOT NULL, `best_streak_games` INT(5) NOT NULL, `best_streak_gwg` INT(5) NOT NULL, `best_streak_assists` INT(5) NOT NULL, `best_streak_points` INT(5) NOT NULL, `best_streak_goals` INT(5) NOT NULL, `line13` VARCHAR(50) NOT NULL, `name` VARCHAR(100) NOT NULL, `line15` VARCHAR(50) NOT NULL, `drafted` VARCHAR(100) NOT NULL, `line17` VARCHAR(50) NOT NULL, `line18` VARCHAR(50) NOT NULL, `line19` VARCHAR(50) NOT NULL, `attitude` INT(5) NOT NULL, `alternate_position` INT(5) NOT NULL, `nhl_rights` INT(5) NOT NULL, `injury_prone` INT(5) NOT NULL, `overral_draft` INT(5) NOT NULL ) ENGINE = MYISAM ;'; mysql_query($make_table) or die('Cannot create table ' . $player_table_name . '<br />'.mysql_error()); $players_data_file = file('players.txt'); // remove first line from file, this is line holds the number of players $total_players = array_shift($players_data_file); // DO NOT CHANGE THIS. THIS IS SET UP TO MATCH THE DATA IN THE DATA.TXT FILE $fields = array( array('shooting', 'playmaking', 'stickhandling', 'checking', 'marking', 'hitting', 'skating', 'endurance', 'penalty', 'faceoffs'), array('leadership', 'strength', 'potentiel', 'consistency', 'greed', 'fighting', 'click', 'team', 'main_position', 'country', 'handed'), array('birth_year', 'birth_day', 'birth_month', 'salary', 'contract_lenght', 'draft_year', 'draft_round', 'drafted_by', 'rights'), array('week_games', 'week_goals', 'week_assists', 'week_points'), array('month_games', 'month_goals', 'month_assists', 'month_points'), array('record_goals', 'record_assists', 'record_points', 'no_trade_switch', 'two-way_switch', 'player-team_option'), array('status', 'rookie', 'considering_offer_data', 'team_offering', 'amount_time_spent_considering', 'injury'), array('line8'), array('line9'), array('line10'), array('goal_streak', 'point_streak', 'total_gp', 'suspended_game', 'training', 'weight', 'height', 'status_in_organization'), array('best_streak_games', 'best_streak_gwg', 'best_streak_assists', 'best_streak_points', 'best_streak_goals'), array('line13'), array('name'), array('line15'), array('drafted'), array('line17'), array('line18'), array('line19'), array('attitude', 'alternate_position', 'nhl_rights', 'injury_prone', 'overral_draft') ); // split every 20 lines into a new array $all_players_data = array_chunk($players_data_file, 20); // loop through each block of 20 lines foreach($all_players_data as $player_data) { // check to see if the player already exist $player_name = sql_safe($player_data[13]); $user_exists_sql = "SELECT `name` FROM `$player_table_name` WHERE `name`=$player_name "; $result = mysql_query($user_exists_sql) or die('Error checking user!<br />'.mysql_error()); // if the user does not exist, use an INSERT STATEMENT // we'll add the user into the database if(mysql_num_rows($result) == '0') { $sql = "INSERT INTO `$player_table_name` SET "; $update_user = false; } // user does exist so we'll use an UPDATE statement // update the existing user else { $sql = "UPDATE `$player_table_name` SET "; $update_user = true; } // here we're looping through each line foreach($player_data as $line_key => $line_data) { // if we're not on line 8, 9, 10, 13, 14 or 15 // turn line data into an array if(!in_array($line_key, array(7, 8, 9, 12, 13, 14))) { $field_data = explode(' ', $line_data); // match up the data with the field array // this is where our query is generated foreach($field_data as $field_key => $field_value) { if(isset($fields[$line_key][$field_key])) $sql .= "`" . $fields[$line_key][$field_key] . "`=" . sql_safe($field_value) . ', '; } $sql .= "\n"; } // add the whole line into the query else { // if we're updating the user skip line 14 if( $update_user && $line_key == 13) continue; $sql .= "`" . $fields[$line_key][0] . "`=" . sql_safe($line_data) . ", \n"; } } // remove the last three characters from $sql $sql = substr($sql, 0, -3); // add the WHERE clause only if we are updating the user if($update_user) $sql .= " WHERE name=$player_name"; echo '<pre>' . print_r($sql, true) . '</pre>'; mysql_query($sql) or die('Cannot inset/update table!'.mysql_error()); } ?>
  22. Oops marked the wrong bit of data. Its the last bit of data on the second line. What is the field name for that?
  23. To clarify the parts highlighted in red Do not match up to a field in the database. Is this correct? All the other bits are inserted into the database fine.
  24. Okay I have tested the code fully now and there are inconsistencies with the table names. The data in the player.txt file does not match up with the table names you have supplied. The way I am matching up the data in the player.txt file with the correct field name is by the example query you provided earlier Can you confirm those are the correct field names? The way way the $fields array is constructed is by how the data is layed out in player.txt
  25. Okay lets see what the error is Change this line $result = mysql_query($user_exists_sql); To $result = mysql_query($user_exists_sql) or die(mysql_error());
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.