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 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts

    first insert works, second doesn't even though only a light difference

    hey everyone,

    Ive been having trouble with this bit of code, the first insert works fine, however, the second doesnt insert at all, even though there is only 2 differences, those being instead of 1 on the type, its a 2 and on the length, instead of being a 0 its a generated number:

    PHP Code:
    $minutes $lengthminutes 60;
    $hours $lengthhours * (60 60);
    $days $lengthdays * ((60 60) * 24);
    $months $lengthmonths * (((60 60) * 24) * 30);

    $totalban $lengthminutes $lengthhours $lengthdays $lengthmonths;
    $total time() + ($minutes $hours $days $months);


    $utime=date("Y-m-d h:i:s"$total);

    if (
    $totalban == 0) {
    $message"You have now banned $banplayer Permenantly!";



    $sqlinsertban2 "INSERT INTO `banned` 
    (`username`, `by`, `type`, `reason`, `length`) 
    VALUES 
    ('$banplayer' , '$fetch->username' , '1' , '$reason' , '0')"
    ;

    mysql_query$sqlinsertban2 ) or die( mysql_error() );  

    }elseif (
    $totalban != 0){

    $sqlinsertban "INSERT INTO `banned` 
    (`username`, `by`, `type`, `reason`, `length`) 
    VALUES 
    ('$banplayer' , '$fetch->username' , '2' , '$reason' , '100')"
    ;

    mysql_query$sqlinsertban ) or die( mysql_error() ); 

     

    $message"You have now banned $banplayer until <b>$utime</b>! || $total";




    if anyone has any ideas, that would be much appreciated.

    thanks

    Dan
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Gots an error on that SQL?
    Post a schema dump for that table as well: SHOW CREATE TABLE banned and post that.

  • #3
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    i cant see an error there, its really weird because its identical apart from those 2 little things



    the dump didnt work, it wouldnt show all of it to me, i hope this is enough
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    I assumed as well that you have determined that it even enters that conditional block?
    Print out the $sqlinsertban and make sure you give it conditions to enter that conditional. When it does, take that and run that in the SQL client to verify that it works.

  • #5
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    i have tested it, over and over, i just made it print what it was trying to process and this is what i got:

    Code:
    INSERT INTO `banned` (`username`, `by`, `type`, `reason`, `length`) VALUES ('BFR' , 'DOS1392' , '2' , 'test ban works 2' , '1361393385')
    however, it doesnt actually insert into the database, but changes the overhead value in the database table to a higher value, if that makes any difference?
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    And when you run that in the client it produces no insertion and no error?
    Your resulting query doesn't match what you have here either. You have hardcoded entries for the fifth parameter, but in the result you have a string which appears to be a timestamp. Which begs the question though as to why that's a text datatype.
    If you get no error and the record doesn't appear, something is wrong with your MySQL server. It needs to reply with something, either a successful insertion or a failure notice.

    The overhead in PHPMyAdmin isn't relevant to this query, but it is affected by update and deletions and will affect searching. Running an OPTIMIZE query will resolve that. That refers to the empty space caused by the deletion of records or drastic alterations on an update. Insertions I don't believe have any affect on the overhead, though I could be wrong.

  • #7
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    when running the second insert in the mysql server, it says its successful, however, it does not insert into the database.

    The reason its hard coded in the first insert is because its ment to just be a 0, so yes i could change it to leave it at default, if thats what you mean?

    but as for why its not working, ive tried changing from varchar to int, and that stil didnt work, however if i change out $total in the second query, and put in any other number for example "2" it will insert fine :S
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    I'm not talking about the 0, I'm talking about the 100.
    How many records does PHP state has been entered? Also, you've checked that its not paged beyond the default 30 records I think it is that PHPMyAdmin shows?

  • #9
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    o i am very sorry, the 100 isnt the correct part of code, i do believe i have lead you slightly astray with that, where that 100 is it should be $total: this is my new update code, however, this has the same problem on the second insert, however if i change $total to a number, it works, its just when its $total it doesnt:

    PHP Code:
    $minutes $lengthminutes 60;
    $hours $lengthhours * (60 60);
    $days $lengthdays * ((60 60) * 24);
    $months $lengthmonths * (((60 60) * 24) * 30);

    $totalban $lengthminutes $lengthhours $lengthdays $lengthmonths;
    $total time() + ($minutes $hours $days $months);


    $utime=date("Y-m-d h:i:s"$total);

    if (
    $totalban == 0) {
    $message"You have now banned $banplayer Permenantly!";



    $sqlinsertban2 "INSERT INTO `banned` 
    (`id`, `username`, `by`, `type`, `reason`) 
    VALUES 
    ('' , '$banplayer' , '$fetch->username' , '1' , '$reason')"
    ;

    mysql_query$sqlinsertban2 ) or die( mysql_error() );  

    }elseif (
    $totalban != 0){

    $sqlinsertban "INSERT INTO `banned` 
    (`id`, `username`, `by`, `type`, `reason`, `length`) 
    VALUES 
    ('' , '$banplayer' , '$fetch->username' , '2' , '$reason' , '$total')"
    ;

    mysql_query$sqlinsertban ) or die( mysql_error() ); 

     

    $message"You have now banned $banplayer until <b>$utime</b>! || $total<br><br><br>$sqlinsertban";




    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #10
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    How are you checking to see if records are inserted? You're actually issuing a select query for them (not relying on PHPMyAdmin overview) right?
    You can verify the number of inserted rows. PHPMyAdmin or a client will return that directly and PHP can pull using mysql_affected_rows. Do these show that one record has been inserted?

  • #11
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    i am checking in php my admin (should i not be?) it does not show up on there, however, when i run the first insert afterwards, the auto inc jumps one, for example it could start on 1, that 1 works, then the second one doesnt because its the 2nd insert query, then if i try the first query again the auto inc will be 3 not 2, if that make sense
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #12
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Yeah your fine then. Issue a SELECT statement instead; sounds to me that you have filtering in place on the output table that only checks for a specific enum type.

  • #13
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    ive made a select query that will display all of the banned inputs, but its empty, any ideas?
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #14
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Define empty? The entire resultset?
    Run this: SELECT * FROM `banned` WHERE type = '2'.

  • #15
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    MySQL returned an empty result set (i.e. zero rows). ( Query took 0.0002 sec )


    i ran your string and that came up, so in answer, yes the result set is empty, even though i have not deleted anything yet, and it is less than 30 in the result by the way.

    this is what came up in the var dump:

    Code:
    string(136) "INSERT INTO `banned` (`username`, `by`, `type`, `reason`, `length`) VALUES ('TestAccount' , 'DOS1392' , '2' , 'fgfdg' , '1361399158')"
    incase that helps i dont know.

    i can post my entire code if you would like?
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags


  •  
    Page 1 of 2 12 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
    •