Enter data by PHP

0

After submitting the form I do the following:

 $n_processo = $_POST['n_processo'];
 $nome = $_POST['nome'];
  $dia = $_POST['dia'];
  $mes=$_POST['mes'];
  $ano = $_POST['ano'];
  $data = $dia."-".$mes."-".$ano;
    $cc = $_POST['cc'];
    $curso =$_POST['cursos'];
  $ciclo1 = $_POST['ciclo'];
  $ciclo2 = $_POST['ciclo2'];
  $ciclo = $ciclo1."-".$ciclo2;' 


    $sqlcurso = mysql_query("SELECT n_curso FROM cursos WHERE designacao LIKE '".$curso."'");

    $row = mysql_fetch_array($sqlcurso);    


    $sql = "INSERT INTO alunos(n_processo,nome,data_nasc,cc,n_curso,ciclo_formacao)
          VALUES ('".$n_processo."','".$nome."','".$data."','".$cc."','".$row['n_curso']."','".$ciclo."')";

    if(!mysql_query($sql))
    {
        echo"1";
    }
    else
    {
        $sql2 = mysql_query("SELECT n_processo FROM alunos WHERE n_processo = '".$n_processo."'");
      $sql22 = mysql_num_rows($sql2);

      if($sql22 > 0)
      {
        echo "2";
      }
      else
      {
        echo "3";
      }
  }

I was confused because supposedly the exclamation point (!) means different as in the above query it indicates when the query did not work, would give a message, below did the query to see if there is already a record with that primary key, if there is the message 2 otherwise it gives the message 3 that means that it was inserted successfully, but only is inserted when it returns the message 2 does it mean it already exists? Are I going to pack things?

    
asked by anonymous 10.04.2016 / 20:40

0 answers