[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

User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

bla5e wrote:then how would it know who it is accepting?
because if($_GET['yes']) is just checking if the variable is there.. it doesn't lose its value.

the value of $_GET['yes'] is the person's ID (what you were calling $_GET['id'] in your script
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 »

i dont think im understanding you correctly..

can you post what you mean?
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

<?php 
if ($_GET['yes'])
{ 
     $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['yes']."'"; 
        $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['yes'].""); 
        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"); 
        } 
    }     

?>
That code should work.

It checks to see if $_GET['yes'] is set in the URL string (which it is, it's = to an id number.

Then it performs the query based on the value of $_GET['yes'] which is an id number.
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 »

thanks! it works!!

but theres a problem...
when i click the 'Add' button (to send the mail message) it goes to

view.php?yesp2=19<input%20name=


nvm i figured it out... i didnt have '>' to end the form tag
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

give me a moment I'm going to clean your code up for you a bit :)
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 »

yesp2 doesnt do anything (wont mail or delete from mysql)

Code: Select all

<?php
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.");
  		} 
	} 	
?>
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['yes'])
{ 
	$con = mysql_connect($server, $user, $password); 
	mysql_select_db($database, $con); 
	$result = mysql_query("SELECT * FROM `join` where `id` = '".$_GET['yes']."'");
	while($data = mysql_fetch_assoc($result))
	{
		echo ("<br>"); 
		echo ("<form method=\"post\" action=\"yesp2=".$_GET['yes'].""); 
		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'])
{ 
	$con = mysql_connect($server, $user, $password); 
	mysql_select_db($database, $con);
	$mail = $_POST['email']; 
	$AdminMessage = "whateveryouwanthere";
	mail($mail, "Team Exile", $AdminMessage, "From: join@teamexileonline.com"); 
	mysql_query("DELETE FROM `join` WHERE `id` = '".$_GET['id']."'");
	echo ("<br>Deleted from Requests & Sent mail to user for acceptance.");
} 
}
?>
Improvised and cleaned code. Should work.
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 »

i changed some things about yesp2, but it says that its sending the email & deleting from the mysql.. but its not

Code: Select all

<?php
if($_GET['yesp2']) { 
    $con = mysql_connect($server, $user, $password); 
    mysql_select_db($database, $con); 
    $email = $_POST['email'];
    $mail = $_POST['mail']; 
    $AdminMessage = $mail; 
    mail($email, "Team Exile", $AdminMessage, "From: join@teamexileonline.com"); 
    mysql_query("DELETE FROM `join` WHERE `id` = '".$_GET['id']."'"); 
    echo ("<br>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 »

in the delete query, change $_GET['id'] to $_GET['yesp2']
that will work.

As far as the mail goes
print out your variables to see if they're really there

Code: Select all

echo $mail;
echo "<BR>";
echo $AdminMessage;
echo "<BR>";
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 »

yea variables are there
i tried echo $email

but that didnt show anything
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

then it should be fine.

Code: Select all

if(mail($,$,$,$))
{
  // do nothing
} ELSE
{
   echo "mail could not be sent";
}
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 »

$_POST['email']
isnt being, well, posted...

the form:

Code: Select all

echo ("<input name=\"email\" type=\"text\" value=\"".$data['email']."\" disabled><br> ");

the mailer:

Code: Select all

$email = $_POST['email'];
$mail = $_POST['mail']; 
$AdminMessage = $mail; 
mail($email, "Team Exile", $AdminMessage, "From: join@teamexileonline.com");
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

is there a value being posted.. like written in the form and then submitted?

Also, where is $_POST['mail'] coming from?
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 »

post mail = the textarea, or the body of the email.

on the mailer form itself, it shows the email in the input form thing.. but it wont send it to the mailer.
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

echo ("<form method=\"post\" action=\"yesp2=".$_GET['yes']."");
try changing this to

Code: Select all

echo ("<form method=\"post\" action=\"".$_SERVER['php_self']."?yesp2=".$_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