Jump to content

HOW THE IT CHECK THE MSG FUNCTION AFTER CLICK THE SUBMIT BUTTON


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.");}}
$message=$_POST['message'];


  print "<form action='registration.php' method='post'onsubmit='return msg();'>";

  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='Set Name'></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>";
?>

<script type="text/javascript">
<?php
  function msg(){

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

{



   if(strlen($message)<1)

   {    
    // print "You did not input a message";
      echo"<SCRIPT LANGUAGE='javascript'>alert('You did not input a message')</SCRIPT>";

   }

   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)
       {

         $message=strip_tags($message);
         echo("<SCRIPT LANGUAGE='JavaScript'>window.alert('$message')</SCRIPT>");
        // die("<meta http-equiv=\"refresh\" content=\"0; url=registration.php\">");
       }
        $message=$_POST['message'];
         $message=strip_tags($message);
     /*   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");

        }     */

   }
}
return false;
}
return true;
</script>
?>




 

 

 

This is my code in my submit2.php im clicked submit button but if it is empty it should return an javascript alert error but why it directs through registration.php without reading the rules?

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.