Hi!!

I'm pretty new to PHP but I've made this system, that works with MySQL, wich can upload text so like a tagwall or something, but this system does NOT print wether the fiels are empty or full. Can you show me how to make my PHP script detect non-filled fields?

Thanx!
g0ldDuCk

    if(!$field)
    print "field is empty";

      Yes thx but how do I intergrate that in this code:

      <BODY>
      <?
      if($password == "*"){
      echo "The Headline is Online. <A HREF='index.php'>Show</A>";
      $db = mysql_connect("localhost","user","
      *");
      mysql_select_db("user",$db);
      $news_date = time();

      mysql_query("INSERT INTO scripts (date, headline, text, name) VALUES ('$news_date','$news_headline','$news_text','$news_name')");

      } else {
      ?>
      <FORM METHOD=POST ACTION="submit_news.php">
      PassWord:<BR>
      <INPUT TYPE=PASSWORD NAME=kodeord><BR>
      Headline:<BR>
      <INPUT TYPE=TEXT NAME=nyhed_overskrift><BR>
      Name:<BR><INPUT TYPE=text NAME=nyhed_navn VALUE=admin>
      <BR>
      Text:<BR>
      <TEXTAREA NAME=nyhed_tekst>Write the story here</TEXTAREA><BR>
      <INPUT TYPE=submit VALUE=Write!!>
      </FORM>
      <?
      }
      ?>
      </BODY>

        This message is translated to english from danish there might be some missing translations. Sorry! But it shouldn't affect the code.

          PHP being server-side, you cannot check if a field is empty before posting the form.

          Once the form is received, php can check the values to check the password for example.

          To check the form before sending it, you must use client-side script, like javascript.

          An easy method to do this is the use of regular expressions.

          &lt;script language='javascript'&gt;
          function check(f)
          {
          with (f)
          {
          if ( !kodeord.value.match( '[ \t\n]+$' ) )
          {
          alert('Provide a password');
          return;
          }
          }
          }
          &lt;/script&gt;

          &lt;FORM METHOD=POST ACTION="submit_news.php" onsubmit="check"&gt;

          ...

          &lt;/FORM&gt;

            I forgot the () after check
            The code is check( this )

              yeah greggory thx! BUT I know that i can use JavaScript. But i dont want to use that because then I've got to make 2 pages instead of just one PHP site. And I know that u cant use PHP to validate the form before submitted. But that's not what I wanted either. Just a extension of my PHP script, that can validate the form, and if a field is empty, it'll say something like: Field One's empty, u know.

              Hope u've understood that ;-)

                Write a Reply...