-
Posts
16,734 -
Joined
-
Last visited
-
Days Won
9
Everything posted by PFMaBiSmAd
-
Here are some things not to do - 1) You don't use mysql_real_escape_string() on the whole query string as that would break the sql syntax of the query. You use mysql_real_escape_string() on each individual piece of string data that is put into the query. 2) mysql_real_escape_string() returns the escaped string, so the way you are using it doesn't do anything because you are not assigning the result that it returns to anything. 3) You don't create a separate table for each user as that creates a database management nightmare. You must query your user table to get the user id before you can even find the user's data. What you do need to do is use one table to hold all the Transactions with a column for the user id. 4) If you do have a legitimate reason to get the id from the INSERT query, you don't need to execuite a SELECT query to do it. You can use mysql_insert_id()
-
Remove the left over - mysql_free_result($res); statement that is at about line 10 in the code.
-
Edit: You will need to add an $i variable that gets incremented to the following code. Edit2: I have updated the posted code to include the appropriate counters. If we assume that the logic of what you are doing makes sense in your application, the following code executes the queries you have in your logic - <?php include("secure/database.php"); // Include Database Connection File... $q = "SELECT * FROM `accountinfo_db` ORDER BY `strikeaction` ASC";//Select all from account table order by strike action ascending . $res = mysql_query($q) or die(mysql_error()); if(mysql_num_rows($res)){ // players exist in the table $i = 1; // the rank counter while($player=mysql_fetch_array($res)){ // While Loop mysql_free_result($res); $id = securevar($player['id']); // ID $user = securevar($player['username']); // Username $q = "UPDATE `accountinfo_db` SET `strikerank` = '$i' WHERE `id` = '$id'"; // Update account set strike action equals $i where account is account. if(mysql_query($q)){ // query execuited without error and probably updated the row (unless the value was the same before/after...) echo "Strike Rank set to $user as ".number_format($i)."!"; // Echo This. } else { // query failed with an error // put your error reporting/logging code here... } $i++; } $q = "SELECT * FROM `accountinfo_db` ORDER BY `defenceaction` ASC"; // Select all from table order by defenceaction ascending. $res = mysql_query($q) or die(mysql_error()); $i = 1; while($player=mysql_fetch_array($res)){ $id = securevar($player['id']); $user = securevar($player['username']); $q = "UPDATE `accountinfo_db` SET `defencerank` = '$i' WHERE `id` = '$id'"; if(mysql_query($q)){ echo "Defence Rank set to $user as ".number_format($i)."!"; } else { // query failed with an error // put your error reporting/logging code here... } $i++; } $q = "SELECT * FROM `accountinfo_db` ORDER BY `covertaction`, `anticovertaction` ASC"; $res = mysql_query($q) or die(mysql_error()); $i = 1; while($player=mysql_fetch_array($res)){ $id = securevar($player['id']); $user = securevar($player['username']); $q = "UPDATE `accountinfo_db` SET `covertrank` = '$i' WHERE `id` = '$id'"; if(mysql_query($q)){ echo "Covert & Anti Covert Rank set to $user as ".number_format($i)."!"; } else { // query failed with an error // put your error reporting/logging code here... } $i++; } $q = "SELECT * FROM `accountinfo_db` ORDER BY `msaction` ASC"; $res = mysql_query($q) or die(mysql_error()); $i = 1; while($player=mysql_fetch_array($res)){ $id = securevar($player['id']); $user = securevar($player['username']); $q = "UPDATE `accountinfo_db` SET `msrank` = '$i' WHERE `id` = '$id'"; if(mysql_query($q)){ echo "Mothership Rank set to $user as ".number_format($i)."!"; } else { // query failed with an error // put your error reporting/logging code here... } $i++; } $q = "SELECT * FROM `accountinfo_db` ORDER BY `msaction`, `strikeaction`, `defenceaction`, `covertaction`, `anticovertaction`, `msaction` ASC"; $res = mysql_query($q) or die(mysql_error()); $i = 1; while($player=mysql_fetch_array($res)){ $id = securevar($player['id']); $user = securevar($player['username']); $time = time(); $q = "UPDATE `accountinfo_db` SET `rank` = '$i', `lastTurnTime` = '$time' WHERE `id` = '$id'"; if(mysql_query($q)){ echo "Overall Rank set to $user as ".number_format($i)."!"; } else { // query failed with an error // put your error reporting/logging code here... } $i++; } } else { // there are no rows/players in the table echo "No players exist, no data to process..."; } ?>
-
In addition to everything else that has been pointed out that is makes no sense in the code, the logic test in the for() statement is backwards AND since the for() loop is attempting to iterate over the result set from the first query AND that is what the while() loop does, there's no point in having that for() loop in the code at all.
-
NEWB Q - Reading Records from mySQL but No Output
PFMaBiSmAd replied to EmperorJazzy's topic in PHP Coding Help
^^^ Computers only do exactly what their code tells them to do and we only see exactly the information you supply in your posts. When you don't post accurate code and data, it causes wild goose chases fixing things that are not actually present. -
NEWB Q - Reading Records from mySQL but No Output
PFMaBiSmAd replied to EmperorJazzy's topic in PHP Coding Help
if(mysqli_num_rows($result)){ // at least one row, process the data from the query while ($row = mysqli_fetch_array($result)) { echo $row['Full_name']; } } else { // query matched zero rows echo "Sorry, there is no data to display!"; } I also see that your first code used $row['Full_name'] while your later code used $row['Fname']. If your php code is running at all (the following won't help with fatal parse errors in your main file), you can put the following two lines of code in your file to set the error_reporting/display_errors settings at runtime - ini_set("display_errors", "1"); error_reporting(-1); -
NEWB Q - Reading Records from mySQL but No Output
PFMaBiSmAd replied to EmperorJazzy's topic in PHP Coding Help
Either your query is matching zero rows or there is no column named Fname in your table. Are you doing this on a system with error_reporting set to E_ALL (or a -1) and display_errors set to ON so that all the php detected errors will be reported and displayed? This would produce an error if the query returns a row but $row['Fname'] does not exist. You can and should use mysqli_num_rows() to find out if there are any rows returned by a query and display an appropriate message if there are not. -
NEWB Q - Reading Records from mySQL but No Output
PFMaBiSmAd replied to EmperorJazzy's topic in PHP Coding Help
Does the 'view source' show your </body></html> tags? -
NEWB Q - Reading Records from mySQL but No Output
PFMaBiSmAd replied to EmperorJazzy's topic in PHP Coding Help
Either php is not installed on your server or your file name does not end in .php or you are browsing directly to the file on your computer instead of using a URL (such as http://localhost/your_file.php ) in your browser's address bar. -
NEWB Q - Reading Records from mySQL but No Output
PFMaBiSmAd replied to EmperorJazzy's topic in PHP Coding Help
And the 'view source' of that page is????? The reason I keep asking what you are getting for the actual output to the browser is that will pin down where exactly the problem is. -
NEWB Q - Reading Records from mySQL but No Output
PFMaBiSmAd replied to EmperorJazzy's topic in PHP Coding Help
If the 'view source' of the page in your browser shows the 'php code', then you got caught using php's lasy-way short open tags - <? You should only use full opening php tags - <?php -
If you need to repeat the <option></option> selections, why not just produce that part of your output in a php variable and then simply echo the contents of that variable every time you need it?
-
What is the difference bertween writing ... and ...
PFMaBiSmAd replied to pioneerx01's topic in PHP Coding Help
Here's a monkey wrench thrown in - I'm going to guess that in your actual code you are having a problem with, someone used a defined constant for the array index name and in the case where you put the quotes around it, your code actually stopped working? A more reasonable answer: As already suggested, you should be developing and debugging your code on a system with error_reporting set to E_ALL (or to a -1) and display_errors set to ON so that you would be seeing all the errors that php detects. -
What is blank, the whole page? The (your name goes here) part? What exactly do you see in front of you and what is the current code that produces the page?
-
You actually need A, MX, and SPF dns zone records that identify your host's mail server as being the mail server that corresponds to your domain name. Something similar to - A mail.your_domain.com = ip address of your host's mail server MX 20 mail.your_domain.com. SPF - see this link - http://en.wikipedia.org/wiki/Sender_Policy_Framework
-
Foreach for iterating mysql result, or other alternatives
PFMaBiSmAd replied to wepnop's topic in PHP Coding Help
There's no way to use a foreach() loop because a foreach() loop iterates over an array. Queries don't return an array, they return a result resource that must be accessed using mysql_fetch_xxxxx() or mysql_result() statements. -
Have you checked if the actual src="..." value being output to your browser is what you think it is? And have you forced your browser to clear any cached (broken) content since you changed the code?
-
The src="..." attribute in an <img> tag IS A URL because it is the browser that fetches and displays the image.
-
Foreach for iterating mysql result, or other alternatives
PFMaBiSmAd replied to wepnop's topic in PHP Coding Help
Sorry to jump in, but I'm glad you finally shared what you are doing, because the code you are using now is very very inefficient - 1) It is re-evaluating mysql_num_rows() every pass through the for() statement, 2) It is re-evaluating mysql_num_rows() inside the loop to break from the loop, but that is pointless because that is what the loop is already doing, 3) It is using mysql_data_seek() inside the loop, but that is pointless because mysql_fetch_object() advances the result pointer. You can replace all that with the following that just about every php/mysql book or tutorial would have shown - while($object = mysql_fetch_object($result)){ } -
You would probably have more success searching for - php weekly schedule php weekly schedule script Since that is what you actually stated you wanted as your output.
-
$details is a string and string data must be enclosed in single-quotes in a query, otherwise your string looks like a mathematical expression. $sql = "UPDATE usertable SET uSkillsMax='$details'"; Edit: Don't make this harder than it really is.
-
Because LINK is an invalid method, the form defaults to GET method, i.e. the data is submitted in the URL/LINK.
-
You are expecting someone who is not standing right next to you to be able to tell you what is wrong with your code without knowing what your code actually is. There's at least 6 different things your code could be dong wrong that could cause this symptom. It would take seeing all your page 2 code and the code on the page that is sending the email for someone in a forum to be able to help you with what is wrong with your code.
-
simultaneous cross database connection
PFMaBiSmAd replied to Muddy_Funster's topic in PHP Coding Help
The query is executed on and by the database server, so no, this is not possible as it would require the database server where the query is being executed to have the ability to connect to and access the data on the other database server. -
PHP can only loop through 280 mysql UPDATES - HELP
PFMaBiSmAd replied to byroncoolie's topic in MySQL Help
Have you investigated where the 280 limit is occurring at? It is probably in the maximum length of the URL that the browser will send and the web server will accept. You should be using the POST method for a large amount of data.