simple beginner question....

A

Anonymous

Guest
Take a look to this code :
<?
if($submit)
{
echo entrou;
$db = mysql_connect("localhost", "parxal","sjrlop");
mysql_select_db("maillist",$db);
$sql = " INSERT INTO maillist (name,email,morada,url) values ('$nome','$email','$morada','$url') ";
echo "Thank you! Information entered.\n";
}
else
{
?>
<form name="form1" method="post" action="index.php">
<p>Nome :
<input type="text" name="nome">
</p>
<p>Morada:
<input type="text" name="morada">
</p>
<p>Email:
<input type="text" name="email">
</p>
<p>Url:
<input type="text" name="url">
</p>
<p>
<input type="submit" name="submit" value="Enter information">

</form>
<?
echo $nome;
}
?>

This is an html form, and his values are going to a database.
but, the variables are always empty, so de database records are empty!
when i right in the end echo $nome, $nome havent got ant value, why?
<input type="text" name="nome"> this should be tranform in $nome var?
 
parxal said:
Take a look to this code :
<?
if($submit)
{
echo entrou;
$db = mysql_connect("localhost", "parxal","sjrlop");
mysql_select_db("maillist",$db);
$sql = " INSERT INTO maillist (name,email,morada,url) values ('$nome','$email','$morada','$url') ";
echo "Thank you! Information entered.\n";
}
else
{
?>
<form name="form1" method="post" action="index.php">
<p>Nome :
<input type="text" name="nome">
</p>
<p>Morada:
<input type="text" name="morada">
</p>
<p>Email:
<input type="text" name="email">
</p>
<p>Url:
<input type="text" name="url">
</p>
<p>
<input type="submit" name="submit" value="Enter information">

</form>
<?
echo $nome;
}
?>

This is an html form, and his values are going to a database.
but, the variables are always empty, so de database records are empty!
when i right in the end echo $nome, $nome havent got ant value, why?
<input type="text" name="nome"> this should be tranform in $nome var?


I am not a guru , however why you don't separate them ?

First write the html with web form

Code:
<form name="form1" method="post" action="index.php">
  <p>Nome : 
    <input type="text" name="nome">
  </p>
  <p>Morada: 
    <input type="text" name="morada">
  </p>
  <p>Email: 
    <input type="text" name="email">
  </p>
  <p>Url: 
    <input type="text" name="url">
  </p>
  <p> 
    <input type="submit" name="submit" value="Enter information">
   
</form>


then write index.php and insert all your code to write on database .

your index.php should like this

Code:
<?
$db = mysql_connect("localhost", "parxal","sjrlop");
mysql_select_db("maillist",$db);
$sql = " INSERT INTO maillist (name,email,morada,url) values ('$nome','$email','$morada','$url') ";
echo "Thank you! Information entered.\n";
?>

You can insert some if/else to check if the email is just on database .. and other checks ....[/code]
 
i made that! bue the problem is the same! i have got a textbox in my form named "nome", is supose that php create a variable names $nome that contain the textbox value.
but my doesn't do that! the var are empty!
 
Back
Top