Click to See Complete Forum and Search --> : Weekly Problem


abc123
07-11-2006, 06:20 PM
Hello all,
Have been enjoying the phpbuilder community for quite some time now and must say it is a great resource for learning php. I do have an idea and it would be interesting to see what the people here think.

I visit a website for scripting quite a bit and every week they have a puzzle to try and solve. Basically they show you a script that doesn't work and ask you why and how to solve the problem. These can be logical errors and syntax errors. After the week is up they give you the answer. Sounds a bit stupid I know but it does make it interesting to see problems made up by experienced people as they tend to know the ones that cause most problems.

To be fair I know that the forum is full of problems. But being able to solve a weekly problem set by someone with experience can help with confidence in the less experience who can take several days to solve the problem and then be satisfied at the end of the week by seeing the solution.

This would of course take some effort for the experienced people to do, but looking through the forum they all seem happy to help others and might even enjoy setting challenges.

Just an idea.

Any thoughts?

Elizabeth
07-11-2006, 08:18 PM
We tried something similar before, but it was more like a coding challenge rather than a problem solving or "what's wrong with this script". Then the winner of the challenge was responsible for writing the next one.

But your idea is a bit simpler so it may go farther. I like it! :)

So who wants to go first?

Shrike
07-12-2006, 08:39 AM
Ok lets start simple. A function which inserts some data into a database and a statement to check if the insert worked.

// URL: /index.php?table=foo&foo=1
function insert()
{
extract( $_POST );
$query = 'INSERT INTO $table VALUES ( $foo )';
$result = mysql_query( $query );
$id = mysql_insert_id();
}
if( $id = insert() )
{
echo 'Inserted succesfully';
}

There are 3 syntax errors and 3 security problems to find :evilgrin:

madwormer2
07-12-2006, 09:23 AM
Err, what do we do when we've solved it, because if we post it here then the next person doing it can cheat :p

Shrike
07-12-2006, 09:44 AM
Well if they cheat, they haven't learned anything...which kind of defeats the purpose :)

abc123
07-12-2006, 10:12 AM
If people were interested then it would have to be a sticky thread where only a moderator could post. Suggestions for problems could come from other people but ultimately it has to have only one person being able to post a problem and then a week later to post the solution. If it isn't done like this then yes anyone could post problems/solutions all day long. Isn't that what we do anyway? hmmm...

The point of the weekly problem would be to give people a challenge and a chance to solve a problem.

Basically just something to pass the time.

Good to see some people are interested though.

vaaaska
07-12-2006, 02:22 PM
Why not simply setup a new site specifically for this very one thing? And certainly, you could make it an xml feed so people could just grab it and put it on their own site as well.

halojoy
07-12-2006, 03:28 PM
A function which inserts some data into a database and a statement to check if the insert worked.
// URL: /index.php?table=foo&foo=1
function insert()
{
extract( $_POST );
$query = 'INSERT INTO $table VALUES ( $foo )';
$result = mysql_query( $query );
$id = mysql_insert_id();
}
if( $id = insert() )
{
echo 'Inserted succesfully';
}
Hey, you have several errors in your code here!
I suggest you learn more about PHP.
There are plenty of good basic tutorials, if you search the net.

Dont give up, PHP is fun, when you know a bit more.
:)

madwormer2
07-12-2006, 03:32 PM
Either you're retarded or sarcastic.

I vote sarcastic retard.

pohopo
07-12-2006, 04:21 PM
if($obj_beer->_temperature() != 'cold') {
$obj_beer->refrigerate($int_hours);
} else {
$obj_beer->drink()
}
So find the error with this.

Weedpacket
07-12-2006, 07:22 PM
Easy; it's doesn't take into account the user's locale.

vaaaska
07-12-2006, 08:35 PM
Easy; it's doesn't take into account the user's locale.

Yeah, in or out of the lampshade.

Weedpacket
07-13-2006, 06:23 AM
Yup, me and the Mud Hutter.

pohopo
07-13-2006, 02:43 PM
This is more a logical error then syntax. And the error is that you should NEVER not have cold beer!! :D (okay, i am cheesy)

Weedpacket
07-14-2006, 03:09 AM
Ah; so that code should be replaced byassert('$obj_beer->_temperature()=="cold"');
$obj_beer->drink();But like I said, that's locale-dependent.