taking input...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ola ola
Forum Newbie
Posts: 3
Joined: Fri Oct 31, 2008 9:10 pm

taking input...

Post 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>
 
 
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: taking input...

Post 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".
ola ola
Forum Newbie
Posts: 3
Joined: Fri Oct 31, 2008 9:10 pm

Re: taking input...

Post 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.....
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: taking input...

Post 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?
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: taking input...

Post 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.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: taking input...

Post 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
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: taking input...

Post 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.
Post Reply