-1

I have created a table with an AUTO INCREMENT column (Id, primary key), and have done the following php code:

    $med="MED0x";
    $sql=" INSERT INTO Inscricoes2 (`Nome`,`Nome Clinico`, `Numero Cedula`, `Email`, `Descricao`) VALUES ('$nome_completo', '$nome_clinico', '$numero_cedula', '$email' , '$comentario') " ;
    $num=mysql_insert_id($con);
    $resultado=$med . $num;
    echo "$resultado";

But it doesnt echo anything, and an error appears. What is wrong here?

Bart Friederichs
  • 32,037
  • 14
  • 96
  • 185
manuel mourato
  • 771
  • 1
  • 7
  • 33

1 Answers1

4

That is because you are never executing the query, hence there is no insert id.

mysql_query($query);
$num=mysql_insert_id($con);

How can I prevent SQL injection in PHP?

Community
  • 1
  • 1
Hanky Panky
  • 45,969
  • 8
  • 69
  • 95