New Coder Posted April 7, 2008 Share Posted April 7, 2008 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 protected]"; $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 https://forums.phpfreaks.com/topic/99941-_serverphp_self-problem/ Share on other sites More sharing options...
paul2463 Posted April 7, 2008 Share Posted April 7, 2008 you are missing a closing single speech mark on $change = $_POST['change]; Link to comment https://forums.phpfreaks.com/topic/99941-_serverphp_self-problem/#findComment-511051 Share on other sites More sharing options...
New Coder Posted April 7, 2008 Author Share Posted April 7, 2008 whoops oh yea, typo... but it still not working Thanks Link to comment https://forums.phpfreaks.com/topic/99941-_serverphp_self-problem/#findComment-511055 Share on other sites More sharing options...
ramchel Posted April 7, 2008 Share Posted April 7, 2008 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 https://forums.phpfreaks.com/topic/99941-_serverphp_self-problem/#findComment-511068 Share on other sites More sharing options...
kenrbnsn Posted April 7, 2008 Share Posted April 7, 2008 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 https://forums.phpfreaks.com/topic/99941-_serverphp_self-problem/#findComment-511069 Share on other sites More sharing options...
New Coder Posted April 7, 2008 Author Share Posted April 7, 2008 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 https://forums.phpfreaks.com/topic/99941-_serverphp_self-problem/#findComment-511072 Share on other sites More sharing options...
ramchel Posted April 7, 2008 Share Posted April 7, 2008 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 https://forums.phpfreaks.com/topic/99941-_serverphp_self-problem/#findComment-511093 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.