Jump to content

Making the message text area dissappear when come to registration


shebbycs

Recommended Posts

<?php

$db = mysql_connect("localhost", "root") or die("Could not connect."); //username and password

if(!$db) 

die("no db");

if(!mysql_select_db("simple",$db))
if(!mysql_select_db("regis",$db))//database name

	die("No database selected.");

if(isset($_POST['submit'])) //if submit button push has been detected

{

   $message=$_POST['message'];

   if(strlen($message)<1)

   {

      print "You did not input a message";

   }

   else

   {

      $message=strip_tags($message);

      $IP=$_SERVER["REMOTE_ADDR"]; //grabs poster's IP

      $checkforbanned="SELECT IP from admin where IP='$IP'";

      $checkforbanned2=mysql_query($checkforbanned) or die("Could not check for banned IPS");

      if(mysql_num_rows($checkforbanned2)>0) //IP is in the banned list

      {

         print "You IP is banned from posting.";

      }

     else
      
       if(strlen($message)>=1)
       {
         if (isset($_POST['sub']))
         {

if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] )
{
  die('You did not complete all of the required fields');
}

// checks if the username is in use

  if (!get_magic_quotes_gpc()) 
  {
   $_POST['username'] = addslashes($_POST['username']);
  }

$usercheck = $_POST['username'];

$check = mysql_query("SELECT username FROM registration WHERE username = '$usercheck'")

  or die(mysql_error());

$check2 = mysql_num_rows($check);



//if the name exists it gives an error

if ($check2 != 0)
  {
   die('Sorry, the username '.$_POST['username'].' is already in use.');
  }


//this makes sure both passwords entered match

  if ($_POST['pass'] != $_POST['pass2'])
  {
   die('Your passwords did not match. ');
  }

// here we encrypt the password and add slashes if needed

   $_POST['pass'] = md5($_POST['pass']);

    if (!get_magic_quotes_gpc()) 
    {
      $_POST['pass'] = addslashes($_POST['pass']);

      $_POST['username'] = addslashes($_POST['username']);

    }

// now we insert it into the database


     $insert = "INSERT INTO registration (username, password) VALUES ('".$_POST['username']."', '".$_POST['pass']."')";
     $add_member = mysql_query($insert);
     die("<meta http-equiv=\"refresh\" content=\"0; url=login.php\">");


}

else
{




echo "<form action='login.php' method='post'>

<table border='0'>

<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> ";




}

       }
     /*   if($_POST['username'] && $_POST['pass'])
       {

         $name = mysql_query("SELECT * FROM Persons");
         $thedate = date("U"); //grab date and time of the post

         $insertmessage="INSERT into mesej (name,IP,postime,message) values('$name','$IP','$thedate','$message')";

         mysql_query($insertmessage) or die("Could not insert message");

        }     */

   }





}

print "<form action='' method='post' name='form'>";

print "Your message:<br>";

print "<textarea name='message' cols='40' rows='2'></textarea><br>";

print "<a onClick=\"addSmiley('')\"><img src='smile.gif'></a> "; 

print "<a onClick=\"addSmiley('')\"><img src='blush.gif'></a> ";

print "<a onClick=\"addSmiley('')\"><img src='images/wink.gif'></a> ";

print "<input type='submit' name='submit' value='submit'></form>";

print "<script language=\"Java Script\" type=\"text/javascript\">\n";

print "function addSmiley(a)\n";

print "{\n";

print "document.form.message.value += a;";

print "document.form.message.focus();\n";

print "}\n";

print "</script>\n";

print "<br><br>";



?>

 

Screenshots

 

25238754106371062279.jpg

 

After i hit submit button with message inside it, it appear like this :

 

44489660080470386983.jpg

 

My main problem is when it goes to registration phase im do not want that message text  area appear so in my code which is  wrong and where im need to redo sir?

Link to comment
Share on other sites

This should take care of it.  Add a hidden textarea to your registration form which passes the $message variable through the registration process.  Wrapping the message form with isset should hide that form.  You might want to change the default to links for "Log in" Or "Register" instead of automatically pushing registration.  IF you go that route, you could save the message with a SESSION until user has logged in or registered.  You should run the username and the message through mysqli_real_escape_string before adding to the DB.  Good luck on your project. :)

<?php

$db = mysql_connect("localhost", "root") or die("Could not connect."); //username and password

if(!$db) 

die("no db");

if(!mysql_select_db("simple",$db))
if(!mysql_select_db("regis",$db))//database name

	die("No database selected.");

if(isset($_POST['submit'])) //if submit button push has been detected

