Page 1 of 3

[Solved] Code problem

Posted: Tue Aug 09, 2005 10:07 am
by bla5e
The Function:

Code: Select all

<?php
echo ("<td width=20%>  <a href=\"view.php?yes=".$data['id']."\">YES</a> / <a href=\"view.php?id=".$data['id']."\">NO</a></td>");
?>
The 'Yes' Page/code: * This is the part that wont display *

Code: Select all

<?php
if ("yes" == "".$_GET['id']."") {
		$con = mysql_connect($server, $user, $password) or die ('I cannot connect to the database because: ' . mysql_error()); 
		mysql_select_db($database);
		echo mysql_error();
		$sql = "SELECT * FROM `join` where `id` = '".$_GET['id']."'";
		$result = mysql_query($sql, $con) or die(mysql_error());
		echo mysql_error();
		while ($data = mysql_fetch_assoc($result)) {
		echo ("<br>");
		echo ("<form method=\"post\" action=\"yesp2=".$_GET['id']."");
		echo ("<input name=\"email\" type=\"text\" value=\"".$data['email']."\" disabled> ");
		echo ("<textarea col=25 rows=20 name=mail>");
		echo ("<input type=submit name=submit value=Add>");
		echo ("</form");
		}
	}	

?>

The Action Page for Yes:

Code: Select all

<?php
if ("yesp2" == "".$_GET['id']."") {
		$con = mysql_connect($server, $user, $password) or die ('I cannot connect to the database because: ' . mysql_error()); 
		mysql_select_db($database);
		echo mysql_error();
		$del = "DELETE FROM `join` WHERE `id` = '".$_GET['id']."'";
		$sql1 = "SELECT * FROM `join` where `id` = '".$_GET['id']."'";
		$result = mysql_query($sql1, $con) or die(mysql_error());
		echo mysql_error();
		while ($data = mysql_fetch_assoc($result)) {
			$mail = $_POST['mail'];
			$AdminMessage .= $mail;
			mail("".$data['email']."", "Team Exile", $AdminMessage, "From: join@teamexileonline.com");
		}
		mysql_query($del, $con) or die(mysql_error());		
		echo mysql_error();
		echo ("<br>Deleted from Requests & Sent mail to user for acceptance.");
	}
?>

I dont get any errors, but the First 'Yes' page wont display itself... I posted 'Yes' page2 incase someone wants to see if there is any errors in that page cuz im not able to debug it until the First yes page works.

Please help!! ive been workin on this for 30min and still cant get any results!
Thanks

Posted: Tue Aug 09, 2005 10:09 am
by Grim...
Is there anything in the database?

Posted: Tue Aug 09, 2005 10:11 am
by Grim...
Hang on...
First line should be

Code: Select all

