Page 1 of 1

taking input...

Posted: Thu Nov 13, 2008 5:45 pm
by ola ola
hiya
I have written this to get some input from the user as form input and send me mail, I can get input from 2 fields but can't take the input from the rest, can anyone please help me to solve the problem?
here is the php code and html code as well.

Code: Select all

 
<?php
$to = "protecty@gmail.com";
$subject = "php email test";
 
$name = $_REQUEST['name'] ;
$ans = $_REQUEST['txtq'] ;
$ans2 =$_POST['msg'];
 
$headers = "From: $name";
$sent = mail($to, $subject, $ans, $ans2, $headers) ;
if($sent)
{print "Your mail was sent successfully"; }
else
{print "Sorry, an error occure, can't send your mail"; }
?> 
 

Code: Select all

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
    background-color: #7996B1;
}
-->
</style></head>
 
<body>
<form id="form1" name="form1" method="post" action="ques.php">
  <p>Enter your name here 
    <label>
    <input name="name" type="text" id="name" size="40" />
    </label>
  </p>
  <p>&nbsp;</p>
  <p>Q1. What other features you want to see in this site? (example: email, help, forum etc.)</p>
  <p>
    <label>
    <textarea name="txtq" id="txtq" cols="45" rows="5"></textarea>
    </label>
  </p>
  <p>
    <label>Q3. Any recommand for this website... (any other related useful topics)<br />
    <br />
    <textarea name="msg" cols="45" rows="5" id="msg"></textarea>
    </label>
  </p>
  <p>Select anyone please</p>
  <p>
    <label>
    <input type="radio" name="radio" id="radio_tall" value="radio_tall" />
    Tall</label>
  </p>
  <p>
    <label>
    <input type="radio" name="radio" id="radio_short" value="radio_short" />
    Short</label>
  </p>
  <p>
    <label>
    <input type="submit" name="submit" id="submit" value="Submit" />
    </label>
  </p>
</form>
<p>&nbsp;</p>
</body>
</html>
 
 

Re: taking input...

Posted: Thu Nov 13, 2008 6:28 pm
by aceconcepts
When you "get" your values use $_POST and not $_REQUEST.

Also, try using a naming convention for your fields such as "strName" in place of "name".

Re: taking input...

Posted: Thu Nov 13, 2008 6:37 pm
by ola ola
aceconcepts wrote:When you "get" your values use $_POST and not $_REQUEST.

Also, try using a naming convention for your fields such as "strName" in place of "name".
I tried its not working.....

Re: taking input...

Posted: Thu Nov 13, 2008 6:43 pm
by Eran
Also, try using a naming convention for your fields such as "strName" in place of "name".
I have to ask - why is this recommended?

Re: taking input...

Posted: Thu Nov 13, 2008 8:24 pm
by aceconcepts
I never stated it was recommended. I simply find it helpful to use such naming conventions in order to distinguish between data types associated with a field. Also, One might feel compelled to name a variable as "name" in order to store posted values. This may cause conflicts with reserved names by relation database management systems such as MySQL.

Just a thought though.

Re: taking input...

Posted: Fri Nov 14, 2008 8:00 am
by Eran
'name' is not a reserved name in MySQL
I usually try to map input names to match field names in database tables. Creating abbreviations that are only meaningful for whoever wrote them is bad practice in my opinion

Re: taking input...

Posted: Sat Nov 15, 2008 5:56 am
by aceconcepts
I know 'name' is not a reserved name in MySQL. But if you start off using a naming convention a lot like the one you just suggested it will save you a lot of revision work in the future.