...

View Full Version : While Problems



kochier
12-02-2008, 02:11 AM
if(isset($_POST['update']))
{
$Name = $_POST['Name'];
$Name = preg_replace("/[^a-zA-Z]/", "\n", $Name);
$Name2 = first_words($Name, 0, 1);
$Name3 =first_words($Name, 1, 1);
$Nam = strtolower($Name2);
$Nam2 = strtolower($Name3);
if (preg_match('/([a-z])\1/i', $Name2) and empty($Name3))
{
include 'library/opendb.php';
mysql_select_db('greendoor') or die('Cannot select database');
$result = mysql_query("SELECT Word1 FROM greendoor") or die(mysql_error());
while($row = mysql_fetch_array($result)){
$Word1 = $row['Word1'];
if ($Word1 == $Nam)
{
$result2 = mysql_query("SELECT Word1, Word2, Plural FROM greendoor WHERE Word1 = '$Nam'") or die(mysql_error());
while($row = mysql_fetch_array($result2)){
$Word2 = $row['Word2'];
$Plural = $row['Plural'];
{
if ($Plural == '0')
{
echo 'There is a '. $Nam. ' through the Green Glass Door, but there are no '. $Word2. '.';
}
else
{
if ($Plural == '1')
{
echo 'There are '. $Nam. ' through the Green Glass Door, but there is no '. $Word2. '.';
}}}}}
else
{
echo $Nam.' will go through the Green Glass Door.';
$fname = 'library/greendoor.php';
$fhandle = fopen($fname,"r");
$content = fread($fhandle,filesize($fname));
$content = $content .'<br />' .$Name;
$fhandle = fopen($fname,"w");
fwrite($fhandle,$content);
fclose($fhandle);
$to = 'test@test.com';
$subject = 'Green Door Word';
$message = "$Name";
$headers = 'From: test@test.com';
mail($to, $subject, $message, $headers) or exit('mail fail');
}}}
else
{
if (preg_match('/([a-z])\1/i', $Name2) and preg_match('/([a-z])\1/i', $Name3))
{
echo $Name2 .' ' .$Name3 .' will go through the Green Glass Door.';
}
else
{
if (preg_match('/([a-z])\1/i', $Name2) or preg_match('/([a-z])\1/i', $Name3))
{
if ($Nam == 'double' and $Nam2 == 'letters')
{
echo "Congratulations, you've beat the Green Glass Door. Now try the <a href =" .'"willitgothrough107.php">Red Plastic Window</a>.';
}
else
{
echo $Name2 .' ' .$Name3 .' will both go through and not go through the Green Glass Door.';
}}
else
{
if (!empty($Name3))
{
echo $Name2 .' ' .$Name3 .' will not go through the Green Glass Door.';
}
else
{
if ($Nam == 'branches')
{
echo 'There are no branches through the Green Glass Door, but there are trees.';
}
else
{
if ($Nam == 'heaven')
{
echo 'There is no heaven beyond the Green Glass Door, but there is a hell.';
}
else
{
if ($Nam == 'microsoft')
{
echo 'There is no Microsoft beyond the Green Glass Door, but there is Yahoo and Google.';
}
else
{
if ($Nam == 'yesterdays')
{
echo 'There are no yesterdays beyond the Green Glass Door, but there are tomorrows.';
}
else
{
if ($Nam == 'yesterday')
{
echo 'There is no yesterday beyond the Green Glass Door, but there is a tomorrow.';
}
else
{
if ($Nam == 'circles')
{
echo 'There are no circles beyond the Green Glass Door, but there are balls.';
}
else
{
if ($Nam == 'circle')
{
echo 'There is no circle beyond the Green Glass Door, but there is a ball.';
}
else
{
if ($Nam == 'colour')
{
echo 'There is no colour beyond the Green Glass Door, but there is green.';
}
else
{
if ($Nam == 'plastic')
{
echo 'There is no plastic through the Green Glass Door, but there is glass.';
}
else
{
echo $Name2 .' will not go through the Green Glass Door.';
$fname = 'library/greendoor.php';
$fhandle = fopen($fname,"r");
$content = fread($fhandle,filesize($fname));
$content = $content .'<br />' .$Name;
$fhandle = fopen($fname,"w");
fwrite($fhandle,$content);
fclose($fhandle);
$to = 'test@test.com';
$subject = 'Green Door Word';
$message = "$Name";
$headers = 'From: test@test.com';
mail($to, $subject, $message, $headers) or exit('mail fail');
}}}}}}}}}}}}}}
?>


I hate to post such a huge chunk of code, but it's really frustrating me right now, and I can't seem to figure it out. You can see it in action here (http://absurdity981.com/willitgothrough106.php). Basically if I put hello in it should go through, if I put trees through it will go through, and since there's a database entry for trees, it will say there's trees but no soil. I had it working perfectly but I made a minor change, and now it's not working, it keeps repeating the same line twice, if it will go through the door. I'm been moving things around for the last hour and can't figure out what I messed up, I was just about to make a back-up after making these changes but haven't gotten to it, so there's no backup to go to. Please help me I just want this working again.

Fou-Lu
12-02-2008, 03:15 AM
I'm not sure I understand the problem, I used trees and this is what I got back:
trees will go through the Green Glass Door.There are trees through the Green Glass Door, but there is no soil.

That looks correct to me.

For you're code though, you may want to run that through a formatter.
Seeing something like this:


}}}}}}}}}}}}}}

makes me cringe, and does make debugging more difficult (since its hard to tell what bracket is ending what instruction). Of course, if its just an edit back to add PHP code tags for example (which will lose the formatting), just ignore this.

kochier
12-02-2008, 04:27 AM
Well it should say "There are trees through the Green Glass Door, but there is no soil." if trees wasn't in the database it should say "trees will go through the Green Glass Door." It says both, when before it did not. And all of those end brackets are why I was editing it, I've had it working for words that go through, and was about to start on words that don't go through, when I messed it all up. If you notice most of those end brackets at the end are caused by all the if statements I have in my code for every case, I am in the middle of updating it so I just use a database, and get rid of all of those if statements. I believe the problem is further up, with the while statements, something seems to have been placed in the wrong place there, but can't seem to figure out what.

Fou-Lu
12-02-2008, 04:46 AM
Format you're code; you'll probably be able to find the problem then.
All I can tell you for sure is that this:


echo $Nam.' will go through the Green Glass Door.';

Is within an else block which I believe is for the first preg_match. If this is the phrase you're not supposed to be getting, you'll need to see why its in there and how the processing instructions are working to get there.

kochier
12-02-2008, 08:56 AM
It should be after the else statement to the datebase check, so if the word is not in the database it defaults to this. If the word is a single word and goes through it goes through the pregmatch block. Which then has an if statement that checks if the word is in the database, at which case it pulls up the other word and displays it like trees, soil. But if the word is not in the database it will go to the default else statement, and say trees can go through.

EDIT: I figured out what I changed. I added another word to the database, so the while loop runs once for the first word in the database, and then for the next word. That's why it was working earlier, trees was the only entry in the database.

EDIT 2: I've tried changing

$result = mysql_query("SELECT Word1 FROM greendoor") or die(mysql_error())

$result = mysql_query("SELECT Word1 FROM greendoor WHERE Word1 = $Nam1") or die(mysql_error())
So it won't loop through all of the words, it only selects the word it needs. And it does, the problem is it doesn't to anything for words that go through and aren't in the database.

kochier
12-03-2008, 04:39 PM
I realize now I'm calling the data from the database wrong, and probably using the while a bit off too. I've tried changing things around with varying results, but I can't seem to get what I want.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum