-
Posts
16,734 -
Joined
-
Last visited
-
Days Won
9
Everything posted by PFMaBiSmAd
-
There is no loop. In looking at your posted code, how can you tell what statements are where. Your indention of blocks of code is confusing at best.
-
If your registration script outputs a message - "You have been registered! ..." with a link to a login page, what makes you think your registration script is not working?
-
Forget that you ever saw the global keyword. Functions should return (i.e. via a return $userID; statement) the value the function produces. You even used the word 'return' in your question. By returning the value, you can then use the value any way you want. You can assign it to a variable $userID = getuserid();, echo it echo getuserid();, or use it as a call time parameter in another function call if(in_array(getuserid(),$some_array)){ As to the actual problem in your code, the global $userID; statement must come before you reference the $userID variable so that php knows you are referencing not a local variable but the global one (or more simply, functions should return the value they produce and not even mess with the global keyword.)
-
In the case of the $password variable, NOT using $password in the query statement will prevent your script from working. If you are going though the trouble of putting lines of code in your script, you must make sure that each line of code contributes something to the goal you are trying to solve and that the line of code is needed. You also need to escape each piece of string data that you are putting into the query statement, to both prevent sql errors when that data contains sql special characters and to prevent sql injection by hackers. Posting the actual error message(s) would be needed to pin down what is causing the problem. You have more than one die() statement and no one here can tell you what the current problem is without knowing at which point the logic is detecting an error.
-
Populating a table with gaps in the SQL results
PFMaBiSmAd replied to idontkno's topic in PHP Coding Help
Both the code that litebearer posted and the line of code I posted will do what you want. However, your description you just wrote is confusing rows with columns (columns go across the page and rows go down the page.) I suggest you actually try what has been shown or suggested by litebearer and myself to see if you can get the output that you want. -
You wouldn't move anything between tables when its status changes. You need one table the holds the definition of your schedule - id, date/time, location, home team id, away team id, status (none, in progress, final, delayed, canceled, forfeit), and anything else you can think of that is unique and specific to any one match. The id would identify each match in the schedule. Other than adding new entries to this table for each new season, you would only need to update the status and perhaps some of the other fields (i.e. the date, time, or location if a match got moved to a different date, time, or location.) You would have a second table to hold scores. It would have columns for the match_id, home team score, away team score, and probably columns to hold the initial creation date/time, last update date/time, and id of the last person that created/updated it. You would insert a row in this table for each match that is complete. If you are fixing errors in the values, my previous discussion above would apply. To get the results for any match, list of matches, or range of matches, you would do a LEFT JOIN of the first table with the second table.
-
For all problems, you need to find the actual cause of the problem before you can fix it. Otherwise you just end up fixing symptoms and the actual problem still remains. Without any specific information to pin down the problem to a specific cause, you could have php code that is executing too many queries on each page request (executing queries inside of loops are what typically get people into trouble with their web host), in which case the php code and possibly the database tables many need to be fixed; one or more queries might need to be optimized, by adding appropriate indexes; the amount of data in the table or in each row is the cause of the problem and the table(s) or rows may need to be partitioned differently. So, short-answer, someone would need to have all the relevant php code and all the database information (structure, amount of rows in the table, amount of data and its type in each row) in order to just find the actual cause of the problem. For all we know you could be storing image data in your database and the site is an image hosting site or you are executing hundreds of queries on each page request.
-
Populating a table with gaps in the SQL results
PFMaBiSmAd replied to idontkno's topic in PHP Coding Help
The code you posted last, is putting the three values (result1,result2,result3) from each database row into one <td></td> cell in the html table row. Is that what you want to do? That doesn't match anything you have stated or shown. What you have implied you want is each of those three result values (some of which might be empty or null) to be in its own <td></td> table cell so that each database table row makes one html table row. This is what I replied about and would work if you were putting <td></td> tags around each value - echo "<td>{$c101[0]}</td><td>{$c101[1]}</td><td>{$c101[2]}</td>"; So far, your description and examples don't show what you are doing, what data you have and don't have, what result you are getting, and what result you expect. Either show real or mock-up data for enough rows in your database table and exactly where you want each value from each database row to be output in the html table. -
I'll make a separate reply for this. Where exactly are you trying to set the two session variables from? A log in script? In which case you expect them to already have values in them when you visit that page and do you also want to limit access to that page only if a person is logged in? Your current code is setting them via hard code values from hidden fields in your form, so they won't be set until after the form has been submitted the first time. Did you do it this way to compensate for some other symptom associated with the session variables?
-
^^^ EXACTLY what does that mean and at EXACTLY what point does the problem occur at? Are the links to the images present, correctly formatted, and have the correct path and image name? What does an actual link to an image look like? When you click on a link, is the image broken or is there some other error occurring? The code you posted doesn't have a session_start() statement in it so setting or referencing $_SESSION variable will only work on that page. You are also unconditionally assigning some post data to session variables, so any time that page gets requested via a get requested (i.e. you first browse to the page), the post variables will be empty and the session variables will be assigned empty values too. Also, you would need to post a working sample files.xml for any one here to directly help. We're not going to sift through the logic tying to figure out what data the code is using as an input, which itself might be where the problem lies. Supply enough information so that someone could actually see what the code is supposed to be doing without spending more time to reverse engineer it and synthesize test data than what it would probably take to solve the problem.
-
mysql_real_escape_string only when needed?
PFMaBiSmAd replied to joecooper's topic in PHP Coding Help
There's also a magic quotes setting (magic_quotes_runtime) that escapes data when it is retrieved from a database. -
That's a bad design. Your table that defines the schedule should be different from the table recording the scores. Anyway, you would need to test if the submitted form field is an empty string. You would then form an UPDATE query that sets the INT field to a sql NULL keyword. Your INT field needs to be defined as not not-null (i.e. uncheck the not-null option). You also cannot have any single-quotes around the NULL keyword inside the query statement (the query would fail with an error for an INT field, perhaps depending on your database strict mode setting) - <?php $hgoals = $_POST['home_goals'] == '' ? 'NULL' : intval($_POST['home_goals']); $query = "UPDATE your_table SET your_column = $hgoals WHERE some_where_condition"; Edit: I just tested and if strict mode is off for your mysql server and your query has single-quotes around the numerical value - $query = "UPDATE your_table SET your_column = '$hgoals' WHERE some_where_condition";, then the update trying to set it to the a null will result in setting the field to a zero value.
-
^^^ You shouldn't have records in a table until the actual data exists and has been inserted. If someone did insert a record incorrectly (i.e. a score got entered for a match that hasn't been played yet), you would either delete the record entirely to remove it or if the actual data for the wrongly inserted record now exits, update the record to hold its actual value.
-
Populating a table with gaps in the SQL results
PFMaBiSmAd replied to idontkno's topic in PHP Coding Help
The array for each row that mysql_fetch_array returns will have entries for each column that is listed in your select statement, even if the value the query produces is a null value or an empty string. If a html table cell is empty, you should output a as the content in the <td></td> tags for that cell so that the browser will render the cell with any borders or style you are using, but that would not cause the the example 3rd cell value to be in the 2nd column in the output. About the only way you could get the 3rd cell's value to be in the 2nd column is if you are not outputting the <td></td> tags for each cell. If you are only outputting two <td></td> <td></td> for that row, there's no way that the browser will ever know the second one is for the 3rd column in the table. What's your actual code that is producing the incorrect output table. -
LOL, I was just looking through the remainder of the code, and it is including itself - if ($do[0] == "buy") { include('shops.php'); buy(); } elseif ($do[0] == "buy2") { include('shops.php'); buy2($do[1]); } elseif ($do[0] == "buy3") { include('shops.php'); buy3($do[1]); } elseif ($do[0] == "sell") { include('shops.php'); sell(); } If you are already running the code on that page, why are you including it? It already exists.
-
You are including the posted code more than once. You either have an include/require statement for that file inside of a loop or in more than one other file that is being included, or one of the files you are including in that file is also including that file.
-
Curl is used to make requests to (generally other) servers. If you are using it to make a request to a server different from your own server (the normal case), there is no connection or relationship between the session on your server that was started by the browser and a session the curl request establishes on the other server. If you are using curl to make a request back to the same server your script is running on, you are doing something the hardest and slowest way possible. You should be directly accessing code or data on your server through the file system, not by making http requests back to your own server. Among other things, an incorrect understanding of how something your code is using works or an assumption about an initial condition that isn't being satisfied. It's impossible to tell without seeing the code that reproduces the symptom. In programming, due to its general purpose nature and multiple ways of accomplishing any task, there is not a one to one relationship between any symptom and what is causing it. Six different people could have written code that implements the same application and they could all be getting the same exact symptom, but the actual cause could be different in each case because of differences in their actual code, data, and methodology used to implement the application.
-
Or you can do this directly in your query when you select the field value (which will be about 8 times faster than using php code) - http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format
-
trying to avoid session variables being destroyed
PFMaBiSmAd replied to imsewhi's topic in PHP Coding Help
Is this correct - your index.php page correctly shows the right check boxes as being checked, right before you press the submit button and goto the payment gateway page? The code you did post for index.php is not testing if there was a form submission to it by your previous page, so any time it gets requested, it will unconditionally assign values to the $_SESSION variables. When it gets requested without any $_POST data, the $_SESSION variables will be assigned null/empty values (or perhaps your code later on in the index.php page is clearing those session variables.) I doubt your payment gateway is making a GET request to your index.php page, but it could. It's more likely your browser is requesting the index.php again or you have some code on that page that is clearing the session variables instead of testing them (one = sign instead of two == signs) or your thankyou.php page is redirecting back to the index.php page at some point, or you have some rewrite rules that are causing the index.php to be requested again. Your code that assigns the values to the $_SESSION variables needs to be inside of a conditional test so that it will only be executed as the result of a form submission. This will fix the most immediate problem, but you need to determine why and how the index.php page is being requested again, to prevent unnecessary requests and to fix the actual problem in case it is causing other unexplained operations. -
Can a server answer a GET request with a POST response?
PFMaBiSmAd replied to jhsachs's topic in PHP Coding Help
Yes, fix what is causing the problem. In programming, people regularly spend a HUGE amount of time trying to fix SYMPTOMS, when often, once the actual problem is known, there is a simple fix that will work for all cases, instead of adding more and more code to handle special case conditions. -
If this topic is solved, the forum's Topic Solved button is at the lower-left-hand side of the page.
-
You are going to need to reread the information at the link I posted. Just using MAX() will get you the maximum value for that single field. All the other values will be from the first row encountered in the group.
-
LOL, three different people posted code showing how you would call your function and either assign the value it returns to a program variable or directly echo the value that your function returns.
-
Where exactly are you calling the createTheVariable() function at (the code you posted only contains the function definition) and assigning the value it returns to the the $var variable? You would need a statement like, $var = createTheVariable(); for your existing code to work. Also, you apparently don't have php's error_reporting set to E_ALL and display_errors set to ON in your master php.ini on your development system to get php to help you. You would be getting an undefined variable error message when you try to echo $var, that would alert you that $var has not been assigned a value.
-
trying to avoid session variables being destroyed
PFMaBiSmAd replied to imsewhi's topic in PHP Coding Help
That there are the correct number/name of $_SESSION variables on your thankyou.php page, indicates that they have been set at some point and do actually exist, with the wrong or no values, on your thankyou.php page. You need to find out at what point in your code they are set to the correct values and at what point they are not. The problem will lie somewhere between those two points.