Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 4 FirstFirst 1234 LastLast
Results 16 to 30 of 50
  1. #16
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,408
    Thanks
    68
    Thanked 102 Times in 101 Posts
    It works!! I completely forgot about the gold=gold part of the query.
    By the way the reason it's a second line in the description is for faster testing and also seeing if it works outside of a function.

    #3. That comes later, right now I am just testing things. My PHP.ini file is screwed up and will never produce another error for me, I have to relay on log files. I don't know where to get a fresh copy of it.

    #4. I put ".$char['username']." back in it which is what I originally had.

    --


    Now the only part that is still broken is this:

    PHP Code:
    mysqli_query($link"INSERT INTO rod_myequipment SET username='".$char['username']."' id='".$itemrow['id']."' name='".$itemrow['name']."' type='".$itemrow['type']."' power='".$itemrow['power']."' minlevel='".$itemrow['minlevel']."' class='".$itemrow['class']."'"); 
    It doesn't provide any errors or log file errors. But nothing is inserted into the database??

    EDIT: I just tried this

    PHP Code:
    mysqli_query($link"INSERT INTO rod_myequipment ('username', 'id', 'name', 'type', 'power', 'minlevel', 'class') VALUES ('".$char['username']."' '".$itemrow['username']."' '".$itemrow['name']."' '".$itemrow['type']."' '".$itemrow['power']."' '".$itemrow['minlevel']."' '".$itemrow['class']."'"); 
    and get this error:

    [15-Jun-2014 17:33:26 America/Denver] PHP Notice: Undefined index: username in /home1/newrodga/public_html/courtyard/blacksmith.php on line 64
    Last edited by myfayt; 06-16-2014 at 12:35 AM.
    Been a sign maker for 7 years. My business:
    American Made Signs

  2. #17
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,294
    Thanks
    57
    Thanked 523 Times in 510 Posts
    Blog Entries
    5
    Quote Originally Posted by myfayt View Post
    It doesn't provide any errors or log file errors. But nothing is inserted into the database??
    I've told you how to print your queries using a variable and then run them in phpmyadmin manually previously.

    Why are you now making an issue of not knowing why your query won't run? - Just print the damn thing, open phpmyadmin and run it on the SQL page. It is not hard to do, I really don't know why you refuse to try.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  3. #18
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,408
    Thanks
    68
    Thanked 102 Times in 101 Posts
    That doesn't make any sense. PRINT is the same thing as ECHO for the most part.
    Why would I print it out, copy it, go into PHPmyAdmin and paste it as an sql?
    Last edited by myfayt; 06-16-2014 at 01:43 AM.
    Been a sign maker for 7 years. My business:
    American Made Signs

  4. #19
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,294
    Thanks
    57
    Thanked 523 Times in 510 Posts
    Blog Entries
    5
    Quote Originally Posted by myfayt View Post
    That doesn't make any sense. PRINT is the same thing as ECHO for the most part.
    Why would I print it out, copy it, go into PHPmyAdmin and paste it as an sql?
    Yes it does make sense and I'm not debating print and echo with you - they do the same job and that is not the point of my last comment.

    Print the SQL. Why? Because you can't use php variables in phpmyadmins sql page - you have to supply it with a complete statement with the variables already put there (hence printing it via php).

    Once you have a complete SQL statement to work with, paste it into the SQL page of phpmyadmin and run it. You'll then be able to see if it has updated, inserted or thrown an error - and phpmyadmin is far better at showing you your sql errors.

    I did tell you this previously. If you continue refusing to accept people trying to help you then you may as well give up.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  5. #20
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,408
    Thanks
    68
    Thanked 102 Times in 101 Posts
    I am not refusing to accept help, it just doesn't make sense to me. Basically the way you said it, it looked like every user had to copy the query and paste in phpmyadmin to update their account. It wasn't clear.
    Been a sign maker for 7 years. My business:
    American Made Signs

  6. #21
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,294
    Thanks
    57
    Thanked 523 Times in 510 Posts
    Blog Entries
    5
    Quote Originally Posted by myfayt View Post
    it looked like every user had to copy the query and paste in phpmyadmin to update their account. It wasn't clear.
    No. I've made it clear to you previously that this is for debugging. You simply don't take notice.

    Quote Originally Posted by tangoforce View Post
    Woohoo! Thats much better! Now you need to improve some of your other debugging skills (and you're about to learn one here lol)



    Looking at that, you're passing $link as a parameter but also declaring to php that you're using a global $link too. I'm not quite sure how php would handle that but I'd assume that the global declartion being the latest would render the parameter void.

    What I always do with queries is to put them into a variable like this:

    PHP Code:
    $Query "UPDATE rod_CharName SET gold-".$itemrow['cost']." WHERE username='".$char['username']."'"
    Why?

    Because then I can do this:
    PHP Code:
        mysqli_query($link$Query); 
    Which is far superior for debugging in php because then if the query does not run / affect the database, you can do this:

    PHP Code:
    $Query "UPDATE rod_CharName SET gold-".$itemrow['cost']." WHERE username='".$char['username']."'";

    print 
    $Query .'<br>';

    mysqli_query($link$Query); 
    Then you can visit the webpage, view the source, copy the query and run it directly in phpmyadmin via the sql page of your selected database. This will then result in phpmyadmin giving you an error message to help you work out what is wrong.

    It sounds slightly complicated / long winded but it really isn't. It's about one minutes work - if that and it allows you to make significant leaps forward.




    I made it more than clear that it was a debugging technique for SQL queries. You have deliberately chosen to ignore this advice because you find it easier to get us to fix your code for you instead of making an effort to be a better programmer.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  7. #22
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,408
    Thanks
    68
    Thanked 102 Times in 101 Posts
    If you want to start a reputation war, that's fine. I'll keep throwing it back.
    Been a sign maker for 7 years. My business:
    American Made Signs

  8. #23
    Regular Coder
    Join Date
    Sep 2011
    Posts
    408
    Thanks
    18
    Thanked 26 Times in 26 Posts
    Quote Originally Posted by myfayt View Post
    If you want to start a reputation war, that's fine. I'll keep throwing it back.
    No need to be childish..

    Quote Originally Posted by myfayt View Post
    Basically the way you said it, it looked like every user had to copy the query and paste in phpmyadmin to update their account. It wasn't clear.
    Why would a user be debugging your site? Unless they're a developer or beta tester, I don't see why you would ever think this. If you are giving users access to phpMyAdmin then good luck with whatever you're trying to do..

    The point of debugging is to DEBUG the script and fix it, you don't keep those there. Once you fix your query, you remove the echo/print statement and it doesn't show to the user.
    If I've helped you out, show your appreciation by clicking the "Thanks" link as well as a link below!

    AdFly
    Facebook | Twitter
    Google | YouTube

  9. #24
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,408
    Thanks
    68
    Thanked 102 Times in 101 Posts
    You know how many times over the years he has lowered my reputation? I am sick of it.

    So I print the insert query and get this:

    INSERT INTO rod_myequipment ('username', 'id', 'name', 'type', 'power', 'minlevel', 'class') VALUES ('test' '' 'Wooden Knife' '1' '1' '1' '1'
    Which is all correct, I don't see any problems. So why isn't it inserting?

    -----------

    Also with this code:

    PHP Code:
    $TQuery "INSERT INTO rod_myequipment ('username', 'id', 'name', 'type', 'power', 'minlevel', 'class') VALUES ('".$char['username']."' '".$itemrow['username']."' '".$itemrow['name']."' '".$itemrow['type']."' '".$itemrow['power']."' '".$itemrow['minlevel']."' '".$itemrow['class']."'";
     print 
    $TQuery;
     
    mysqli_query($link$TQuery); 
    I get this error, which doesn't make sense.

    [16-Jun-2014 17:21:14 America/Denver] PHP Notice: Undefined index: username in /home1/newrodga/public_html/courtyard/blacksmith.php on line 65
    Last edited by myfayt; 06-17-2014 at 12:24 AM.
    Been a sign maker for 7 years. My business:
    American Made Signs

  10. #25
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,294
    Thanks
    57
    Thanked 523 Times in 510 Posts
    Blog Entries
    5
    Quote Originally Posted by myfayt View Post
    If you want to start a reputation war, that's fine. I'll keep throwing it back.
    Who said it was me? - Maybe it was, maybe it wasn't. The user CP does not show who gave reputation. Either way perhaps if you did make a little more effort..

    As for throwing it back, the forum doesn't allow you to repeatedly give the same user good or bad reputation.

    Quote Originally Posted by myfayt View Post
    You know how many times over the years he has lowered my reputation? I am sick of it.
    On the contrary, I've not given you negative rep previously so don't bother pinning that on me!

    Quote Originally Posted by myfayt View Post
    So I print the insert query and get this:
    So you're willing to do it when someone winds you up and makes you angry but at all other times you can't be bothered as you'd rather get someone else to do it. Interesting way of working..

    Quote Originally Posted by myfayt View Post
    Which is all correct, I don't see any problems. So why isn't it inserting?
    Have you looked at the mysql_error() function? (Sorry if that scares you - you might have to write two or three extra lines of code!)

    Quote Originally Posted by myfayt View Post
    Also with this code:

    PHP Code:
    $TQuery "INSERT INTO rod_myequipment ('username', 'id', 'name', 'type', 'power', 'minlevel', 'class') VALUES ('".$char['username']."' '".$itemrow['username']."' '".$itemrow['name']."' '".$itemrow['type']."' '".$itemrow['power']."' '".$itemrow['minlevel']."' '".$itemrow['class']."'";
     print 
    $TQuery;
     
    mysqli_query($link$TQuery); 
    I get this error, which doesn't make sense.
    I've explained the undefined index to you previously too. It means that in your array, there is no item with that index key name.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  11. #26
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,294
    Thanks
    57
    Thanked 523 Times in 510 Posts
    Blog Entries
    5





    If you've posted that in phpmyadmin and claim to have no problems or error messages then you are wrong - very wrong.

    Look where the red box is in my screen shot. You have no comma , seperators between those values. phpmyadmin and mysql WILL display an error for this as the SQL cannot be understood. Additionally you also have no closing ) at the end and the php line of code that buils the query confirms both of what I've said.

    You clearly either don't pay attention or you didn't actually run the query via phpmyadmin. Which is it?
    Last edited by tangoforce; 06-17-2014 at 01:33 AM.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  12. #27
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,408
    Thanks
    68
    Thanked 102 Times in 101 Posts
    I am actually pretty good at mysql, but mysqli is a whole new game changer. It's like relearning it over.
    So pasting it into a sql does nothing, errors out with the username thing again. Pointless to try since I already knew that.

    I found out that the query was wrong, it was $char['username'] and then $itemrow['username'], which the second should have been id.

    -So now it's correctly inserting the id properly.

    -I fixed the closing bracket.

    Now no more errors are shown. No error log or query problems or anything. However still nothing is inserted. Where do I go from here?
    Been a sign maker for 7 years. My business:
    American Made Signs

  13. #28
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,294
    Thanks
    57
    Thanked 523 Times in 510 Posts
    Blog Entries
    5
    Quote Originally Posted by myfayt View Post
    I am actually pretty good at mysql, but mysqli is a whole new game changer.
    Not really. You're still using a SQL statement for mysqli. The only difference is that you have a $link parameter first. Thats not a big thing. The real way to use mysqli is to use binded parameters - now that does create extra work and it can be mind bending when you have to use references to variables instead of the actual variables.


    Quote Originally Posted by myfayt View Post
    -So now it's correctly inserting the id properly.

    However still nothing is inserted. Where do I go from here?
    Huh?
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  14. #29
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,408
    Thanks
    68
    Thanked 102 Times in 101 Posts
    This is what it's showing now

    PHP Code:
    INSERT INTO rod_myequipment ('username''id''name''type''power''minlevel''class'VALUES ('test' '2' 'Wooden Knife' '1' '1' '1' '1'
    So everything is right, why isn't it inserting?
    Been a sign maker for 7 years. My business:
    American Made Signs

  15. #30
    Regular Coder
    Join Date
    Sep 2011
    Posts
    408
    Thanks
    18
    Thanked 26 Times in 26 Posts
    Quote Originally Posted by tangoforce View Post
    You have no comma , seperators between those values. phpmyadmin and mysql WILL display an error for this as the SQL cannot be understood ... You clearly either don't pay attention or you didn't actually run the query via phpmyadmin. Which is it?
    There's your answer, again...

    You know, when I used to use mysqli (before I got into codeigniter) I made a handy db_query()function, here's how it goes:
    PHP Code:
    function db_query($query)
    {
        global 
    $mysqli//DB handler
        
    $result $mysqli->query($query);
        if(isset(
    $mysqli->error))
            
    $error trim($mysqli->error);
        if(isset(
    $error) && !empty($error))
        {
            
    $debug debug_backtrace();
            
    print_r($debug[1]);
            
    print_r($debug[0]);
            echo 
    $error;
        }
        return 
    $result;

    Now this is the OOP style, not the one you're using. Therefore you will need to look at how to convert each function to use, but that's 2 functions. If you cant figure that out then you might want to consider a new hobby, it shouldn't be that difficult. However, this contains automatic error reporting, rather than having to put extra lines of code every time (which annoys me). Once it's all done, you can comment it out or do whatever to disable it if you want to.

    It also includes a debug_backtrace(); section, which shows you what was called last to call that, so you know where the error was called.

    You can take this and use it to help with your anti-debugging self, or you can keep questioning your queries and not have any messages telling you what's wrong when your query doesn't work because you reject to adding it in when it happens to debug.
    If I've helped you out, show your appreciation by clicking the "Thanks" link as well as a link below!

    AdFly
    Facebook | Twitter
    Google | YouTube


 
Page 2 of 4 FirstFirst 1234 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •