Is this code correct[PHP]?

Status
Not open for further replies.

Toxic0n

Well-known member
1,109
Can anyone help me with this?
Code:
Blight: its soo damn hard to make changes
Toxic0n: of course...what did you want me to implement a fucking modular design?
Session Close (Blight): Tue Apr 02 13:03:44 2002


Session Start (ICQ - 114778500:Blight): Tue Apr 02 13:03:58 2002
Blight: LOL
Session Close (Blight): Tue Apr 02 13:03:59 2002


Session Start (ICQ - 114778500:Blight): Tue Apr 02 13:04:02 2002
Blight: no
Toxic0n: thought so
Session Close (Blight): Tue Apr 02 13:04:07 2002


Session Start (ICQ - 114778500:Blight): Tue Apr 02 13:04:19 2002
Blight: I just am too outta the loop
Toxic0n: AND you're fat
Session Close (Blight): Tue Apr 02 13:04:31 2002


Session Start (ICQ - 114778500:Blight): Tue Apr 02 13:04:35 2002
Blight: $query11 = "select * from Users where UserID=\"$defendID\"";  
$result11 = mysql_query($query11) or die('error');  
$row11 = mysql_fetch_assoc($result11);  
$attackname = $row11['Username'];
Blight: why is that giving me an error
Toxic0n: if (!$result =mysql_quoery($query11)){
 die('error');
 }
 you're retarded
Blight: you spelt query wrong
Blight: and that statement is not wrong it works on all my other scripts
Toxic0n: you're an idiot, mmmmkay?
Blight: you are
Toxic0n: and 'im adding that to my quotes file
Toxic0n: and that statement is not wrong it works on all my other scripts
Toxic0n: lol
Blight: how is it wrong?
Toxic0n: because it doesnt even make sense!
Blight: yes it does
Blight: and the change u made did nothing
Toxic0n: you cant just go
 $a=$b or die('blah');
Blight: yes u can
Toxic0n: NO YUO CANNOT!
Toxic0n: if it works ill be the guy in the corner with his foot in his mouth
Blight: Heres a line from a script I wrote  
$result = mysql_query($query) or die("Query failed line 15");
Blight: the script worls fine
Blight: I got it from the coders that help me sometimes
Toxic0n: whatever....there's no if statement,so you are not evaluating the $result and im surprised that code doesnt rape your dog, steal your shoes and reatrt windows
 
What the hell? That's an IM chat transcript dude. I am guessing you want the following code looked at:

Code:
$query11 = "select * from Users where UserID=\"$defendID\"";
$result11 = mysql_query($query11) or die('error');
$row11 = mysql_fetch_assoc($result11);
$attackname = $row11['Username'];
if (!$result = mysql_query($query11)) { die('error'); }

The following should work, I haven't tested it though. And you really should incorporate some error checking / handling into your code.

Code:
$query11 = "select * from Users where UserID=\"".$defendID."\"";
$result11 = mysql_query($query11) or die("Error: ".mysql_error()."");
$row11 = mysql_fetch_assoc($result11);
$attackname = $row11['Username'];
if (!$result = mysql_query($query11)) { die("Error: ".mysql_error().""); }
 
Sorry if I have missed something glaringly obvious, but did running both sections of code and looking at the results seem too crazy for you two?

Anyway, the first block of code is as perfect as bad code can be and will work as expected. If the query fails then it will die spouting "error" to the user, using the mysql_error() function will however provide more useful information than "error".

The second piece of code may work, I amn't sure -- but the following implementation is more "the norm":
Code:
$result11 = mysql_query($query11);
if(!$result11) {
   echo "error";
   exit();
}
 

Toxic0n

Well-known member
1,109
I don't mean to be rude and presumptious, but yes it is :rolleyes:
The code is running on my home server. So that would involve:
Typing out all the code.
Uploading it on the server trhu a goddamn company firewall.
Testing it out for typos and stuff.
Fixing the errors.
Uploading it again.
Checking to see if it works.
Getting the damn proxy to refresh the page.
Checking the output
AND, it might work, but I want to know if it will give me the same results. That's why I asked the questions on forums where intelligent Arsians hang out.
Happy?
EDIT: Nice edit. You actually answered my question, instead of a sarcastic comment.
 
I updated my original message when I realised the original reply was, well, useless. Now, not to sound rude or try to pull rank to a "senior" forum member but unless something is unattainable or you do not know the answer, then I don't think other forum members should need to do work that you could very easily do. Also, let us go through your checklist:

