shebbycs Posted November 4, 2011 Share Posted November 4, 2011 <?php mysql_connect("localhost","root") or die(mysql_error()); mysql_select_db("Regis") or die(mysql_error()); $m=$_POST['message']; if (isset($_POST['submit'])) { // makes sure they filled it in // checks it against the database $check = mysql_query("SELECT * FROM registration WHERE username = '".$_POST['username']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { echo("<SCRIPT LANGUAGE='JavaScript'>window.alert('That user does not exist in our database')</SCRIPT>") ?> <html><head></head><body> <form name="register" method="post" action="login.php" onsubmit="return a()"> <table border='0'> <input type="hidden" name="message" value="<?php echo $m;?>"> <tr><td>Username:</td><td><input type="text" name="username" maxlength="60"></td></tr> <tr><td>Password:</td><td><input type="password" name="pass" maxlength="10"></td></tr> <tr><td>Confirm Password:</td><td><input type="password" name="pass2" maxlength="10"></td></tr> <tr><th colspan=2><input type="submit" name="sub" value="Register"></th></tr></table> </form> </body> </html> <? while($info = mysql_fetch_array( $check )) { $_POST['pass'] = stripslashes($_POST['pass']); $info['password'] = stripslashes($info['password']); $_POST['pass'] = md5($_POST['pass']); } } } else { ?> <html> <head> <script type="text/javascript"> function addsmiley(code) { var pretext = document.smile.message.value; this.code = code; document.smile.message.value = pretext + code; } function a() { var x = document.smile.message.value; if(x=="") { alert("Please insert an message!"); return false; } } </script> <style type="text/css"> body{ background-color: #d8da3d } </style> </head> <body> <form name="smile" method="post" action="registration.php" onSubmit="return a()" > <input type="hidden" name="message" value="<?php echo $m;?>"> Your message:<br><textarea name='message' cols='40' rows='2'></textarea><br> <img src="smile.gif" alt="" onClick="addsmiley('')" style="cursor:pointer;border:0" /> <img src="blush.gif" alt="" onClick="addsmiley('*blush*')" style="cursor:pointer;border:0" /> <input type='submit' name='submit' value='Set Name' class='biasa' ></form> <br> <br> </body> </html> <?php } ?> im doing if statments if the $check2==0 it will show the registration form and else it will show the form name="smile" method="post" action="registration.php" onSubmit="return a()" > <input type="hidden" name="message" value="<?php echo $m;?>"> Your message:<br><textarea name='message' cols='40' rows='2'></textarea><br> <img src="smile.gif" alt="" onClick="addsmiley('')" style="cursor:pointer;border:0" /> <img src="blush.gif" alt="" onClick="addsmiley('*blush*')" style="cursor:pointer;border:0" /> <input type='submit' name='submit' value='Set Name' class='biasa' ></form> but my problem is it cannot direct to else matter although the name is already in database may i know which error is wrong or the if statement is wrong Quote Link to comment https://forums.phpfreaks.com/topic/250433-the-else-statement-cannot-be-run/ Share on other sites More sharing options...
ManiacDan Posted November 4, 2011 Share Posted November 4, 2011 Indent your code properly so you can tell which block goes where. It seems to me that your else() is linked to your first if() for $_POST Quote Link to comment https://forums.phpfreaks.com/topic/250433-the-else-statement-cannot-be-run/#findComment-1284900 Share on other sites More sharing options...
shebbycs Posted November 4, 2011 Author Share Posted November 4, 2011 if (isset($_POST['submit'])) { if($check2 == 0) { //data while($info = mysql_fetch_array( $check )) { //data } } } else { //data } yes the first if im want to make the else working how to do it? Quote Link to comment https://forums.phpfreaks.com/topic/250433-the-else-statement-cannot-be-run/#findComment-1284921 Share on other sites More sharing options...
ManiacDan Posted November 5, 2011 Share Posted November 5, 2011 the else will execute if the first IF is false...so the else will execute if $_POST['submit'] is empty. Visit the page directly so $_pOST is empty. Also, when I said to indent your code I wasn't asking for ME. Indenting your code is good practice. You'll never be able to figure out problems like this if you have 11 control structures grouped together with multiple ending braces per line. Quote Link to comment https://forums.phpfreaks.com/topic/250433-the-else-statement-cannot-be-run/#findComment-1285237 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.