Cant Find The Error

free web hosting
Free Web Hosting > Computers & Tech > Programming > Scripting > PHP

Cant Find The Error

mingkus
In this code I want to retrieve the energy and max energy of a players account, then add 8% to energy of maxenergy, hen if energy is bigger than maxenergy, energy is then made equal to maxenergy. Then the database is updated.
I don't understand why it's not working.

CODE
$query=mysql_query("SELECT MAX(id) as maxid FROM `accounts` LIMIT 1");
$row = mysql_fetch_assoc($query);
$id = $row['maxid'];

$query = "SELECT * FROM `accounts`";
$result=mysql_query($query);
while ($row=mysql_fetch_assoc($result)) {

$energy = $row['energy'];
$maxenergy = $row['maxenergy'];

}
for($i=1; $i<="$id"; $i++) {
$query = "SELECT * FROM `accounts` WHERE (id) = '".$id."'";
$result=mysql_query($query);
$addenergy = (0.08 * $maxenergy);
$energy = ($addenergy + $energy);

if($energy > $maxenergy) {
$energy = $maxenergy;
}
$query = "UPDATE `account` SET (energy) = '".$energy."' WHERE (id) = '".$id."'";
$result = mysql_query($query);
echo" The energy script worked!";
}

 

 

 


Reply

Feelay
maybe if you tell us what error messages you get. it would be easier for us to help you smile.gif?

EDIT: I THINK that you can't make the energy get higher, or? well, if thats your problem, you should try to add this:

CODE
$energy = ($addenergy += $energy);


If thats the fault, then that should be the solution. And remember to write what your problem is, and NOT ONLY what you want to accomplish. because we can hardly guess what your problem is.

And another thing tongue.gif the "the energy script worked" echo, wont work as you think. it will execute whatever happens, becuse you have no if statement tongue.gif

 

 

 


Reply

wutske
A very usefull trick to debug sql query is to add 'or die(mysql_error())' after every query you make, this way your script will stop once SQL throws an error and the error will be shown to you.

eg.
CODE
$result = mysql_query($query) or die(mysql_error());


Another usefull trick is to echo variables so you can actualy see their values instead of guessing and hoping.

Reply


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

Similar Topics

