k... so, here's the thing...

I'm creating a User's Interface to insert some data into a database, and there are some fields that have foreign keys to other tables, which i have listed in a <SELECT> form, so the user would just select the vlue from a list instead of inserting a new one, which might cause some trouble with the db's integrity... when i want to insert the value to the table, i must do a subquery to obtain the value that goes into the table... that's where i have the problem... mysql just returns an error telling me i have an error in my MySQL syntax...
here's the code for 'insertar.php':

      INSERT INTO Region (Nombre, Cod_Pais)
      VALUES ('$_POST[nombre_region]', (SELECT Cod_Pais FROM Pais WHERE Nombre=$_POST[opcion_pais]))", $cos_s)){
      echo "Fila insertada en la tabla 'Region' existosamente<br />";
      die("Error al insertar registro en tabla 'Region'<br />" . mysql_error());

and this is the code for 'insertar_datos.html':

<form action="insertar.php" method="post">
   Nombre de la Region: <input type="text" name="nombre_region" /><br />
   Pais de la Region: <select name="opcion_pais">
      <option>--Seleccionar Pais--</option>
         $resultado_pais = mysql_query(" SELECT * FROM Pais ORDER BY Nombre");
         while($row = mysql_fetch_array($resultado_pais, MYSQL_ASSOC)){
            echo "<option value=\"" . $row[Cod_Pais] . "\">" . $row[Nombre] . "</option>";
   </select><br />
   <input type="submit" name="submit_region" value="Insertar Region">

this is the output: Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/www/lapuglia.awardspace.com/insertar.php on line 21

9 Years
Discussion Span
Last Post by shaikh_mshariq

Try to debug the code. Echo your query on your page and then copy paste that code to your mysql client's console there u can have a brief idea about that. I dont know what is the problem in that but I used this trick to solve problem quickly.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.