Ver Mensaje Individual
  #5 (permalink)  
Antiguo 12/09/2009, 14:59
Xbio
 
Fecha de Ingreso: septiembre-2009
Mensajes: 20
Antigüedad: 17 años
Puntos: 0
Respuesta: Obtener valor de un campo

Pues si, esa es mi intencion. para así luego poder relacionar autores y libros

Hee probado el codigo y me sale este error:

Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\web\Scripts\upload_nuevo_libro.php on line 25

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\xampp\htdocs\web\Scripts\upload_nuevo_libro.php on line 26

Pongo como quedaria el codigo por si no lo he puesto bien
Código PHP:
<?php


$basedatos 
= "test";
$titulo= htmlentities($_GET["titulo"]);
$autor= htmlentities($_GET["autor"]);
$editorial= htmlentities($_GET["editorial"]);
$isbn= htmlentities($_GET["isbn"]);
$precio= htmlentities($_GET["precio"]);

$sql = "insert into libros values (null,'$titulo','$editorial','$isbn','$precio')";
$sql2 ="insert into autores values (null,'$last_id','$autor')";

$sql3 = "SELECT * FROM `libros` ORDER BY id_libro DESC"; //si es que se llama id_libros
$result = mysql_query($sql3, $link);
$row = mysql_fetch_array($result);
$i = 0;
while ((
$row)&&($i==0)){
$last_id = $row["id_libro"];//en este ciclo lo que hago es llegar al último registro y leer su id que es el auto_increment que estás buscando
$i = $i + 1;
}

mysql_connect("localhost", "root", "prueba"); 
mysql_select_db("test"); 


 
$consulta="SELECT * FROM libros WHERE isbn='$isbn'";

$resultado=mysql_query($consulta) or die (mysql_error()); 

if (
mysql_num_rows($resultado) == 0) 
{ 

$result = mysql_query($sql);
$result2 = mysql_query($sql2);

if (!
$result && !$result2) {
    die(
"<h2 align='center'>No se ha podido crear la tabla mysql</h2>".mysql_error());
}else{

echo (
'<table width="390" border="0">
  <tr>
    <td width="384"><strong><u>El libro ha sido introducido correctamente, gracias.</u></strong></td>
  </tr>
</table>
<table width="390" border="0">
  <tr>
    <td width="384">¿Que desea hacer?</td>
  </tr>
</table>
<table width="317" border="1">
  <tr>
    <td width="145" align="center"><strong>Ir a inicio</strong></td>
    <td width="162" align="center" valign="bottom">'
);
echo
"<a href=\"javascript:history.back()\" ><strong>Introducir otro libro</strong></a></td>
  </tr>
</table>
"
;

} 



}else{
    echo 
"<b>Error:</b> El libro introducido ya existe en nuestra base de datos, por favor introduzca otro ";
    echo 
"<a href=\"javascript:history.back()\">Regresar</a>";
}?
sobre lo de null quedaria así¿no?
Código PHP:
$sql = "insert into libros values ('$titulo','$editorial','$isbn','$precio')";
$sql2 ="insert into autores values ('$last_id','$autor')"; 
gracias