Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-22-2012, 06:57 PM   PM User | #1
Dan13071992
Regular Coder

 
Join Date: Dec 2010
Location: Kent, UK
Posts: 573
Thanks: 23
Thanked 10 Times in 10 Posts
Dan13071992 is an unknown quantity at this point
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
Dan13071992 is offline   Reply With Quote
Old 11-22-2012, 07:14 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Gots an error on that SQL?
Post a schema dump for that table as well: SHOW CREATE TABLE banned and post that.
Fou-Lu is offline   Reply With Quote
Old 11-22-2012, 07:28 PM   PM User | #3
Dan13071992
Regular Coder

 
Join Date: Dec 2010
Location: Kent, UK
Posts: 573
Thanks: 23
Thanked 10 Times in 10 Posts
Dan13071992 is an unknown quantity at this point
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
Dan13071992 is offline   Reply With Quote
Old 11-22-2012, 08:44 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 11-22-2012, 08:51 PM   PM User | #5
Dan13071992
Regular Coder

 
Join Date: Dec 2010
Location: Kent, UK
Posts: 573
Thanks: 23
Thanked 10 Times in 10 Posts
Dan13071992 is an unknown quantity at this point
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
Dan13071992 is offline   Reply With Quote
Old 11-22-2012, 09:05 PM   PM User | #6
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 11-22-2012, 09:09 PM   PM User | #7
Dan13071992
Regular Coder

 
Join Date: Dec 2010
Location: Kent, UK
Posts: 573
Thanks: 23
Thanked 10 Times in 10 Posts
Dan13071992 is an unknown quantity at this point
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
Dan13071992 is offline   Reply With Quote
Old 11-22-2012, 09:38 PM   PM User | #8
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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?
Fou-Lu is offline   Reply With Quote
Old 11-22-2012, 09:42 PM   PM User | #9
Dan13071992
Regular Coder

 
Join Date: Dec 2010
Location: Kent, UK
Posts: 573
Thanks: 23
Thanked 10 Times in 10 Posts
Dan13071992 is an unknown quantity at this point
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
Dan13071992 is offline   Reply With Quote
Old 11-22-2012, 09:46 PM   PM User | #10
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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?
Fou-Lu is offline   Reply With Quote
Old 11-22-2012, 09:55 PM   PM User | #11
Dan13071992
Regular Coder

 
Join Date: Dec 2010
Location: Kent, UK
Posts: 573
Thanks: 23
Thanked 10 Times in 10 Posts
Dan13071992 is an unknown quantity at this point
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
Dan13071992 is offline   Reply With Quote
Old 11-22-2012, 09:57 PM   PM User | #12
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 11-22-2012, 10:04 PM   PM User | #13
Dan13071992
Regular Coder

 
Join Date: Dec 2010
Location: Kent, UK
Posts: 573
Thanks: 23
Thanked 10 Times in 10 Posts
Dan13071992 is an unknown quantity at this point
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
Dan13071992 is offline   Reply With Quote
Old 11-22-2012, 10:21 PM   PM User | #14
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Define empty? The entire resultset?
Run this: SELECT * FROM `banned` WHERE type = '2'.
Fou-Lu is offline   Reply With Quote
Old 11-22-2012, 10:28 PM   PM User | #15
Dan13071992
Regular Coder

 
Join Date: Dec 2010
Location: Kent, UK
Posts: 573
Thanks: 23
Thanked 10 Times in 10 Posts
Dan13071992 is an unknown quantity at this point
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
Dan13071992 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:26 AM.


Advertisement
Log in to turn off these ads.