Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

simple beginner question....

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

simple beginner question....

Postby parxal » Thu Nov 07, 2002 6:05 am

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
New php-forum User
New php-forum User
 
Posts: 40
Joined: Thu Nov 07, 2002 5:58 am

Re: simple beginner question....

Postby leon » Thu Nov 07, 2002 6:17 am

parxal wrote: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: Select all
<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: Select all
<?
$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]
User avatar
leon
New php-forum User
New php-forum User
 
Posts: 36
Joined: Sat Aug 03, 2002 11:54 am

Postby parxal » Thu Nov 07, 2002 8:51 am

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!
parxal
New php-forum User
New php-forum User
 
Posts: 40
Joined: Thu Nov 07, 2002 5:58 am


Return to PHP coding => General

Who is online

Users browsing this forum: Google Feedfetcher and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.