[Solved] Code problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

[Solved] Code problem

Post 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
Last edited by bla5e on Tue Aug 09, 2005 11:47 am, edited 1 time in total.
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

Is there anything in the database?
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post 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']) {
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

ya the first page (the page that you click the link to go to the Yes page) has about 19 entrys
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post 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>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$_GET['yes'] is where you are sending the data to the 'yes' page..
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post 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. "
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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'])
     {
          //
     }
}
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post 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
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

are both the $_GET['yes'] and $_GET['id'] set in the url string?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post 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>");
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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'])
{
     //
}
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

then how would it know who it is accepting?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

and all of your $_GET['id'] 's in that section should be changed to $_GET['yes']
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply