Jump to content

the else statement cannot be run


shebbycs

Recommended Posts

<?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

Link to comment
https://forums.phpfreaks.com/topic/250433-the-else-statement-cannot-be-run/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.