Page 1 of 1
Find the mistake PHP
Posted: Fri Aug 12, 2011 3:20 pm
by Losdivinos
Hi.
I got this idea yesterday. This is mainly just for fun and for practice.
You will have to find the mistake in the PHP code above, and when that is done you should post a code with 1 mistake.
<?
include 'connect.php';
$getinfo="SELECT ALL FROM users WHERE userid='4' AND name='gaydyde'";
$getinfo2=mysql_query($getinfo) or die("Could not get gaydude's info!");
?>
Have fun!
Re: Find the mistake PHP
Posted: Fri Aug 12, 2011 3:29 pm
by hallsofvallhalla
ha this will drive my eyes nuts!
should be * not ALL, the gaydyde vs gaydude wont matter unless his name is suppose to be dude
how about some js my bullet code for checking collisions for asciiwars, means this is open book if you know what i mean, but the answer is easy...
Code: Select all
if ((bullet[j].x > offsetmap + 485) || (bullet[j].y > 500) || (bullet[j].x < offsetmap + 5) || (bullet[j].y < 225))
{
bullet[j].destroy();
} // end if
for (k = 1; k < l; k++)
{
if (bullet[j].hasHit(goblin[k]))
{
bullet[j].destroy()
goblin[k].destroy();
spawn1curhp = spawn1curhp - 2;
spawn1GUI.resizeTo(spawn1curhp,10);
} // end if
}
}
Re: Find the mistake PHP
Posted: Fri Aug 12, 2011 4:46 pm
by Losdivinos
There is 1 more than needed of these! ---->
}
<php
echo "<div><table><tr><td width='400 px'><b><h1>Accname</h1></b></td><td width='400 px'><b><h1>Clubname</h1></b></td></tr>";
$query = "SELECT * FROM msn";
$result = mysql_query($query);
$num=mysql_numrows($result);
$i=0;
while ($i < $num) {
$accname = mysql_result($result,$i,"accname");
$vname = mysql_result($result,$i,"vname");
$vid = mysql_result($result,$i,"vid");
$i++;
echo "<tr><td><h2> " . $accname . "</h2></td><td><h2><a href='
http://blabalbal.com/clubs/" . $vid . "'> " . $vname . "</a></h2></td></tr>";
}
?>
Re: Find the mistake PHP
Posted: Fri Aug 12, 2011 5:19 pm
by 62896dude
I found 3! (there may be more):
- You didn't end your <table> tag
- It is supposed to be mysql_num_rows, instead of mysql_numrows
- The <a href> that you used near the end should have ' and ', not ' and "
<?php
$a = 5;
$b = 9;
$c = 3;
$d = 4;
if (($a + $b) = $c){
echo "L0lz, ! 0wn n00bz l!k3 !tz m4 j0b!";
}
elseif{
echo "!b0j 4m zt! 3k!l zb00n nw0 ! ,zl0L";
}
?>
*HINT* There are 2 total mistakes in this one
Re: Find the mistake PHP
Posted: Fri Aug 12, 2011 5:42 pm
by Nexus
you don't need an if in elseif{ and I don't think you need the parentheses around $a+$b
here is one
Code: Select all
class Code {
$languagename
}
function newLanguage($newname)
$this->languagename = $newname;
}
four errors in this one

fixed an error XD
Re: Find the mistake PHP
Posted: Fri Aug 12, 2011 6:15 pm
by Xaleph
- No semi colon ending,
- $this is not allowed in the function like that, so neither is languagename a valid argument.
- No opening bracket
Also, on the code for 92dude you forgot:
if (($a + $b) = $c)
The = operator is out of scope, it should have been ==. A single = means the sum of $a and $b is now $c, which in turn will throw an extra error since you cannot assign a $var to nothing.
Ok
Code: Select all
<?php
final class TestWorker implement Worker {
private static $workerThread = null;
function __construct(){
$this->workerThread = new Thread;
}
}
?>
There`s more then 1 error to be found, good luck

Re: Find the mistake PHP
Posted: Fri Aug 12, 2011 6:17 pm
by 62896dude
The other error in mine wasn't the parenthesis, you need two = signs
As for yours, I am not too great with JS (as you know XD)
But, I believe that there should be a ( before newLanguage and a ) before the final }
There should be a { at the end of the line with the function
and maybe it needs to be class.Code?
I'm not sure if even one of those are right

but, they are my four guesses!
OOPS, me and Xaleph uploaded at the same time, look at the errors he pointed out, not mine XD
Re: Find the mistake PHP
Posted: Fri Aug 12, 2011 7:33 pm
by Torniquet
i dont know a whole lot about OOP, but im guessing 'implement' should be 'extends'
either that or $this->workerThread = new Thread; should be $this->workerThread = new Thread(); as your declaring a new class?
Code: Select all
$query = "
SELECT
stats.*,
users.username AS username,
users.postcount AS postcount
FROM stats
LEFT JOIN (
SELECT
users.username AS username,
users.postcount AS postcount
) AS users ON stats.user_id = users.user_id
WHERE
stats.user_id = 4
LIMIT 1
";
enjoy :p
1 error (i think lol

)
Re: Find the mistake PHP
Posted: Sat Aug 13, 2011 1:07 am
by Xaleph
The FROM clause for users is missing.
On my code, there`s several things wrong.
Implement should have been implement
s ( extends is something different ) Implements means that a class is using an interface
The static $var is all cool, except in the code has no function whatsoever.
First of, the final prefix means no vars in the class can be changed on runtime in this case ( this can be modified obviously )
Also, even if the class was not final, you cannot access a static property by using $this, $this refers to 'that' object, yet static means it`s a class value, not an object value, so you cannot access a static value. To modify statics in an object you need to use the self keyword ( which refers to the class, not the object )
Anyway, in the code it wouldn`t matter since the class was final to begin with.
A more simple one:
Code: Select all
function fibo($n){
if($n <= 2) return $n;
else
return fibo($n-2) + fibo($n - 1);
}
Note: there are no errors to be found ( hopefully since it`s 3 am haha ) but the trick is to optimise the code

Good luck!
Re: Find the mistake PHP
Posted: Sat Aug 13, 2011 2:18 am
by 62896dude
I'm gonna guess that maybe you can change ($n-2) to ($n - 2)? I have no clue though, I've been sitting here for at least 5 minutes thinking of an algorithm that might simplify the math, but I've got nothing XD