wildteen88
Staff Alumni-
Posts
10,480 -
Joined
-
Last visited
Never
Everything posted by wildteen88
-
No, it should be $user_exists_sql = "SELECT `name` FROM `$player_table_name` WHERE `name`=$player_name "; $player_name already has the quotes. Also these liines 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` '; $update_user = true; } Need to be 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` "; $update_user = true; }
-
You've left of out this line: $player_name = sql_safe($player_data[13]); Add it before these lines // check to see if the player already exist $user_exists_sql = "SELECT `name` FROM `$player_table_name` WHERE `name`=$player_name"; So its like $player_name = sql_safe($player_data[13]); // check to see if the player already exist $user_exists_sql = "SELECT `name` FROM `$player_table_name` WHERE `name`=$player_name";
-
[SOLVED] Help with keeping form fields populated using sessions
wildteen88 replied to CodeMama's topic in PHP Coding Help
That code looks ok. What is it doing now? Is the form field populated? If its not can you post how the $_SESSION['searchname'] variable is being defined? -
Maybe (SELECT * FROM table WHERE id >= 70000 ORDER BY id ASC LIMIT 3) UNION (SELECT * FROM table WHERE id < 7000 ORDER BY id DESC LIMIT 2) However it probably isn't very efficient
-
WHERE Data_ID >= (13-2) AND `id` <= (13+2)
-
[SOLVED] problem with HTML/PHP form on Apache
wildteen88 replied to aldm's topic in Apache HTTP Server
That because the form action needs to be <form action="phpinfo.php" method="POST"> Now to run your form open your browser and go to http://localhost/forma.html Do not double click your files from within Windows Explorer to open in your browser. You must go to http://localhost to run your html/php files. -
The folder your trying to upload the files to most probably doesn't have sufficient permissions for writing. Add the following at the top of your script if(is_writable('/path/to/upload/folder/') { echo 'Folder is writeable'; } else { echo 'Folder is not writeable'; } And run it on your red-hat server. What is the output? If its says not writeable then change the permissions of the folder to 0777
-
[SOLVED] problem with HTML/PHP form on Apache
wildteen88 replied to aldm's topic in Apache HTTP Server
F:\xampp\htdocs\phpinfo.php should be phpinfo.php All code HTML/PHP needs to be saved in F:\xampp\htdocs You go to http://localhost to run your HTML/PHP -
Work through this tutorial. It should help you with what you need.
-
Look into using trigger_error and/or exceptions or setup your own error_handler
-
Yes change this: // magically make our update query $sql = 'UPDATE player_table_name_here '; To: // get the player name from the array $player_name = sql_safe($player_data[13]); // check to see if the player already exist $user_exists_sql = "SELECT `name` FROM `'.$player_table_name.'` WHERE `name`=$player_name"; $result = mysql_query($user_exists_sql); // 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.'` '; $update_user = true; } Another change you need to make is to change this // add the whole line into the query else { $sql .= "`" . $fields[$line_key][0] . "`=" . sql_safe($line_data) . ", \n"; } to // 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"; } And finally change this echo '<pre>' . print_r($sql, true) . '</pre>'; to // 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>'; You'll now want to add // DONT FORGET TO CONNECT TO MYSQL! $conn = mysql_connect('host', 'user', 'pass'); mysql_select_db('database_name'); $player_table_name = 'NAME OF USER TABLE IN DATABASE'; Before the following line $players_data_file = file('data.txt'); Thats it. The query will now be intelligently generated. If the user already exists it'll perform an update query. If the user does not exist it'll insert the new user I'll leave that to you for creating the table. See what you can come up with. I'll give you a hint you'll want to run an CREATE TABLE IF NOT EXISTS query.
-
Having code on one line or multiple lines will have no affect on performance. The difference in speed will be extremely minimal. The end user wont be able to tell difference in page load times. However the disadvantages you have with the code on one line are if there is any errors you wont be able to tell where they are as the code is unreadable.
-
You'll want to make this your link echo "<li class=\"list2\"><a href=\"/movie/view_list.php?genre=$name_genre&main_id=$id\">".$name_genre."</a></li>"; So if you include sidebar.php in movies/admin/index.php the link should always go to http://localhost/movies/siderbar.php HTML paths are not the same as file paths in PHP. A / at the start of the link will call the requested file from the root of the url, get http://localhost/
-
I do not get what you mean by Where is view_list.php located?
-
What is the code you're using to generate your links?
-
No, post your question in the Apache forum
-
[SOLVED] My loop/function times out the page; cookies
wildteen88 replied to dink87522's topic in PHP Coding Help
The problem is you have a infinity loop, you need to change this $rnd = rand(1, 203); recentQuestionsPop($rnd); To $rnd = rand(1, 203); $checked = recentQuestionsPop($rnd); return does not return the variable you pass it but the value of the variable. You need to capture the returned value when you call the function. To see if a cookie is set you use if(isset($_COOKIE['name_here'])) { // code for when the cookie is set } else { // code for when the cookie is not set } -
Cant include source files in the eclipse IDE
wildteen88 replied to evan12's topic in Editor Help (PhpStorm, VS Code, etc)
What do you mean by include source file? If you have set up a project all files for your project should available to you in the File panel. -
All data in your $_SESSION variables are stored server side , unlike cookies which are stored on the client. Sessions do use cookies but it only stores the session id. This id cannot be tampered with it is unique to each user. No one can get hold of your session data, unless they manage to find an exploit in your code which allows them to gain access, this is why it is important to always sanitize data from the user.
-
PHP fails to load some modules
wildteen88 replied to oneandoneis2's topic in PHP Installation and Configuration
Uninstall PHP and delete the PHP folder. Redownload the Zip package from http://windows.php.net and extract to C:\PHP -
PHP fails to load some modules
wildteen88 replied to oneandoneis2's topic in PHP Installation and Configuration
How did you originally install PHP? Did you install from zip or the installer? -
PHP fails to load some modules
wildteen88 replied to oneandoneis2's topic in PHP Installation and Configuration
Add the PHP folder C:\PHP to the PATH Environment Variable Some extensions require external libraries. These are located in C:\PHP (eg libmysql.dll). Adding PHP to the PATH will allow PHP to find these files. Also when enabling the php_pdo_* extensions make sure you enable php_pdo.dll too. -
Had nothing to do so I came up with this. Mine generates the whole query <?php function sql_safe($value) { $value = trim($value); if(is_numeric($value)) return $value; else return "'$value'"; } $players_data_file = file('data.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_goals', 'week_assists', 'week_gwg', 'month_goals'), array('month_assists', 'month_gwg'), 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('drafeted'), 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) { // magically make our update query $sql = 'UPDATE player_table_name_here '; // 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 { $sql .= "`" . $fields[$line_key][0] . "`=" . sql_safe($line_data) . ", \n"; } } echo '<pre>' . print_r($sql, true) . '</pre>'; } ?>
-
Really simple question about a form and $_POST vars
wildteen88 replied to Perfidus's topic in PHP Coding Help
You don't have to set the enctype, it is not required. -
Really simple question about a form and $_POST vars
wildteen88 replied to Perfidus's topic in PHP Coding Help
Remove enctype="text/plain" from your <form> tag