{

   $message=$_POST['message'];

   if(strlen($message)<1)

   {

      print "You did not input a message";

   }

   else

   {

      $message=strip_tags($message);

      $IP=$_SERVER["REMOTE_ADDR"]; //grabs poster's IP

      $checkforbanned="SELECT IP from admin where IP='$IP'";

      $checkforbanned2=mysql_query($checkforbanned) or die("Could not check for banned IPS");

      if(mysql_num_rows($checkforbanned2)>0) //IP is in the banned list

      {

         print "You IP is banned from posting.";

      }

     else
      
       if(strlen($message)>=1)
       {
         if (isset($_POST['sub']))
         {
// Grab message from hidden field
$message=$_POST['message'];
$message=strip_tags($message);
///Continue
if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] )
{
  die('You did not complete all of the required fields');
}

// checks if the username is in use

  if (!get_magic_quotes_gpc()) 
  {
   $_POST['username'] = addslashes($_POST['username']);
  }

$usercheck = $_POST['username'];

$check = mysql_query("SELECT username FROM registration WHERE username = '$usercheck'")

  or die(mysql_error());

$check2 = mysql_num_rows($check);



//if the name exists it gives an error

if ($check2 != 0)
  {
   die('Sorry, the username '.$_POST['username'].' is already in use.');
  }


//this makes sure both passwords entered match

  if ($_POST['pass'] != $_POST['pass2'])
  {
   die('Your passwords did not match. ');
  }

// here we encrypt the password and add slashes if needed

   $_POST['pass'] = md5($_POST['pass']);

    if (!get_magic_quotes_gpc()) 
    {
      $_POST['pass'] = addslashes($_POST['pass']);

      $_POST['username'] = addslashes($_POST['username']);

    }

// now we insert it into the database


     $insert = "INSERT INTO registration (username, password) VALUES ('".$_POST['username']."', '".$_POST['pass']."')";
     $add_member = mysql_query($insert);
     die("<meta http-equiv=\"refresh\" content=\"0; url=login.php\">");


}

else
{ 

echo "<form action='login.php' method='post'>

<table border='0'>

<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><textarea name='message' cols='1' rows='1' style=\"display:none;\">$message</textarea><input type='submit' name='sub'
value='Register'></th></tr> </table>

</form> ";




}

       }
     /*   if($_POST['username'] && $_POST['pass'])
       {

         $name = mysql_query("SELECT * FROM Persons");
         $thedate = date("U"); //grab date and time of the post

         $insertmessage="INSERT into mesej (name,IP,postime,message) values('$name','$IP','$thedate','$message')";

         mysql_query($insertmessage) or die("Could not insert message");

        }     */

   }





}
IF (!isset($message)){
print "<form action='' method='post' name='form'>";

print "Your message:<br>";

print "<textarea name='message' cols='40' rows='2'></textarea><br>";

print "<a onClick=\"addSmiley('')\"><img src='smile.gif'></a> "; 

print "<a onClick=\"addSmiley('')\"><img src='blush.gif'></a> ";

print "<a onClick=\"addSmiley('')\"><img src='images/wink.gif'></a> ";

print "<input type='submit' name='submit' value='submit'></form>";

print "<script language=\"Java Script\" type=\"text/javascript\">\n";

print "function addSmiley(a)\n";

print "{\n";

print "document.form.message.value += a;";

print "document.form.message.focus();\n";

print "}\n";

print "</script>\n";

print "<br><br>";
}


?>

Link to comment
Share on other sites

its all perfect but when come to the register button when i click even the 3 textbox is empty it can run without seeing the rules how it is possible?

 

  if(strlen($message)>=1)
       {
         if (isset($_POST['sub']))
         {
// Grab message from hidden field
$message=$_POST['message'];
$message=strip_tags($message);
///Continue
if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] )
{
  die('You did not complete all of the required fields');
}

// checks if the username is in use

  if (!get_magic_quotes_gpc()) 
  {
   $_POST['username'] = addslashes($_POST['username']);
  }

$usercheck = $_POST['username'];

$check = mysql_query("SELECT username FROM registration WHERE username = '$usercheck'")

  or die(mysql_error());

$check2 = mysql_num_rows($check);



//if the name exists it gives an error

if ($check2 != 0)
  {
   die('Sorry, the username '.$_POST['username'].' is already in use.');
  }


//this makes sure both passwords entered match

  if ($_POST['pass'] != $_POST['pass2'])
  {
   die('Your passwords did not match. ');
  }

// here we encrypt the password and add slashes if needed

   $_POST['pass'] = md5($_POST['pass']);

    if (!get_magic_quotes_gpc()) 
    {
      $_POST['pass'] = addslashes($_POST['pass']);

      $_POST['username'] = addslashes($_POST['username']);

    }

// now we insert it into the database


     $insert = "INSERT INTO registration (username, password) VALUES ('".$_POST['username']."', '".$_POST['pass']."')";
     $add_member = mysql_query($insert);
     die("<meta http-equiv=\"refresh\" content=\"0; url=login.php\">");

Link to comment
Share on other sites

I'm not sure exactly what you're saying.  Once the $message variable is set, it's put inside a hidden textarea in the registration form so when you click "Register" the post value for message is resent and converted back to the variable with $message=$_POST['message']; and so this will repeat even if username and password are empty.

Link to comment
Share on other sites

Sir im means after i put the message on the text area and when im click it goes to the registration info

 

32181949290494063847.jpg

 

but if the whole is empty, it suppose to popup "'You did not complete all of the required fields"

 

 

 if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] )
{
  die('You did not complete all of the required fields');
}

// checks if the username is in use

  if (!get_magic_quotes_gpc()) 
  {
   $_POST['username'] = addslashes($_POST['username']);
  }

$usercheck = $_POST['username'];

$check = mysql_query("SELECT username FROM registration WHERE username = '$usercheck'")

  or die(mysql_error());

