-2

I want the user to obligatory input something in the title when creating a thread, so it doesn't show up as an empty title

I can not find the place to put the right code, can you help me ?

my connect.php

   <?php

$dbname="Jr"; // Indique o nome do banco de dados que será aberto
$user="root"; // Indique o nome do usuário que tem acesso
$password=""; // Indique a senha do usuário

if(!(mysql_connect("localhost",$user,$password))) {
   echo "Não foi possível estabelecer uma conexão com o gerenciador MySQL. Favor Contactar o Administrador.";

} else {
    //echo "Conectado!!!"."<br>";
}

if (mysql_select_db($dbname)) {
    //echo "DB selecionado!";
}

$grava_titulo = $_POST['titulo'];
$grava_mensagem = $_POST['mensagem'];
$grava_tags = $_POST['tags'];

$sql_gravar = mysql_query("INSERT INTO posts (titulo, mensagem, tags) value ('$grava_titulo', '$grava_mensagem', '$grava_tags')");




if($sql_gravar)
{
    echo"<br>";
    echo "A sua mensagem foi enviada com sucesso!"."<br>";
    echo "Obrigado por participar!";
}else
{
    echo "Desculpe, erro ao enviar!";
}
?>

here is the form.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>SOBRE</title>
</head>
<?php
include "css.php";
?>
<body>

<div id="fundo_paginas">

    <div id="geral_paginas">


<?php
include "menu.php";
?>


        <div id="conteudo">
            <div id="titulo_pagina">
                <p>Posts</p>
            </div><!--titulo_pagina-->

            <form id="form1" name="form1" method="post" action="">
          <table width="327" border="0">
            <tr>
              <th width="80" scope="row"><div align="left">Titulo</div></th>
              <td width="237"><label>
                <input name="titulo" type="text" id="form" size="35" maxlength="100" />
              </label></td>
            </tr>
            <tr>
              <th scope="row"><div align="left">Mensagem</div></th>
              <td><label>
                <textarea name="mensagem" cols="40" rows="6" id="form"></textarea>
              </label></td>
            </tr>
            <tr>
              <th scope="row"><div align="left">Tags</div></th>
              <td><label>
                <input name="tags" type="text" id="form" size="35" />
              </label></td>
            </tr>
            <tr>
              <th scope="row">&nbsp;</th>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <th scope="row">&nbsp;</th>
              <td><label>
                <input type="submit" name="Submit" value="   Enviar   " />
              </label></td>
            </tr>
          </table>
        </form>     
    <center>
        <?php
        include "conexao/conexao.php";
        ?>
    </center>
        </div><!--conteudo-->

      <div style="clear:both">

    </div><!-- geral_paginas -->

</div><!--fundo_paginas-->

</body>
</html>
jonas_7
  • 1
  • 1
  • 1
    Sorry, i don't understand what you're asking. What do you mean with "do not send blank fields and errors"? – STT LCU Jan 20 '14 at 16:00
  • 4
    One method is to use conditional statements. Google `if(empty` and `if(isset` Oh, and by the way... [**You're open to SQL injection**](http://stackoverflow.com/q/60174/) – Funk Forty Niner Jan 20 '14 at 16:04

2 Answers2

1

Basically, you need to check the information before it goes to the database, if you look at this it will help you. http://www.w3schools.com/php/php_form_validation.asp

green_arrow
  • 1,257
  • 7
  • 21
  • 37
  • I want the user to obligatory input something in the title when creating a thread, so it doesn't show up as an empty title – jonas_7 Jan 20 '14 at 16:35
1

As far as i understand your question, you want to block empty fields and also check the field has desired type of input.

These are two links which may help you:

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Nithin Dinesh
  • 133
  • 10