-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
  • 33,050
  • 15
  • 95
  • 195
manuel mourato
  • 801
  • 1
  • 12
  • 36

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
  • 46,730
  • 8
  • 72
  • 95