Keywords : error

  1. Boot Error On Customized Kernel [solved]
    (2)
  2. Php Configuration Error?
    (6)
    Hey guys, I'm trying to set up a dummy server on a virtual machine. PHP, HTML, MySQL are all
    working. However, I ran into a slight PHP error as shown below: Nexenta Core 1.0.1 (OpenSolaris
    20080311, b85) PHP 5.1.2 MySQL 5.0.22 Quicksilver Forums 1.4.2 Any help will be appreciated.
    xboxrulz....
  3. Ffow: Frontlines: Fuel Of War
    Error Report (2)
    I bought this game about two days ago for $29.99 and I decided to install it on my computer today.
    I finished the installation and when I try to play, it pops up an error report. I had just recently
    downloaded latest drivers for my graphics card...... I tried this on my other computer too. The
    same error report popped up. I am furious because I think I have just wasted 30 bucks...... If you
    have this game, are you having the same problems and how can you fix this problem? Thanks in
    advance...... -NelsonTR4N /cool.gif" style="vertical-align:middle" emoid="B)" bo....
  4. Cpanel Error When Loggin In...
    Unable to access my cPanel... (5)
    Hey all... I was trying to get into my cPanel to try to move some files, and it entered this page
    error: Not Found The server was not able to find the document (./frontend/rvblue/index.html) you
    requested. Please check the url and try again. You might also want to report this error to your
    webhost. cpaneld/11.23.6 Server at www.skemb.astahost.com Does this mean anything or make any sense
    to any of you!!?? Any kind of response is appriciated... Thanks all! - skedad -....
  5. Purchase Credit Error
    (0)
    Whenever i enter purchase credits i get this CODE 404 : Not Found The server has not found
    anything matching the Request-URI. No indication is given of whether the condition is temporary or
    permanent. The 410 (Gone) status code SHOULD be used if the server knows, through some internally
    configurable mechanism, that an old resource is permanently unavailable and has no forwarding
    address. This status code is commonly used when the server does not wish to reveal exactly why the
    request has been refused, or when no other response is applicable. does any one else ge....
  6. Error Connecting To Domain
    (2)
    It seems my site is not coming up, I use my own domain name and have set the nameservers and I even
    just double checked it. I am getting this error message CODE Error: Requested content
    'gr33nn1nj4.com/' cannot be accessed. Server data timeout. (and www. respectively), I
    double checked to make sure I didn't mistype my domain name by double checking the account info
    ( the stuff it said to save after making the account /smile.gif" style="vertical-align:middle"
    emoid=":)" border="0" alt="smile.gif" />) any ideas on how to resolve this?....
  7. Common Ftp Server Error Codes
    error codes that you come across (0)
    QUOTE ~~~~~~~~~COMMON FTP ERROR CODES~~~~~~~~~~ # Description 110 Restart marker reply. In
    this case, the text is exact and not left to the particular implementation; it must read: MARK yyyy
    = mmmm where yyyy is User-process data stream marker, and mmmm server's equivalent marker (note
    the spaces between markers and "="). 120 Service ready in nnn minutes. 125 Data connection already
    open; transfer starting. 150 File status okay; about to open data connection. 200 Command okay.
    202 Command not implemented, superfluous at this site. 211 System status, or sy....
  8. Mysql Storage Engine Error 28
    (5)
    Hello, On my website and forum, SDeckNET, the mySQL database is not working. I get the error "mySQL
    error: Got error 28 from storage engine mySQL error code: Date: Wednesday 02nd 2008f July 2008
    05:33:53 AM" from my forum. From what I know, error 28 means I'm out of disk space, how can this
    be? I was never told of a mySQL space limitation and all these cases of downtime are destroying my
    site's memberbase. EDIT: It now seems PhpMyAdmin is down too, with the error: "Warning:
    session_write_close() : SQLite: session write query failed: database is full in /usr/l....
  9. I Have An Error With My Mysql Connection
    mysql connection error (7)
    ok so here's my web page... http://lacrossems.t35.org/ it only lags cause its trying to
    connect to the my sql server...i followed this guide
    http://forum.ragezone.com/showthread.php?t=387249 and when i edit my config.php to my host and
    login info i always get the error cannot connect to the database here is my config.php if you can
    help me CODE $host = 'CENSORED';                // my host $host =
    'righto';       // my database username $host = 'CENSORED';   // my database
    password $host = 'odinms';       // my datab....
  10. Linux Basic Command - For Storing Compilation Error To File
    (1)
    Ex: Compiling a cpp file using a basic command " g++ filename.cpp " and to run the program use
    ./a.out , Then to store the compilation error to text file use this command. g++ test.cpp >
    log.txt log.txt contains the compile time errors. ....
  11. Strange Error When Trying To Install Fedora Core 9
    (6)
    Hi all, I tried to install Fedora Core 9 in a VmWare virtual machine under WinXP. I downloaded the
    DVD ISO image and proceeded with the installation. When the process was started since about a
    minute, the following error did show: "The file evince-2.22.1.1-1.fc9.i386.rpm cannot be opened.
    This is due to a missing file, a corrupt package or corrupt media" Fine, I told to myself,
    let's download the ISO image again, this time from a different server, just in case. No joy,
    same error. Tried another couple of times, each one using a different server for the download. Sa....
  12. My First Google Error
    (8)
    Today in computing at school! We were using google. We typed in ''Poll scripts''
    It came up with a pop up saying ''Sorry Google does not currently allow this
    search'' I then clicked refresh & it worked! Have errors happened to you ....
  13. Php Error-where To Put "?>"
    (2)
    lol....lately i have many problems in writing my scripts and i dont know if i should create post
    only for purpose so ppl can help me or should i create many post like i am doing right now...i am
    NOT making this to get many credits...i am doing it because i need help and many people here help
    me! CODE if ($_GET !='race'){ Who do you wanna race?           Derbi Senda 50
         Honda NS 50 R      Suzuki ZR 50      Yamaha DT 50 MX      Aprilia RS 50      - ?        
    } i have this code...if i put after it i get QUOTE Parse error: syntax....
  14. Sql Syntax Error [corrected]
    apostrophes missing (2)
    QUOTE #1054 - Unknown column 'Eggie' in 'where clause' i get that error when
    i type this in MYSQL CODE select bike from members where username=Eggie i have column
    bike,members and username... and i have information in every of those columns... but why does it say
    that there is no COLUMN because i said i want info from row where column 'username' is
    'Eggie' btw-YAY..my 101 post EDIT:sorry...i just solved it i forgot to put apostrophes
    CODE select bike from members where username='Eggie' ....
  15. Java Applet Loading Error
    (5)
    I'v just started to study JAVA. And I borrowed a book, Great Ideas in Computer Science with
    JAVA. But I can't loading any applet written on the text. I use firefox to load applet. Does
    anyone know why the applet can't be loaded? sample code is below. /laugh.gif"
    style="vertical-align:middle" emoid=":lol:" border="0" alt="laugh.gif" /> CODE import
    java.awt.*; public class HelloWorld extends java.applet.Applet { TextField m1,m2; public void
    init() { m1 = new TextField(60); m2 = new TextField(60); m1.setText("H e l l o W o r l d !");
    m2.setText("T....
  16. Lost Connection To Mysql ,..., System Error: 111 In
    (3)
    While I was trying to connect to my database or even create one using PhP mySQL I was given the
    followoing error: Lost connection to MySQL server at 'reading initial communication
    packet', system error: 111 in Has somebody encontered a similar report? I have my database
    created using the cpanel together with a user name and password. I wonder if it is a server issue?
    What can you do if you have not access to the configuration files?....
  17. Bid For Power Opengl Error [solved]
    (6)
    While installing Bid for power(stand alone quake 3 mod) i got the Quake 3 console blue screen like
    you got when usually starting to play quake 3 and this comes out and stops! QUOTE Q3 1.32
    win-x86 Oct 7 2002 ----- FS_Startup ----- Current search path: \\INES\SharedDocs\My Music\Bid For
    Power\bfpq3\UltimateHellPackfix.pk3 (1457 files) \\INES\SharedDocs\My Music\Bid For
    Power\bfpq3\UltimateHellPack.pk3 (5697 files) \\INES\SharedDocs\My Music\Bid For
    Power\bfpq3\map-turniej.pk3 (48 files) \\INES\SharedDocs\My Music\Bid For
    Power\bfpq3\map-thecellgames.pk3 (41 files) \\....
  18. Warning: Mysql_num_rows()
    What is the error :S (1)
    Hey! I've made a register script.. Some time ago it worked. And I ain't sure if I changed
    something since then.. The error I am getting is this: Warning: mysql_num_rows(): supplied argument
    is not a valid MySQL result resource in /home/feelay/public_html/regcheck.php on line 31 Here is
    the code on theese lines: CODE $sqlCheckForDuplicate = "SELECT username FROM user WHERE username
    = '". $username ."'";                 if( mysql_num_rows( mysql_query(
    $sqlCheckForDuplicate ) ) == 0 )         {             $sqlRegUser =     "INSERT INTO            ....
  19. Error While Activing Hosting Account - Resolved
    (7)
    This happen when I try to active my hosting account.. Remembering that I had an account here and
    was the same domain......
  20. Itunes Album Art
    Unknown error -609 (6)
    Ok, for Christmas, I got an iPod nano 3rd generation. (The wide one). The day after, I downloaded
    iTunes 7.5 (Only took about 4 hours with my dial-up). Anyway, I put all my songs onto it, but I
    wanted the album art, too (My Cover Flow's a little... Bland). So I tried downloading it with
    itunes, but I get an error... When I check the "Automatically download missing album art" checkbox
    in the preferences, nothing happens, nothing pops up. When I click "Get Album Artwork", I get an
    error box that says "Could not get artwork for some Albums". Under that is a little bo....
  21. Bsod Error & It's Causes
    (6)
    Introduction: One of the most dreaded error messages for a Windows user is
    the blue screen, or the Blue Screen of Death (BSOD) as it is popularly known, which suddenly pops
    up informing you that something is seriously wrong with Windows. What this screen essentially
    means is that Windows has crashed and needs to reboot to recover . Usually, you will be able to
    recover and continue without any problems Problems causing BSOD : The BSODs are
    generally associated with five problems faced by Windows: QUOTE ❍ S....
  22. Mysql Connect Error, Too Many Connections.
    (1)
    Just to begin with I want to say that I am not here necessarily to complain about it lol. I'm
    not sure but if my site is possibly helping to contribute to the problem, I'd like to know if
    anyone knows any good articles or tutorials that might have information on what to look out for that
    could contribute to these sort of problems. I know my site may not have anything to do with it (as
    I don't think it is overly popular or anything or even close), but knowing what to look out for
    when messing with PHP/mySQL would be great. I personally haven't found too....
  23. Cursor-for-loop Out Of Bounds Error
    error in PLSQL code (8)
    I have been working on some code that has really caused me to loose few of my hair due to excessive
    scratching. Here is the problem I am facing: I have table, on which I have a cursor defined:
    CODE   CURSOR cur_some_record IS     SELECT *       FROM some_loaded_table      ORDER BY
    some_sort_column; I am later using it in the PLSQL code as follows: CODE -- Some
    intializing code   FOR some_record IN cur_some_record   LOOP     -- Do processing on each of the
    record     -- referencing it as some_record.   END LOOP; So, it is a pretty straight forward r....
  24. Dreamweaver 8 Issue
    This error is bugging me and it wont go away. (9)
    Well i have been using Dreamweaver for a long time now and no problems. I tried to install it on my
    new laptop and it ran fine until i opened a document. When i opened a file in the split or design
    mode it has this error: QUOTE The following translators were not loaded due to errors: ASP.htm:
    has configuration information that is invaild. XSLT.htm: has configuration information that is
    invaild. It does this with every file this error does not come up with code mode only the design
    and split. Can someone please help because it always says this two times and it s....
  25. Windows XP Error: Explorer Crashes While Drag & Drop
    (14)
    Dear Friends When using WINDOWS XP, and while in Windows Explorer, very often when attempting to
    drag a file from Explorer to the folder you want to move it to, an error message will pop up saying:
    Windows Explorer has encountered a problem and needs to shut down...which usually freezes up
    Explorer..and you have to open it up and try to do the function of dragging the file again. As
    well...in some cases, when that error shows up, almost instantly after closing it, which usually
    means you have to do the Control-Al-Del thing opening the task list in order to close the fol....
  26. Grub Error After Reinstalled Winxp
    (11)
    I have Windows XP and Fedora 4 installed in my PC. Grub is the boot loader. Today, I decided to
    reinstall Windows XP. After the installation finished, I boot into fedora 4 with rescue disk. then..
    chroot, grub-install /dev/hda, reboot. but I could not boot into the system. It just show me this,
    grub> There is no option for me to choose. (It uses to have a list.) Then I fdis /mbr, root
    (hd0,0), set(hd0) yes, the grub menu is back. But cannot boot into both system (windows xp and
    Fedora 4) fc4: invalid compressed format (err=1) xp:disk error ,press any key to restart ....
  27. Help Needed: Monitor Out Of Timing
    Out of Timing error with certain apps (6)
    I've decided to convert to an LCD monitor over the CRT, which I believe to be infinitely better.
    Anyway there are certain applications that, when I start up, the monitor goes black and a message
    says: Out of Timing H: 43 Hz V 27kHz. Or something like that. Any help? Drivers are up to date, and
    I think it's not influenced by resolution. I'd like to get this to work because it was
    rather large investment. Thanks.....
  28. Send Mail Through Outlook Express
    Error - Connected / Won't Send (7)
    I have not been able to send mail through my e-mail account. I have my own domain and my current
    email settings are as follows: Incoming Mail: mail.vjgamer.com Outgoing Mail: mail.vjgamer.com
    Account Name: vjgamer (This is my default account/cPanel name.) Password: Same as my cPanel Password
    Outgoing Mail Server - My server requires authentication (Checked) Settings... - Use same
    settings as incoming mail server I have checked my MX settings in my cPanel. It was set to
    vjgamer.com, so earlier today I changed it to mail.vjgamer.com. This did not work, I am gettin....
  29. Error In Installing MySQL Server
    MySQL server cannot be started (6)
    I try to upgrade my MySQL server from 4.018 to 4.1.10a. Firstly, I downloaded mysql-4.1.10a (not the
    essential one) for win XP Then I install the new version after the old version was uninstalled.
    After the installation process, Instance Configurator comes up to help for the configuration. But an
    error occured when it try to start the MySQL service. Error messageis "cannot create windows
    service for MySQL. Error:0" So my MySQL server cannot be started. It is running win XP on my
    computer. Does anybody can tell me what is wrong?. Thanks (sorry for my bad english)....
  30. Error 406 - Problem In My Phpbb Forum
    Actually a problem with Apache (8)
    When I post the message in my forum contant the word "system" it can't work and said the HTTP
    error 406. I add three Mod : attach mod 2.3.11 , cash mod 2.2.2 , pay money mod 1.0.7 phpBB
    verison 2.0.12 my forum http://siuwing.astahost.com/testmod and then I also setup a model forum
    by cPanel , the error of posting also occur -> http://www.siuwing.astahost.com/testmod2/ the
    model forum havent adding any mod what is the problem ...? /sad.gif' border='0'
    style='vertical-align:middle' alt='sad.gif' /> ....

    1. Looking for error






*SIMILAR VIDEOS*
Searching Video's for error
advertisement




Cant Find The Error