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

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.