Typing out all the code. -- that was already done in anyway.
Uploading it on the server trhu a goddamn company firewall. -- uploading it will take the same time whether it's through a firewall or not, and neither of those code segments is bigger than 1KB.
Testing it out for typos and stuff. -- it's a ~10 line code block, there shouldn't be errors unless you are completely stupid, even if there are it will take 2 seconds to spot them.
Fixing the errors. -- see above.
Uploading it again. -- edit it on the server, your FTP client probably (90%) has a feature that allows you to edit rmote text files.
Checking to see if it works. -- how hard is typing http://serverip/test.php?
Getting the damn proxy to refresh the page. -- F5 is your friend.
Checking the output -- yeah, because actually looking at a screen requires effort.


Edit: The original comment wasn't sarcastic, I was actually wondering was there something stopping you just testing the code or had you already tried testing it to no avail. Now I realise it was pure laziness.
 

Toxic0n

Well-known member
1,109
Originally posted by Orange Rhino:
I updated my original message when I realised the original reply was, well, useless. Now, not to sound rude or try to pull rank to a "senior" forum member but unless something is unattainable or you do not know the answer, then I don't think other forum members should need to do work that you could very easily do. Also, let us go through your checklist:
Well, 'senior' != smarter, postcount!=pensu size, but we all know that

Typing out all the code. -- that was already done in anyway.
Partially

Uploading it on the server trhu a goddamn company firewall. -- uploading it will take the same time whether it's through a firewall or not, and neither of those code segments is bigger than 1KB.
I cant use FTP directly, i have to use www.web2ftp.com, which is pretty slow
Testing it out for typos and stuff. -- it's a ~10 line code block, there shouldn't be errors unless you are completely stupid, even if there are it will take 2 seconds to spot them.
Sometimes there are small errors that are hard to spot, even in 10 lines of code. You with your 2 years of PHP coding should know that.
Fixing the errors. -- see above.
See above
Uploading it again. -- edit it on the server, your FTP client probably (90%) has a feature that allows you to edit rmote text files.

See above
Checking to see if it works. -- how hard is typing http://serverip/test.php?

Not hard, but pretty slow
Getting the damn proxy to refresh the page. -- F5 is your friend.

Not if the web page is sored on the proxy
Checking the output -- yeah, because actually looking at a screen requires effort.
Not really. Not for me, anyway. YMMV.
Edit: The original comment wasn't sarcastic, I was actually wondering was there something stopping you just testing the code or had you already tried testing it to no avail.
Your comment did sound sarcastic.
Now I realise it was pure laziness.
Sure
EDIT: I volunteer full time for the Canadian Cancer Society, so I really didn't want to waste a lot of work time doing all of the above, when I knew somebody here could give me the correct answer.
 

Clintology

Ars Legatus Legionis
15,566
Subscriptor
Originally posted by Toxic0n:
I don't mean to be rude and presumptious, but yes it is :rolleyes:
The code is running on my home server. So that would involve:
Typing out all the code.
Uploading it on the server trhu a goddamn company firewall.
Testing it out for typos and stuff.
Fixing the errors.
Uploading it again.
Checking to see if it works.
Getting the damn proxy to refresh the page.
Checking the output
AND, it might work, but I want to know if it will give me the same results. That's why I asked the questions on forums where _intelligent_ Arsians hang out.
Happy?
EDIT: Nice edit. You actually answered my question, instead of a sarcastic comment.

WAHHHHHHHHH WAHHAH WHAHAHAHHHHHH

=clint
 
I amn't going to continue this disagreement / argument / debate / whatever because it is going nowhere and there is no real right or wrong in it. One thing though ...

Originally posted by Toxic0n:

Testing it out for typos and stuff. -- it's a ~10 line code block, there shouldn't be errors unless you are completely stupid, even if there are it will take 2 seconds to spot them.

Sometimes there are small errors that are hard to spot, even in 10 lines of code. You with your 2 years of PHP coding should know that.
A MySQL connection string, database selection, query and query check is an incredibly easy piece of code unless you are joining queries and tables and such, which you were not doing here. It is a very easy code block and errors should be minimal at best and even if they are they cannot be that hard to spot in such a simple code block. I amn't arguing with you or insulting your intelligence, just my view of the situation.
 
Status
Not open for further replies.