if ($yes == "".$_get['id']."") {
right?

And do you need the "". and .""?

Code: Select all

if ($yes == $_get['id']) {

Posted: Tue Aug 09, 2005 10:11 am
by bla5e
ya the first page (the page that you click the link to go to the Yes page) has about 19 entrys

Posted: Tue Aug 09, 2005 10:13 am
by s.dot
I don't know if this will make any difference, but I don't believe I've seen if booleans like that before.

Try

Code: Select all

if($_GET['id'] == "yes")
{
 //
}
"".$_GET['id']."" -> you're starting a string, then escaping to output php then escaping back to the string, then ending it.

So the "". and ."" isn't necessary. $_GET['id'] works just fine.

And putting your $_GET variable first is a more common practice, I don't know if it's more correct or not.

Posted: Tue Aug 09, 2005 10:14 am
by bla5e
when i did that ($yes instead of what i had) it posted the results of the mysql query b4 i did anything

example:
index.php says "Deleted from Requests & Sent mail to user for acceptance. "

its supposed to say that on
index.php?yesp2=<id>

Posted: Tue Aug 09, 2005 10:15 am
by feyd
$_GET['yes'] is where you are sending the data to the 'yes' page..

Posted: Tue Aug 09, 2005 10:19 am
by bla5e
Updated code:

Code: Select all

<?php
if ($_GET['yes'] == $_GET['id']) {
		$con = mysql_connect($server, $user, $password) or die ('I cannot connect to the database because: ' . mysql_error()); 
		mysql_select_db($database);
		echo mysql_error();
		$sql = "SELECT * FROM `join` where `id` = '".$_GET['id']."'";
		$result = mysql_query($sql, $con) or die(mysql_error());
		echo mysql_error();
		while ($data = mysql_fetch_assoc($result)) {
		echo ("<br>");
		echo ("<form method=\"post\" action=\"yesp2=".$_GET['id']."");
		echo ("<input name=\"email\" type=\"text\" value=\"".$data['email']."\" disabled> ");
		echo ("<textarea col=25 rows=20 name=mail>");
		echo ("<input type=submit name=submit value=Add>");
		echo ("</form");
		}
	}	

	if ($_GET['yesp2']  == $_GET['id']) {
		$con = mysql_connect($server, $user, $password) or die ('I cannot connect to the database because: ' . mysql_error()); 
		mysql_select_db($database);
		echo mysql_error();
		$del = "DELETE FROM `join` WHERE `id` = '".$_GET['id']."'";
		$sql1 = "SELECT * FROM `join` where `id` = '".$_GET['id']."'";
		$result = mysql_query($sql1, $con) or die(mysql_error());
		echo mysql_error();
		while ($data = mysql_fetch_assoc($result)) {
			$mail = $_POST['mail'];
			$AdminMessage .= $mail;
			mail("".$data['email']."", "Team Exile", $AdminMessage, "From: join@teamexileonline.com");
		}
		mysql_query($del, $con) or die(mysql_error());		
		echo mysql_error();
		echo ("<br>Deleted from Requests & Sent mail to user for acceptance.");
	}	
?>
The weird thing is, still on index.php (the page that isnt running any querys) it says "Deleted from Requests & Sent mail to user for acceptance. "

Posted: Tue Aug 09, 2005 10:22 am
by s.dot

Code: Select all

if ($_GET['yesp2']  == $_GET['id'])
if both of those aren't set in the URL string, isn't nothing = nothing ? Seems to me this expression would always evaluate to true if they're both empty.

try

Code: Select all

if($_GET['yesp2'])
{
     if($_GET['yesp2'] == $_GET['id'])
     {
          //
     }
}

Posted: Tue Aug 09, 2005 10:25 am
by bla5e
ok that worked, heres another update:

Code: Select all

<?php
	if ($_GET['yes'] == $_GET['id']) {
		$con = mysql_connect($server, $user, $password) or die ('I cannot connect to the database because: ' . mysql_error()); 
		mysql_select_db($database);
		echo mysql_error();
		$sql = "SELECT * FROM `join` where `id` = '".$_GET['id']."'";
		$result = mysql_query($sql, $con) or die(mysql_error());
		echo mysql_error();
		while ($data = mysql_fetch_assoc($result)) {
		echo ("<br>");
		echo ("<form method=\"post\" action=\"yesp2=".$_GET['id']."");
		echo ("<input name=\"email\" type=\"text\" value=\"".$data['email']."\" disabled> ");
		echo ("<textarea col=25 rows=20 name=mail>");
		echo ("<input type=submit name=submit value=Add>");
		echo ("</form");
		}
	}	

	if($_GET['yesp2']) { 
     if($_GET['yesp2'] == $_GET['id'])      { 
		$con = mysql_connect($server, $user, $password) or die ('I cannot connect to the database because: ' . mysql_error()); 
		mysql_select_db($database);
		echo mysql_error();
		$del = "DELETE FROM `join` WHERE `id` = '".$_GET['id']."'";
		$sql1 = "SELECT * FROM `join` where `id` = '".$_GET['id']."'";
		$result = mysql_query($sql1, $con) or die(mysql_error());
		echo mysql_error();
		while ($data = mysql_fetch_assoc($result)) {
			$mail = $_POST['mail'];
			$AdminMessage .= $mail;
			mail("".$data['email']."", "Team Exile", $AdminMessage, "From: join@teamexileonline.com");
		}
		mysql_query($del, $con) or die(mysql_error());		
		echo mysql_error();
		echo ("<br>Deleted from Requests & Sent mail to user for acceptance.");
  		} 
	} 
?>
thanks for all the help so far!!
yes page 1 still wont display tho

Posted: Tue Aug 09, 2005 10:29 am
by s.dot
are both the $_GET['yes'] and $_GET['id'] set in the url string?

Posted: Tue Aug 09, 2005 10:31 am
by bla5e
ya

Code: Select all

echo ("<td width=20%>  <a href=\"view.php?yes=".$data['id']."\">YES</a> / <a href=\"view.php?id=".$data['id']."\">NO</a></td>");

Posted: Tue Aug 09, 2005 10:34 am
by s.dot
according to that PHP code only your yes variable is set, and it's = $data['id']

your code should just be

Code: Select all

if($_GET['yes'])
{
     //
}

Posted: Tue Aug 09, 2005 10:35 am
by bla5e
then how would it know who it is accepting?

Posted: Tue Aug 09, 2005 10:35 am
by s.dot
and all of your $_GET['id'] 's in that section should be changed to $_GET['yes']