ciao ragā,
Sto seguendo un corso cartaceo di php/mysql
sono giunto al punto di dover inserire i dati nel database da un form html ma non riesco a capire dove sta l'inghippo....
Ovviamente ho creato il database NomeDB con la tabella Nometabella e il programma si connette ed e' tutt'ok i campi sono giusti e tutto...
Questo e' il form
Codice PHP:<html>
<head>
<title>Inserimento</title>
</head>
<body>
<table>
<form metod="post" action="inserimentodati.php">
<tr><td>Nome</td>
<td><input type="text" name="Nome" size="20" maxlength="20"></td></tr>
<tr><td>Cognome</td>
<td><input type="text" name="Cognome" size="20" maxlength="20"></td></tr>
<tr><td>Codice</td>
<td><input type="text" name="Codice" size="10" maxlength="10"></td></tr>
<tr><td coldspan=\"2\"><input type="submit" value="Inserisci"</td></tr>
</form>
</table>
</body>
</html>
Questo e' il file Inserimentodati.php
Mi appare il messsaggio di errore impossibile inserire il record nel databaseCodice PHP:<html>
<head>
<title>Inserimento</title>
</head>
<?php
$host = 'localhost';
$user = 'admin';
$password = 'password';
$database = 'NomeDB';
$db = mysql_connect($host, $user, $password) or die ("impossibile connettersi al server");
mysql_select_db($database, $db) or die ("impossibile connettersi al database");
$query = "insert into Nometabella" .
"(Nome,Cognome,Codice) " .
"VALUES('".
$_REQUEST['Nome'] . "','" .
$_REQUEST['Cognome'] . "','" .
$_REQUEST['Codice'] . "')'" ;
if (!mysql_query($query,$db))
print ("attenzione, Impossibile inserire il record nel database");
if (mysql_query($query,$db))
print ("record inserito con successo");
mysql_close($db);
?>
</body>
</html>

Rispondi quotando