Jump to content

$_SERVER['PHP_SELF'] Problem


New Coder

Recommended Posts

Hello all,

 

I'm trying to make a form so that people can notify us of their personal details changing.

So far I have this page:

<?PHP 


		$email = $_POST['email'];
			$change = $_POST['change];
			$sent = $_POST['sent'];

		$form="<form action=\"$_SERVER['PHP_SELF']\" method=\"post\">";
		$form.="User ID:<br>$user_id<br><br>";
		$form.="Email:<br><input type=\"text\" name=\"email\"";
		$form.=" size=\"50\" value=\"$email\"><br><br>";
		$form.="Change:<br><textarea name=\"change\"";
		$form.="cols=\"30\" rows=\"5\">$change</textarea>";
		$form.="<br> <input type=\"submit\" name=\"sent\" ";
		$form.="value=\"Send Form\"></form>";

		if($sent)
			{ $valid=true;  #set variable default value


		if( !$email)
		{ $errmsg.="Enter email address:<br>"; $valid=false;}
		else
		{
			$email = trim( $email );

			$_name = "/^[-!#$%&\'*+\\.\/0-9=?A-Z*\{|}~]+";
			$_host = "([0-9A-Z]+\.+)+";
			$_tlds = "([0-9A-Z]){2,4}$/i";

			if( !preg_match($_name."@".$_host.$_tlds,$email) )
			{
  			$errmsg .="Email address has incorrect format!<br>";
  			$valid = false;}
		}

		if( !$change )
			{ $errmsg.="Enter you changes:<br>"; $valid=false;}
			}

		if( $valid != true){echo( $errmsg. $form);}
			else 
			{ $to = "email@somewhere.com";
				$re = "Details Changed from $user_id";
				$msg = $change;
				$headers = "From: $email \r\n";
				if( mail( $to, $re, $msg, $headers ) )
			 {echo("Thanks for your changes, $user_id");}
	}
		?>

 

Gives me a blank page... but if I remove $_SERVER['PHP_SELF'] from the code a page does display but will not function.

 

Do I need to add/uncomment an extension in the php.ini file?

I'm lost...

 

Many Thanks

Link to comment
Share on other sites

Hi,

 

Please change the way you use the $_SERVER['PHP_SELF'] variable inside the the quoted string. There are couple of ways of solving this problem. Either remove the single quote around PHP_SELF or add flower brace around the $_SERVER['PHP_SELF'] variable to make the variable usage in a non-ambiguous manner.

 

Present Problematic Code:

 

$form="<form action=\"$_SERVER['PHP_SELF']\" method=\"post\">"; 

 

Change To:

Possiblity 1:

$form="<form action=\"$_SERVER[php_SELF]\" method=\"post\">"; 

Possiblity 2:

$form="<form action=\"{$_SERVER['PHP_SELF']}\" method=\"post\">"; 

 

Thanks,

Ramchel

"Happy Coding"

Link to comment
Share on other sites

You can't have a quoted index in a quoted string, do this instead:

<?php
$form="<form action='{$_SERVER['PHP_SELF']}' method='post'>";
?>

 

Also, notice that you can eliminate all the of escaped double quotes by replacing them with single quotes.

 

Ken

Link to comment
Share on other sites

I have tried all suggestions,

If I leave a field blank it does prompt to say which field is blank, so that much is working.

If all fields are filled in and I press submit, the form disappears, no email arrives and I do not get the "Thanks for your changes..." message.

Do I need to have register_global = on in my ini file?

 

Many Thanks

 

 

Link to comment
Share on other sites

Hi,

 

Possible problem is with how you configured the PHP to send mails out of the applications. A proper mail configuration is required for sending mails from PHP programs.

 

following are the php.ini variables needs to be set properly for mail to work properly 'sendmail_from' and 'sendmail_path'.

 

Thanks,

Ramchel

"Happy Coding"

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.