$check2 = mysql_num_rows($check);



//if the name exists it gives an error

if ($check2 != 0)
  {
   die('Sorry, the username '.$_POST['username'].' is already in use.');
  }


//this makes sure both passwords entered match

  if ($_POST['pass'] != $_POST['pass2'])
  {
   die('Your passwords did not match. ');
  }

// here we encrypt the password and add slashes if needed

   $_POST['pass'] = md5($_POST['pass']);

    if (!get_magic_quotes_gpc()) 
    {
      $_POST['pass'] = addslashes($_POST['pass']);

      $_POST['username'] = addslashes($_POST['username']);

    }

// now we insert it into the database


     $insert = "INSERT INTO registration (username, password) VALUES ('".$_POST['username']."', '".$_POST['pass']."')";
     $add_member = mysql_query($insert);
     die("<meta http-equiv=\"refresh\" content=\"0; url=login.php\">");

 

 

 

but instead after im click register button its does not check whether im input all the information shall i know what is the wrong ?

Link to comment
Share on other sites

sir although im had done the way you ask sir but its still does not check the empty ones

 

 

<?php

$db = mysql_connect("localhost", "root") or die("Could not connect."); //username and password

if(!$db) 

die("no db");

if(!mysql_select_db("simple",$db))
if(!mysql_select_db("regis",$db))//database name

	die("No database selected.");

if(isset($_POST['submit'])) //if submit button push has been detected

{

   $message=$_POST['message'];

   if(strlen($message)<1)

   {

      print "You did not input a message";

   }

   else

   {

      $message=strip_tags($message);

      $IP=$_SERVER["REMOTE_ADDR"]; //grabs poster's IP

      $checkforbanned="SELECT IP from admin where IP='$IP'";

      $checkforbanned2=mysql_query($checkforbanned) or die("Could not check for banned IPS");

      if(mysql_num_rows($checkforbanned2)>0) //IP is in the banned list

      {

         print "You IP is banned from posting.";

      }

     else
      
       if(strlen($message)>=1)
       {
         if (isset($_POST['sub']))
         {
          $message2=$_POST['message'];
          $message3=strip_tags($message2);

        if (empty($_POST['username']) || empty($_POST['pass']) || empty($_POST['pass2'] ))
        {
           print "You did not complete all of the required fields";
        }

        // checks if the username is in use

        if (!get_magic_quotes_gpc())
       {
        $_POST['username'] = addslashes($_POST['username']);
       }

        $usercheck = $_POST['username'];

        $check = mysql_query("SELECT username FROM registration WHERE username = '$usercheck'")

         or die(mysql_error());

        $check2 = mysql_num_rows($check);

        
       //if the name exists it gives an error

       if ($check2 != 0)
      {
       die('Sorry, the username '.$_POST['username'].' is already in use.');
      }


       //this makes sure both passwords entered match

       if ($_POST['pass'] != $_POST['pass2'])
      {
       die('Your passwords did not match. ');
      }

      // here we encrypt the password and add slashes if needed

       $_POST['pass'] = md5($_POST['pass']);

       if (!get_magic_quotes_gpc())
      {
       $_POST['pass'] = addslashes($_POST['pass']);

       $_POST['username'] = addslashes($_POST['username']);
      }

      // now we insert it into the database


     $insert = "INSERT INTO registration (username, password) VALUES ('".$_POST['username']."', '".$_POST['pass']."')";
     $add_member = mysql_query($insert);
     die("<meta http-equiv=\"refresh\" content=\"0; url=login.php\">");
   }

else
{
  echo "<form action='' method='post'>

  <table border='0'>

  <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> ";
}

       }
     /*   if($_POST['username'] && $_POST['pass'])
       {

         $name = mysql_query("SELECT * FROM Persons");
         $thedate = date("U"); //grab date and time of the post

         $insertmessage="INSERT into mesej (name,IP,postime,message) values('$name','$IP','$thedate','$message')";

         mysql_query($insertmessage) or die("Could not insert message");

        }     */

   }
}

if(!isset($message))
{
  print "<form action='' method='post' name='form'>";

  print "Your message:<br>";

  print "<textarea name='message' cols='40' rows='2'></textarea><br>";

  print "<a onClick=\"addSmiley('')\"><img src='smile.gif'></a> ";

  print "<a onClick=\"addSmiley('')\"><img src='blush.gif'></a> ";

  print "<a onClick=\"addSmiley('')\"><img src='images/wink.gif'></a> ";

  print "<input type='submit' name='submit' value='submit'></form>";

  print "<script language=\"Java Script\" type=\"text/javascript\">\n";

  print "function addSmiley(a)\n";

  print "{\n";

  print "document.form.message.value += a;";

  print "document.form.message.focus();\n";

  print "}\n";

  print "</script>\n";

  print "<br><br>";
  
}



?>

 

I means it does not print "You did not complete all of the required fields";

Link to comment
Share on other sites

Forgive me, I was copying your code.

First you don't want to have "die".  You would echo the comment or make the comment a variable which you would show within the body tags of your page.  So

if (empty($_POST['username']) || empty($_POST['pass']) || empty($_POST['pass2']))
{
  echo"You did not complete all of the required fields";
}

