avo Posted April 24, 2006 Share Posted April 24, 2006 Hi allcan any one please explan what im doing incorrect please im not after code to solve it but an explanation into why .my code [code]if ($_POST ['Signup']) {mysql_connect ($dbhost, $dbuser, $dbpass) or die (mysql_error () );mysql_select_db ($dbname) or die (mysql_error () );$sql= "INSERT INTO members ( username ) VALUES ( '".$_POST['muser']."')";mysql_query ($sql) or die ( mysql_error () );mysql_close ();}if ($_POST ['muser'] !="" ) {$frm_check_username ="good";$frm_check = "good";} else {$frm_check_username ="bad";$frm_check = "bad";}[/code]All it is at the moment is a simple one line form contaning username when i press the form button its passed to the &_POST variable this then connects to my db the if statement is linked to my username text box if this as some text in the box all ok but if not then frm_check = bad the code echoed in my html is [code] <?php if ($frm_check == "bad") { echo "<td colspan=\"2\"><div align=\"center\">error</div></td>"; } ?>[/code]my question is why when my form loads it echos the above out and dont wait untill i have pressed the submit button hen not text as been entered into the box if text is in the box all works fine and error is removed untill irefesh the browser again.Thank you in advance. Quote Link to comment https://forums.phpfreaks.com/topic/8304-echo-without-asking/ Share on other sites More sharing options...
kenrbnsn Posted April 24, 2006 Share Posted April 24, 2006 Is your script in a file named "something.php"? If it's not, then the PHP interpreter is not being invoked and it will look like regular text to HTML, which displays it on the screen.Ken Quote Link to comment https://forums.phpfreaks.com/topic/8304-echo-without-asking/#findComment-30281 Share on other sites More sharing options...
avo Posted April 24, 2006 Author Share Posted April 24, 2006 HI thanks yes its in a file called admin_member.php can you please explane a little more on what you mentioned if it helps im running this on a local host apache am i missing soemthing in my ini file.my db is working (sql)thanks and appriciated. Quote Link to comment https://forums.phpfreaks.com/topic/8304-echo-without-asking/#findComment-30287 Share on other sites More sharing options...
sanfly Posted April 24, 2006 Share Posted April 24, 2006 If I'm understanding you correctly, you are getting the "error" echoed before you have pressed submit?If so, this is because you dont say anything about requiring the submit to be pressed in the if/else code where $frm_check is definedYou need to use one of the two following instead[code]if($_POST['muser'] && $_POST['Signup']) { $frm_check_username ="good"; $frm_check = "good";} elseif(!$_POST['muser'] && $_POST['Signup']) { $frm_check_username ="bad"; $frm_check = "bad";}[/code]or, replace the whole lot with this[code]if ($_POST['Signup']) { mysql_connect($dbhost, $dbuser, $dbpass) or die (mysql_error () ); mysql_select_db($dbname) or die (mysql_error () ); $sql= "INSERT INTO members ( username ) VALUES ( '".$_POST['muser']."')"; mysql_query($sql) or die( mysql_error () ); mysql_close(); if ($_POST['muser'] !="" ) { $frm_check_username ="good"; $frm_check = "good"; } else { $frm_check_username ="bad"; $frm_check = "bad"; }}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/8304-echo-without-asking/#findComment-30291 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.