Forum Moderators: coopster

Message Too Old, No Replies

My Insert don't work!

         

Method

4:19 pm on Feb 9, 2004 (gmt 0)

10+ Year Member



I'm trying to understand PHP.
This is a simple Form but it doesn't work.
Can you have a look? Thanks


<b>form.html</b>
<html>
<body>
<div align="center">
<p><font size="6"><strong><font color="#0000FF">Form di prova</font></strong></font>
<font color="#0000FF"><strong> </strong></font></p>
<p>&nbsp;</p>
</div>
<form method="post" action="install.php">
<p align="center"><font color="#0000FF" size="5"><strong><font size="4">E-mail:
<input type="text" name="email">
</font></strong></font></p>
<p align="center"><font color="#0000FF" size="5"><strong><font size="4">Nome :
<input type="text" name="nome">
</font></strong></font></p>
<p align="center"><font color="#0000FF" size="5"><strong><font size="4">Cognome :
<input type="text" name="cognome">
</font></strong></font></p>
<p align="center"><font color="#0000FF" size="5"><strong><font size="4">Codice Fiscale :
<input type="text" name="codfisc">
</font></strong></font></p>
<p align="center"><font color="#0000FF" size="5"><strong><font size="4">Telefono:
</font></strong></font><font size="4"><strong>
<input type="text" name="telefono">
<br>
</strong></font> </p>
<p align="center">
<input type="submit" value="Invia">
</p>
</form>
<div align="center">
</div>
</body>
</html>

install.php

<HTML>
<HEAD><TITLE>Inserimento dati personali</TITLE></HEAD><BODY>
<?php
$db_host = "myhost";
$db_name = "mydb";
$db_user = "user";
$db_password = "password";
$db = mysql_connect ($db_host, $db_user, $db_password);
if ($db == FALSE)
die ("Errore nella connessione");
print ("Connesso con successo");
mysql_select_db ($db_name)
or die ("<br>Errore nella selezione del database</br>");
print ("<br>Database selezionato</br>");
$email="email";
$nome= "nome";
$cognome= "cognome";
$codfisc="codfisc";
$telefono="telefono";
$query = "INSERT INTO personal (email, nome, cognome, codfisc, telefono) VALUES ('$email','$nome','$cognome','$codfisc','$telefono')";
//echo $query;
//echo $db;
if ($result = mysql_query ($query,$db))
{ echo "<br>L'inserimento è avvenuto con successo</br>";}
else { echo "<br>L'inserimento NON è avvenuto con successo</br>"; }
mysql_close($db);
?>
</BODY>
</HTML>

THANKS!

Timotheos

4:33 pm on Feb 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Method, Welcome to WebmasterWorld!

My guess is your register globals [php.net] is off. You'll need to access your post variables with the $_POST [php.net] superglobal. For example, you can get the email variable by $email = $_POST['email'].

dreamcatcher

8:33 pm on Feb 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The other problem is this:


$email="email";
$nome= "nome";
$cognome= "cognome";
$codfisc="codfisc";
$telefono="telefono";

Which means that no matter what you type in your input fields, the value will always remain the same as you are assigning second values to each variable. This will over write whatever the value was originally.

:)

Method

1:17 pm on Feb 10, 2004 (gmt 0)

10+ Year Member



How must I write to not make overwrite?
Sorry for my inexperience but I am a beginner!

Method

1:51 pm on Feb 10, 2004 (gmt 0)

10+ Year Member



My insert works!
Thank you for your availability!
:) :)