OR

if (empty($_POST['username']) || empty($_POST['pass']) || empty($_POST['pass2']))
{
  $errormsg1="You did not complete all of the required fields";
}
//Then below in your page you would have
IF (isset($errormsg1)){ echo "$errormsg1";

Link to comment
Share on other sites

sir don said like that no need forgive im just a beginner only and im reallly thankful to you for helping me

 

<?php

$db = mysql_connect("localhost", "root") or die("Could not connect."); //username and password

if(!$db) 

die("no db");

if(!mysql_select_db("simple",$db))
if(!mysql_select_db("regis",$db))//database name

	die("No database selected.");

if(isset($_POST['submit'])) //if submit button push has been detected

{

   $message=$_POST['message'];

   if(strlen($message)<1)

   {

      print "You did not input a message";

   }

   else

   {

      $message=strip_tags($message);

      $IP=$_SERVER["REMOTE_ADDR"]; //grabs poster's IP

      $checkforbanned="SELECT IP from admin where IP='$IP'";

      $checkforbanned2=mysql_query($checkforbanned) or die("Could not check for banned IPS");

      if(mysql_num_rows($checkforbanned2)>0) //IP is in the banned list

      {

         print "You IP is banned from posting.";

      }

     else
      
       if(strlen($message)>=1)
       {
         if (isset($_POST['sub']))
         {
          $message2=$_POST['message'];
          $message3=strip_tags($message2);

        if (empty($_POST['username']) || empty($_POST['pass']) || empty($_POST['pass2'] ))
        {
           $errormsg1= "You did not complete all of the required fields";
        }
        IF (isset($errormsg1))echo "$errormsg1";
        // checks if the username is in use

        if (!get_magic_quotes_gpc())
       {
        $_POST['username'] = addslashes($_POST['username']);
       }

        $usercheck = $_POST['username'];

        $check = mysql_query("SELECT username FROM registration WHERE username = '$usercheck'")

         or die(mysql_error());

        $check2 = mysql_num_rows($check);

        
       //if the name exists it gives an error

       if ($check2 != 0)
      {
       die('Sorry, the username '.$_POST['username'].' is already in use.');
      }


       //this makes sure both passwords entered match

       if ($_POST['pass'] != $_POST['pass2'])
      {
       die('Your passwords did not match. ');
      }

      // here we encrypt the password and add slashes if needed

       $_POST['pass'] = md5($_POST['pass']);

       if (!get_magic_quotes_gpc())
      {
       $_POST['pass'] = addslashes($_POST['pass']);

       $_POST['username'] = addslashes($_POST['username']);
      }

      // now we insert it into the database


     $insert = "INSERT INTO registration (username, password) VALUES ('".$_POST['username']."', '".$_POST['pass']."')";
     $add_member = mysql_query($insert);
     die("<meta http-equiv=\"refresh\" content=\"0; url=login.php\">");
   }

else
{
  echo "<form action='' method='post'>

  <table border='0'>

  <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> ";
}

       }
     /*   if($_POST['username'] && $_POST['pass'])
       {

         $name = mysql_query("SELECT * FROM Persons");
         $thedate = date("U"); //grab date and time of the post

         $insertmessage="INSERT into mesej (name,IP,postime,message) values('$name','$IP','$thedate','$message')";

         mysql_query($insertmessage) or die("Could not insert message");

        }     */

   }
}

if(!isset($message))
{
  print "<form action='' method='post' name='form'>";

  print "Your message:<br>";

  print "<textarea name='message' cols='40' rows='2'></textarea><br>";

  print "<a onClick=\"addSmiley('')\"><img src='smile.gif'></a> ";

  print "<a onClick=\"addSmiley('')\"><img src='blush.gif'></a> ";

  print "<a onClick=\"addSmiley('')\"><img src='images/wink.gif'></a> ";

  print "<input type='submit' name='submit' value='submit'></form>";

  print "<script language=\"Java Script\" type=\"text/javascript\">\n";

  print "function addSmiley(a)\n";

  print "{\n";

  print "document.form.message.value += a;";

  print "document.form.message.focus();\n";

  print "}\n";

  print "</script>\n";

  print "<br><br>";
  
}



?>

 

 

Is it like this ? im had done but still the error cannot come im wonder why

Link to comment
Share on other sites

<?php

$db = mysql_connect("localhost", "root") or die("Could not connect."); //username and password

if(!$db) 

die("no db");

if(!mysql_select_db("simple",$db))
if(!mysql_select_db("regis",$db))//database name

	die("No database selected.");

if(isset($_POST['submit'])) //if submit button push has been detected

{

   $message=$_POST['message'];

   if(strlen($message)<1)

   {

      print "You did not input a message";

   }

   else

   {

      $message=strip_tags($message);

      $IP=$_SERVER["REMOTE_ADDR"]; //grabs poster's IP

      $checkforbanned="SELECT IP from admin where IP='$IP'";

      $checkforbanned2=mysql_query($checkforbanned) or die("Could not check for banned IPS");

      if(mysql_num_rows($checkforbanned2)>0) //IP is in the banned list

      {

         print "You IP is banned from posting.";

      }

     else
      
       if(strlen($message)>=1)
       {
         if (isset($_POST['sub']))
         {
          $message2=$_POST['message'];
          $message3=strip_tags($message2);

        if (empty($_POST['username']) || empty($_POST['pass']) || empty($_POST['pass2'] ))
        {
           $errormsg1= "You did not complete all of the required fields";
        }
        IF (isset($errormsg1)){echo "$errormsg1";}
        // checks if the username is in use

        if (!get_magic_quotes_gpc())
       {
        $_POST['username'] = addslashes($_POST['username']);
       }

        $usercheck = $_POST['username'];

        $check = mysql_query("SELECT username FROM registration WHERE username = '$usercheck'")

         or die(mysql_error());

        $check2 = mysql_num_rows($check);

        
       //if the name exists it gives an error

       if ($check2 != 0)
      {
       die('Sorry, the username '.$_POST['username'].' is already in use.');
      }


       //this makes sure both passwords entered match

       if ($_POST['pass'] != $_POST['pass2'])
      {
       die('Your passwords did not match. ');
      }

      // here we encrypt the password and add slashes if needed

       $_POST['pass'] = md5($_POST['pass']);

       if (!get_magic_quotes_gpc())
      {
       $_POST['pass'] = addslashes($_POST['pass']);

       $_POST['username'] = addslashes($_POST['username']);
      }

      // now we insert it into the database


     $insert = "INSERT INTO registration (username, password) VALUES ('".$_POST['username']."', '".$_POST['pass']."')";
     $add_member = mysql_query($insert);
     die("<meta http-equiv=\"refresh\" content=\"0; url=login.php\">");
   }

else
{
  echo "<form action='' method='post'>

  <table border='0'>

  <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> ";
}

       }
     /*   if($_POST['username'] && $_POST['pass'])
       {

         $name = mysql_query("SELECT * FROM Persons");
         $thedate = date("U"); //grab date and time of the post

         $insertmessage="INSERT into mesej (name,IP,postime,message) values('$name','$IP','$thedate','$message')";

         mysql_query($insertmessage) or die("Could not insert message");

        }     */

   }
}

if(!isset($message))
{
  print "<form action='' method='post' name='form'>";

  print "Your message:<br>";

  print "<textarea name='message' cols='40' rows='2'></textarea><br>";

  print "<a onClick=\"addSmiley('')\"><img src='smile.gif'></a> ";

  print "<a onClick=\"addSmiley('')\"><img src='blush.gif'></a> ";

  print "<a onClick=\"addSmiley('')\"><img src='images/wink.gif'></a> ";

  print "<input type='submit' name='submit' value='submit'></form>";

  print "<script language=\"Java Script\" type=\"text/javascript\">\n";

  print "function addSmiley(a)\n";

  print "{\n";

  print "document.form.message.value += a;";

  print "document.form.message.focus();\n";

  print "}\n";

  print "</script>\n";

  print "<br><br>";
  
}



?>

 

 

Sir is still same does not show the error im thinks something wrong in my code especially when i clicked register button it seems it does not check the

 

  if (empty($_POST['username']) || empty($_POST['pass']) || empty($_POST['pass2'] ))
        {
           $errormsg1= "You did not complete all of the required fields";
        }
        IF (isset($errormsg1)){echo "$errormsg1";}
        // checks if the username is in use

        if (!get_magic_quotes_gpc())
       {
        $_POST['username'] = addslashes($_POST['username']);
       }

        $usercheck = $_POST['username'];

        $check = mysql_query("SELECT username FROM registration WHERE username = '$usercheck'")

         or die(mysql_error());

        $check2 = mysql_num_rows($check);

        
       //if the name exists it gives an error

       if ($check2 != 0)
      {
       die('Sorry, the username '.$_POST['username'].' is already in use.');
      }


       //this makes sure both passwords entered match

       if ($_POST['pass'] != $_POST['pass2'])
      {
       die('Your passwords did not match. ');
      }

      // here we encrypt the password and add slashes if needed

       $_POST['pass'] = md5($_POST['pass']);

       if (!get_magic_quotes_gpc())
      {
       $_POST['pass'] = addslashes($_POST['pass']);

       $_POST['username'] = addslashes($_POST['username']);
      }

 

 

my strong feeling is whether my if wrong in means maybe im misplace the if in wrong place?

Link to comment
Share on other sites

Where you want to display the error message is outside the POST processing code and above the form.

IF (isset($errormsg1)){echo "$errormsg1";}
echo "<form action='' method='post'>

  <table border='0'>

  <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> ";

Also you are still using "Die".

if ($check2 != 0)
      {
       die('Sorry, the username '.$_POST['username'].' is already in use.');
      }

if ($_POST['pass'] != $_POST['pass2'])
      {
       die('Your passwords did not match. ');
      }

Either echo these error messages or set the message to a variable and echo lower above your form.

 

 

Link to comment
Share on other sites

<?php

$db = mysql_connect("localhost", "root") or die("Could not connect."); //username and password

if(!$db) 

die("no db");

if(!mysql_select_db("simple",$db))
if(!mysql_select_db("regis",$db))//database name

	die("No database selected.");

if(isset($_POST['submit'])) //if submit button push has been detected

{

   $message=$_POST['message'];

   if(strlen($message)<1)

   {

      print "You did not input a message";

   }

   else

   {

      $message=strip_tags($message);

      $IP=$_SERVER["REMOTE_ADDR"]; //grabs poster's IP

      $checkforbanned="SELECT IP from admin where IP='$IP'";

      $checkforbanned2=mysql_query($checkforbanned) or die("Could not check for banned IPS");

      if(mysql_num_rows($checkforbanned2)>0) //IP is in the banned list

      {

         print "You IP is banned from posting.";

      }

     else
      
       if(strlen($message)>=1)
       {
         if (isset($_POST['sub']))
         {
          $message2=$_POST['message'];
          $message3=strip_tags($message2);

        if (empty($_POST['username']) || empty($_POST['pass']) || empty($_POST['pass2'] ))
        {
           $errormsg1= "You did not complete all of the required fields";
        }

        // checks if the username is in use

        if (!get_magic_quotes_gpc())
       {
        $_POST['username'] = addslashes($_POST['username']);
       }

        $usercheck = $_POST['username'];

        $check = mysql_query("SELECT username FROM registration WHERE username = '$usercheck'")

         or die(mysql_error());

        $check2 = mysql_num_rows($check);

        
       //if the name exists it gives an error

       if ($check2 != 0)
      {
       print ('Sorry, the username '.$_POST['username'].' is already in use.');
      }


       //this makes sure both passwords entered match

       if ($_POST['pass'] != $_POST['pass2'])
      {
       print ('Your passwords did not match. ');
      }

      // here we encrypt the password and add slashes if needed

       $_POST['pass'] = md5($_POST['pass']);

       if (!get_magic_quotes_gpc())
      {
       $_POST['pass'] = addslashes($_POST['pass']);

       $_POST['username'] = addslashes($_POST['username']);
      }

      // now we insert it into the database


     $insert = "INSERT INTO registration (username, password) VALUES ('".$_POST['username']."', '".$_POST['pass']."')";
     $add_member = mysql_query($insert);
     die("<meta http-equiv=\"refresh\" content=\"0; url=login.php\">");
   }
   IF (isset($errormsg1)){echo "$errormsg1";}
else
{
  echo "<form action='' method='post'>

  <table border='0'>

  <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> ";
}

       }
     /*   if($_POST['username'] && $_POST['pass'])
       {

         $name = mysql_query("SELECT * FROM Persons");
         $thedate = date("U"); //grab date and time of the post

         $insertmessage="INSERT into mesej (name,IP,postime,message) values('$name','$IP','$thedate','$message')";

         mysql_query($insertmessage) or die("Could not insert message");

        }     */

   }
}

if(!isset($message))
{
  print "<form action='' method='post' name='form'>";

  print "Your message:<br>";

  print "<textarea name='message' cols='40' rows='2'></textarea><br>";

  print "<a onClick=\"addSmiley('')\"><img src='smile.gif'></a> ";

  print "<a onClick=\"addSmiley('')\"><img src='blush.gif'></a> ";

  print "<a onClick=\"addSmiley('')\"><img src='images/wink.gif'></a> ";

  print "<input type='submit' name='submit' value='submit'></form>";

  print "<script language=\"Java Script\" type=\"text/javascript\">\n";

  print "function addSmiley(a)\n";

  print "{\n";

  print "document.form.message.value += a;";

  print "document.form.message.focus();\n";

  print "}\n";

  print "</script>\n";

  print "<br><br>";
  
}



?>

 

 

im had done the the correct but still wrong :(

Link to comment
Share on other sites

Here's another version of your page.

<?php
//Include your db connection info//
$host	=  "localhost";
$login 	= "" ;
$pass 	= "";
//database name.//
$db 	= "";

// do some house keeping //
//adds slashes if the magic quotes is off.
function addslash($string)
{
   if (!get_magic_quotes_gpc())
       $string = addslashes($string);
   return $string;
}
if (get_magic_quotes_gpc())
{
function stripslashes_deep($value)
{
$value = is_array($value) ?
array_map('stripslashes_deep', $value) :
stripslashes($value);
return $value;
}
$_POST = array_map('stripslashes_deep', $_POST);
}

$link = mysqli_connect($host, $login, $pass);
mysql_connect("$host","$login","$pass") OR DIE
        ("There is a problem with the system.  Please notify your system administrator." .mysql_error());
mysql_select_db("$db") OR DIE
        ("There is a problem with the system.  Please notify your system administrator." .mysql_error());
//Do general trim to all posed values
function getPostVar($varname){
    if(isset($_POST[$varname])){
        return trim($_POST[$varname]);
    }
    return '';
}
$message = getPostVar('message');
$username = getPostVar('username');
$pass = getPostVar('pass');	
$pass2 = getPostVar('pass2');
//Set some flags used for showing different forms
$banned="f";
$showform1="t"; 
$showform2="f";
$name="notset";		
$password="notset";
$error="";
//Start form1//
if(isset($_POST['submit'])){ //if submit button push has been detected
if(strlen($message)<1){   
	$showform1="t";
        $error.="You did not input a message"; 
}else{   
	$showform1="f";
}//if(strlen($message)<1)
//Check if banned//
      $IP=$_SERVER["REMOTE_ADDR"]; //grabs poster's IP
     $checkforbanned="SELECT IP from admin where IP='$IP'";
     $checkforbanned2=mysql_query($checkforbanned) or die("Could not check for banned IPS");
    if(mysql_num_rows($checkforbanned2)>0) //IP is in the banned list
     {
        $error.= "You IP is banned from posting.";
$banned="t";
     }
    else
{     
//continue if IP passes//
	$banned="f";
}// end if(mysql_num_rows($checkforbanned2)>0) ELSE
}//end form1
//*************************// 
//Start form2
//Set flags
IF (!empty($message) && $banned=="f"){
$showform1="f";
$showform2="t";
}
if (isset($_POST['sub'])){
if (empty($username) || empty($pass) || empty($pass2)){  
$showform2="t";
$error.= "You did not complete all of the required fields<br />";
}
else{
        // checks if the username is in use
$usercheck = $_POST['username'];
$check = mysql_query("SELECT COUNT(username) as usercnt FROM registration WHERE username = '$usercheck'") or die(mysql_error());
WHILE ($ckuser = mysql_fetch_array($check)){
$check2=$ckuser['usercnt'];
//	$check2 = mysql_num_rows($check);
//if the name exists it gives an error
if ($check2 != 0){
$name="bad";
    $error.="Sorry, the username $usercheck is already in use.<br />";
   }
else{
$name="good";	
}
//this makes sure both passwords entered match 	  
if ($_POST['pass'] != $_POST['pass2']){  
$password="bad";	  
      $error.="Your passwords did not match.<br />";
      }
else{
$password="good";	
}
//Check flags to contiue

IF ($name=="bad" || $password=="bad"){
$showform2="t";		
}
IF ($name=="good" && $password=="good"){
$showform2="f";
echo "Thank you";		
//continue processing if name and pass are good	  
// here we encrypt the password and add slashes if needed
$_POST['pass'] = md5($_POST['pass']);
// now we insert it into the database
$username1 = mysqli_real_escape_string($link, $username);
$password1 = $_POST['pass'];

mysql_query("INSERT INTO registration (username, password) VALUES ('$username1', '$password1')");

$thedate = date("U"); //grab date and time of the post

$message = mysqli_real_escape_string($link, $message);
mysql_query("INSERT into mesej (name,IP,postime,message) values('$username1','$IP','$thedate','$message')");

}//IF ($name=="bad" || $password=="bad")
}//if (empty($username) || empty($pass) || empty($pass2))
}//if (isset($_POST['sub']))

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Sample</title>
</head>
<body>

<?PHP
IF (isset($error)){echo "$error";}

IF ($showform2=="t"){  
echo "<form action='' method='post'>";
echo "<table border='0'>";
echo "<tr><td>Username:</td><td>";
echo "<input type='text'name='username' maxlength='60' value='$username' />";
echo "</td></tr>";
echo "<tr><td>Password:</td><td>";
echo "<input type='password' name='pass' maxlength='10' value='$pass' />";
echo "</td></tr>";
echo "<tr><td>Confirm Password:</td><td>";
echo "<input type='password' name='pass2' maxlength='10' value='$pass' />";
echo "</td></tr>";
echo "<tr><th colspan=2><textarea name='message' cols='1' rows='1' style=\"display:none;\">$message</textarea><input type='submit' name='sub' value='Register'></th></tr>";
echo "</table>";
echo "</form> ";
}//IF ($showform2=="t")

IF ($showform1=="t"){
echo "<form action='sample.php' method='post'>";
echo "Your message:<br>";
echo "<textarea name='message' cols='40' rows='2'></textarea><br>";
echo "<a onClick=\"addSmiley('')\"><img src='smile.gif'></a> ";
echo "<a onClick=\"addSmiley('')\"><img src='blush.gif'></a> ";
echo "<a onClick=\"addSmiley('')\"><img src='images/wink.gif'></a> ";
echo "<input type='submit' name='submit' value='submit'></form>";
echo "<script language=\"Java Script\" type=\"text/javascript\">\n";
echo "function addSmiley(a)\n";
echo "{\n";
echo "document.form.message.value += a;";
echo "document.form.message.focus();\n";
echo "}\n";
echo "</script>\n";
echo "<br><br>";  
}//IF ($showform1=="t")
?> 
</body>
</html>

Link to comment
Share on other sites

I was missing a closing bracket after line 92.

<?php
//Include your db connection info//
$host	=  "localhost";
$login 	= "" ;
$pass 	= "";
//database name.//
$db 	= "";

// do some house keeping //
//adds slashes if the magic quotes is off.
function addslash($string)
{
   if (!get_magic_quotes_gpc())
       $string = addslashes($string);
   return $string;
}
if (get_magic_quotes_gpc())
{
function stripslashes_deep($value)
{
$value = is_array($value) ?
array_map('stripslashes_deep', $value) :
stripslashes($value);
return $value;
}
$_POST = array_map('stripslashes_deep', $_POST);
}

$link = mysqli_connect($host, $login, $pass);
mysql_connect("$host","$login","$pass") OR DIE
        ("There is a problem with the system.  Please notify your system administrator." .mysql_error());
mysql_select_db("$db") OR DIE
        ("There is a problem with the system.  Please notify your system administrator." .mysql_error());
//Do general trim to all posed values
function getPostVar($varname){
    if(isset($_POST[$varname])){
        return trim($_POST[$varname]);
    }
    return '';
}
$message = getPostVar('message');
$username = getPostVar('username');
$pass = getPostVar('pass');	
$pass2 = getPostVar('pass2');
//Set some flags used for showing different forms
$banned="f";
$showform1="t"; 
$showform2="f";
$name="notset";		
$password="notset";
$error="";
//Start form1//
if(isset($_POST['submit'])){ //if submit button push has been detected
if(strlen($message)<1){   
	$showform1="t";
        $error.="You did not input a message"; 
}else{   
	$showform1="f";
}//if(strlen($message)<1)
//Check if banned//
      $IP=$_SERVER["REMOTE_ADDR"]; //grabs poster's IP
     $checkforbanned="SELECT IP from admin where IP='$IP'";
     $checkforbanned2=mysql_query($checkforbanned) or die("Could not check for banned IPS");
    if(mysql_num_rows($checkforbanned2)>0) //IP is in the banned list
     {
        $error.= "You IP is banned from posting.";
$banned="t";
     }
    else
{     
//continue if IP passes//
	$banned="f";
}// end if(mysql_num_rows($checkforbanned2)>0) ELSE
}//end form1
//*************************// 
//Start form2
//Set flags
IF (!empty($message) && $banned=="f"){
$showform1="f";
$showform2="t";
}
if (isset($_POST['sub'])){
if (empty($username) || empty($pass) || empty($pass2)){  
$showform2="t";
$error.= "You did not complete all of the required fields<br />";
}
else{
        // checks if the username is in use
$usercheck = $_POST['username'];
$check = mysql_query("SELECT COUNT(username) as usercnt FROM registration WHERE username = '$usercheck'") or die(mysql_error());
WHILE ($ckuser = mysql_fetch_array($check)){
$check2=$ckuser['usercnt'];	
}
//	$check2 = mysql_num_rows($check);
//if the name exists it gives an error
if ($check2 != 0){
$name="bad";
    $error.="Sorry, the username $usercheck is already in use.<br />";
   }
else{
$name="good";	
}
//this makes sure both passwords entered match 	  
if ($_POST['pass'] != $_POST['pass2']){  
$password="bad";	  
      $error.="Your passwords did not match.<br />";
      }
else{
$password="good";	
}
//Check flags to contiue

IF ($name=="bad" || $password=="bad"){
$showform2="t";		
}
IF ($name=="good" && $password=="good"){
$showform2="f";
echo "Thank you";		
//continue processing if name and pass are good	  
// here we encrypt the password and add slashes if needed
$_POST['pass'] = md5($_POST['pass']);
// now we insert it into the database
$username1 = mysqli_real_escape_string($link, $username);
$password1 = $_POST['pass'];

mysql_query("INSERT INTO registration (username, password) VALUES ('$username1', '$password1')");

$thedate = date("U"); //grab date and time of the post

$message = mysqli_real_escape_string($link, $message);
mysql_query("INSERT into mesej (name,IP,postime,message) values('$username1','$IP','$thedate','$message')");

}//IF ($name=="bad" || $password=="bad")
}//if (empty($username) || empty($pass) || empty($pass2))
}//if (isset($_POST['sub']))

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Sample</title>
</head>
<body>

<?PHP
IF (isset($error)){echo "$error";}

IF ($showform2=="t"){  
echo "<form action='' method='post'>";
echo "<table border='0'>";
echo "<tr><td>Username:</td><td>";
echo "<input type='text'name='username' maxlength='60' value='$username' />";
echo "</td></tr>";
echo "<tr><td>Password:</td><td>";
echo "<input type='password' name='pass' maxlength='10' value='$pass' />";
echo "</td></tr>";
echo "<tr><td>Confirm Password:</td><td>";
echo "<input type='password' name='pass2' maxlength='10' value='$pass' />";
echo "</td></tr>";
echo "<tr><th colspan=2><textarea name='message' cols='1' rows='1' style=\"display:none;\">$message</textarea><input type='submit' name='sub' value='Register'></th></tr>";
echo "</table>";
echo "</form> ";
}//IF ($showform2=="t")

IF ($showform1=="t"){
echo "<form action='sample.php' method='post'>";
echo "Your message:<br>";
echo "<textarea name='message' cols='40' rows='2'></textarea><br>";
echo "<a onClick=\"addSmiley('')\"><img src='smile.gif'></a> ";
echo "<a onClick=\"addSmiley('')\"><img src='blush.gif'></a> ";
echo "<a onClick=\"addSmiley('')\"><img src='images/wink.gif'></a> ";
echo "<input type='submit' name='submit' value='submit'></form>";
echo "<script language=\"Java Script\" type=\"text/javascript\">\n";
echo "function addSmiley(a)\n";
echo "{\n";
echo "document.form.message.value += a;";
echo "document.form.message.focus();\n";
echo "}\n";
echo "</script>\n";
echo "<br><br>";  
}//IF ($showform1=="t")
?> 
</body>
</html>

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.