-
Posts
16,734 -
Joined
-
Last visited
-
Days Won
9
Everything posted by PFMaBiSmAd
-
Did you ever do this - Because the code you posted after that did not contain it and you cannot upload a file using a form unless the <form tag contains that attribute.
-
There is no point in randomly trying code or guessing what the code should be. What database class are you using so that someone could tell you how to do some error checking, error reporting, and error recovery to get it to tell you why the query is failing?
-
[SOLVED] How do I select only the lowest price for each unique ID?
PFMaBiSmAd replied to daydreamer's topic in MySQL Help
And if you want the actual rows with the minimum in each group (not just the minimum value in a group) you will need to use one of the methods at the following link (alter the code to use the MIN() function as needed) - http://dev.mysql.com/doc/refman/5.1/en/example-maximum-column-group-row.html -
Then php is not available or it is not configured on your hosting account. You would need to check with your web host what is required to cause php to be enabled for your hosting account.
-
Here is a semi-automated (you need to copy/paste from the browser's screen) method that works with the current season at http://www.nfl.com/schedules <?php // parse wxresults.txt, x = 1,2,3,4... files (copy/paste from http://www.nfl.com/schedules) // find only lines with @ in them, then find the teams and score before and after the @. Lookup abriviation to get full name. // display the 'form' with the winning teams selected. For demo, submits and adds a line to the picks.txt file showing the winning teams. // in a real application the picks, winning teams, and the winning picks would be handled through a database. $week = isset($_GET['week']) ? (int)$_GET['week'] : 1; $file = "w{$week}results.txt"; $lookup = array(); $lookup['CAR'] = 'Carolina Panthers'; $lookup['ATL'] = 'Atlanta Falcons'; $lookup['NO'] = 'New Orleans Saints'; $lookup['PHI'] = 'Philadelphia Eagles'; $lookup['STL'] = 'St. Louis Rams'; $lookup['WAS'] = 'Washington Redskins'; $lookup['HOU'] = 'Houston Texans'; $lookup['TEN'] = 'Tennessee Titans'; $lookup['NE'] = 'New England Patriots'; $lookup['NYJ'] = 'New York Jets'; $lookup['CIN'] = 'Cincinnati Bengals'; $lookup['GB'] = 'Green Bay Packers'; $lookup['ARI'] = 'Arizona Cardinals'; $lookup['JAC'] = 'Jacksonville Jaguars'; $lookup['OAK'] = 'Oakland Raiders'; $lookup['KC'] = 'Kansas City Chiefs'; $lookup['MIN'] = 'Minnesota Vikings'; $lookup['DET'] = 'Detroit Lions'; $lookup['TB'] = 'Tampa Bay Buccaneers'; $lookup['BUF'] = 'Buffalo Bills'; $lookup['SEA'] = 'Seattle Seahawks'; $lookup['SF'] = 'San Francisco 49ers'; $lookup['PIT'] = 'Pittsburgh Steelers'; $lookup['CHI'] = 'Chicago Bears'; $lookup['BAL'] = 'Baltimore Ravens'; $lookup['SD'] = 'San Diego Chargers'; $lookup['CLE'] = 'Cleveland Browns'; $lookup['DEN'] = 'Denver Broncos'; $lookup['NYG'] = 'New York Giants'; $lookup['DAL'] = 'Dallas Cowboys'; $lookup['IND'] = 'Indianapolis Colts'; $lookup['MIA'] = 'Miami Dolphins'; // the following common code is used by the form code and partially by the form processing code $teams = array(); // used by form code $lines = file($file); // read lines from the file into an array $i = 1; // counter for win array $win = array(); // array to hold winners (for form code) foreach($lines as $line){ // find only lines with @ in them $pos = strpos($line,'@'); if($pos !== FALSE){ // get only the portion before the first \t $part = explode("\t",$line); // get each team and score using preg_split $keywords = preg_split("/[\s,]+/", "hypertext language, programming"); //list($teamA,$scoreA,$teamB,$scoreB) = preg_split("/[\s]+/", $part[0]); $results = preg_split("/[\s]+/", $part[0]); //echo "<pre>"; //var_dump($results); //echo "</pre>"; // 0 = teamA, 1 = scoreA, 3 = teamB, 4 = scoreB // put teams into array to be used by the form code $teams[] = $lookup[$results[0]]; $teams[] = $lookup[$results[3]]; if($results[1] > $results[4]){ $win[$i] = $lookup[$results[0]]; // teamA won } else { $win[$i] = $lookup[$results[3]]; // teamB won } $i++; } } $total_games = count($teams) / 2; // condition inputs/default values $submitted = isset($_POST['submit']) ? $_POST['submit'] : ""; // form processing code if($submitted){ // validate inputs $form_errors = array(); // check for empty name if(empty($_POST["name"])){ $form_errors['name_field'] = "Fill in your name:"; } // check for a pick in each game pair for($i=1; $i <= $total_games;$i++){ if(!isset($_POST['pick'][$i])){ $form_errors["pick_{$i}"] = "Select one:"; } } // process the data if no errors if(empty($form_errors)){ $myFile = "Picks{$week}.txt"; $fh = fopen($myFile, 'a') or die("can't open file"); fwrite($fh, "Week{$week},{$_POST['name']},"); fwrite($fh, implode(',', $_POST['pick'])); fwrite($fh, "\n"); fclose($fh); Echo "Your picks have been recorded!"; } } // end of the form processing code // form code if(!$submitted || !empty($form_errors)){ $error_message = empty($form_errors) ? "" : "Please correct the errors shown in red -"; ?> <html> <head> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> <title>Picks</title> </head> <body> <p><?php echo "Enter your Name and select your picks for Week $week, then submit the form."; ?> </p> <span style='color:red'><?php echo $error_message; ?></span> <form method="post" action="#first"> <label for="name">Name: <?php echo isset($form_errors['name_field']) ? "<span style='color:red'>{$form_errors['name_field']}</span>" : "";?></label><br /> <input type="text" name="name" value="***WINNERS***"><br /> <?php $counter = 0; // keep track of pairs of teams $game = 1; // keep track of games (for radio buttons) $first_error = true; foreach($teams as $team){ if($counter % 2 == 0){ if(isset($form_errors["pick_{$game}"])){ if($first_error){ echo "<a name='first'></a>"; $first_error = false; } echo "<span style='color:red'>{$form_errors["pick_{$game}"]}<br /></span>"; } } //$class = (isset($form_errors["pick_{$game}"])) ? "red" : "black"; //checked="checked" $_POST['pick'][$game] if isset, will match a value $selected = ""; if(isset($win[$game]) && $win[$game] == $team){ $selected = "checked='checked'"; } //echo "<input name='pick[$game]' value='$team' type='radio' $selected><span style='color:$class'> $team</span><br>\n"; echo "<input name='pick[$game]' value='$team' type='radio' $selected> $team<br />\n"; $counter++; if($counter % 2 == 0){ $game++; echo "<br>\n"; } } ?> <input name="submit" value="Submit Picks!" type="submit"> <input type="reset"></form> <?php } // end of the form code ?> </body> </html> This produces a form (similar to the form that would be used to pick the choices for the games) and allows them to be submitted so that you can do anything with the information that you need. You could of course skip the form and use the results directly. You specify the week number on the end of the URL yourfile.php?week=8 The wxresults.txt file is the text that copy/pasted by dragging your mouse over the correct rows of text at http://www.nfl.com/schedules I have attached the week 8 results.txt file to this post as an example - [attachment deleted by admin]
-
They are generally referred to as expanding/tree menus. See this link for several examples - http://www.dynamicdrive.com/dynamicindex1/index.html
-
[SOLVED] PHP Function not returning value
PFMaBiSmAd replied to wwfc_barmy_army's topic in PHP Coding Help
It is highly likely that your variable $sect contains the word '$sect'. Echo $sql to see exactly what is in it. What is your code that is calling that function? Please DON"T use the globals keyword in your function. For what you are doing, it has no effect and it should not be used in any case. -
Cannot really help you with what your form or your form processing code is doing without seeing the code for both of them. Due to the general purpose nature of computers and programming, there is not a "one symptom" equals "one specific cause." One symptom can have many different causes. No one can tell you one specific thing to fix without pinning down what is causing it. The first step is to confirm if the code is or is not responsible for the symptom. Edit: Also, what does a phpinfo() statement show for the max_input_time setting?
-
You are likely exceeding one or more of the file upload settings on the server (upload_max_filesize and/or post_max_size and/or a MAX_FILE_SIZE setting being put into the form.) Once you press the submit button on the form, the form processing code will be executed any time the upload finishes, with errors or without errors. It is up to your form processing code to validate the upload data and check for all possible errors. Is your code doing any error checking and reporting why each file is not being uploaded so that you would know which upload error is occurring? Since this is not a HTML problem, moving thread to the php help forum...
-
That does not matter. As soon as you put any code that you find or write into a file on your server, it becomes your code. You are at that point responsible for what it is and what it does or if it contains something that is not compatible with either your server or your server configuration. Which is generally why it is a better idea to write your own code that does what you want it to, than to just copy/paste code that someone else wrote.
-
Problem passing variables from mysql populated form menu
PFMaBiSmAd replied to pip_r's topic in PHP Coding Help
When you do a "view source" of the form page in your browser, what do you get for the <option values? If the form is correct, you would need to post your whole actual form processing code if you want someone to determine what it is doing that is causing the problem. Best guess, you have an if() statement that is assigning the value 'select' to the variable instead of comparing the variable with the value 'select' (i.e. using one = (an assignment operator) instead of two == (an equal comparison operator.) -
The second parameter of setcookie() is a string value. mysql_fetch_array() returns an array. You would need to just use the 'id' element of the array that is being returned.
-
You would need to tell us what problem you are having when you tried that code, because there is nothing wrong with it and it in fact worked for me when I tried it.
-
Based on the path in your error message and the path of your include() statement, the include statement is probably failing. Please use both of the following lines of code immediately after your first opening <?php tag in your main file (you should not put them into sub-files as you will need to remember to remove them) - ini_set("display_errors", "1"); error_reporting(E_ALL); You should in fact have those two settings in your master php.ini so that you don't need to remember to add/remove them from individual files at all.
-
[SOLVED] passing content of $_GET['variable'] to $variable
PFMaBiSmAd replied to mckcd's topic in PHP Coding Help
We give out sarcasm freely when people post two lines of code as being the actual relevant code that is not working and they expect someone else to be able to tell them why what they just posted does not work. -
Just because your web host posted a code example that is using a feature that can be turned off and is therefore not portable between different server configurations, does not mean that you should blindly follow along. If you always use full <?php tags, your php code will always be seen as php code.
-
We reserve sarcasm for those who think the following would be an acceptable exchange of information to find and fix a problem (a Car problem is used as a generic example, but this would apply equally to any situation where you are asking someone else, who is not standing right next to you, for help troubleshooting a problem.) Someone's car has a problem that he/she has noticed when they try to use it and calls a car service center - [HELPER]Hello, can I help you? [OP]My car is not working correctly, what is the problem with it? [HELPER]Well that statement contains zero helpful information, you will need to describe the symptoms that you noticed and give as much relevant information about where you can tell the symptom is occurring at and under what conditions the symptom occurs. [OP]Well, my car is making a noise when I drive it. [HELPER]OK, now I know a noise is occurring when the car is moving. Couldn't you have possibly volunteered that information without me telling you to do so? Without any more information from you about what type of noise or where on the car it is coming from, my best guess answer is that your car is making a noise that you don't like when you drive it and you should probably throw your car away and go get a new one. [OP]OK, I can give you more information that I already knew about the problem but thought that you did not need to know it. It is a dragging noise coming from the back of the car. [HELPER]So, have actually looked at the area where the noise is coming from in case this is a simple problem that you can fix yourself? [OP]No, I was waiting around for someone to tell me to do that. The above assumes that you know nothing about the parts on a car, other than that you can locate where the back of your car is. It concerns using your senses to make observations and communicating relevant information about what you did that caused the symptom and what you observed. The same applies if this was a programming problem. You don't have to be an experienced programmer in order to locate the code that is responsible for the symptom and state what data you were using or what action you were performing that produced the symptom. After you have seen more than a few threads where the OP does not bother to volunteer available information about the problem and does not bother to investigate a problem that is occurring right if front of them, it is real easy to be sarcastic.
-
[SOLVED] passing content of $_GET['variable'] to $variable
PFMaBiSmAd replied to mckcd's topic in PHP Coding Help
You have got to be kidding Your code that is setting $st to a value is inside of a conditional statement that is only true when a form was used to submit data - if ( isset($_POST['submit']) ) That has nothing to do with you using a URL to request the posted code. -
While it is true that AND makes sense if that was a written sentence, it does not make logical sense. Logically, that says I want to match rows WHERE category_name is one value AND category_name is another value at the same time. The condition in the WHERE term must be TRUE for the matching rows. You actually need to use OR. I want to match rows WHERE category_name is one value OR category_name is another value.
-
And unless stated otherwise, all code that is posted comes with an implied disclaimer that it is an untested example showing how you can do something, not that it is actual, final, tested code that can be directly used for any particular purpose. * [* - kind of the same disclaimer that MS ships with its' products, that this is not actual, final, tested code that can be used for any particular purpose.]
-
And if you work out a truth table using OR you will find the it won't work either (because negative logic is being used in the tests, you would need to use AND.) Which is why it is usually best to test for allowed values and do something if a value is one of the possible allowed values.
-
session.save_path must point to a folder that actually exists.
-
Please only use full opening php tags <?php You got caught using the lazy-way short open tags <? that waste several magnitudes more time than they ever saved by not typing the three characters php a few times on any page.