Current location: Hot Scripts Forums » Programming Languages » PHP » $_POST tried


$_POST tried

Reply
  #1 (permalink)  
Old 04-01-09, 10:56 PM
reshma reshma is offline
Newbie Coder
 
Join Date: Mar 2009
Posts: 38
Thanks: 0
Thanked 2 Times in 2 Posts
$_POST tried

i did what u guys suggested,but still i am not anle to get it...this is the code,

<html>

<body>

<form name="myForm" >
Customer ID: <input type= "text" size=3 name="customer_id" onBlur=getInfo();><br>
<input type="submit" value= "Submit" name= "customerid">
</form>
<div id="txtHint"><b>Customer info will be listed here.</b></div>


</body>

</html>


and the PHP code is:

<?php
$customer_id=$_POST['customerid'];
if($customer_id == 003)
{
echo "Jim";
}

else {echo " No customer name available";}
?>
Reply With Quote
  #2 (permalink)  
Old 04-01-09, 11:45 PM
kaceykeleher kaceykeleher is offline
Newbie Coder
 
Join Date: Mar 2009
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
What exactly are you attempting to do?

And for the future, be sure and put your code between the proper tags, which you can find in the posting box. For example, your PHP code should be placed between the PHP brackets, and the same with HTML. It makes it much easier to read.

Correct me if I'm wrong, but it looks like you are using the form to display a persons name once they enter their Customer ID, and once they click outside of the box, using JavaScript? It also looks as though you are not using a database to store information, but instead just telling your code that if they happen to enter 003 then the name 'Jim' will be displayed.

If you could let me know a little bit about what you are trying to do, I'd be more than happy to give you any help I can. Also, could you post your JavaScript for the getInfo() function?

Last edited by kaceykeleher; 04-01-09 at 11:50 PM.
Reply With Quote
  #3 (permalink)  
Old 04-01-09, 11:50 PM
reshma reshma is offline
Newbie Coder
 
Join Date: Mar 2009
Posts: 38
Thanks: 0
Thanked 2 Times in 2 Posts
I am sorry if u had trouble reading the code. i basically just want to check if the value of customer id is getting posted to my PHP code from the HTML form, and thats the reason why i don't have a database mentioned.

I hope u understood what my point is.

Thank you
Reply With Quote
  #4 (permalink)  
Old 04-02-09, 12:13 AM
kaceykeleher kaceykeleher is offline
Newbie Coder
 
Join Date: Mar 2009
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Alright, I made a quick little HTML/PHP file without any storage database. Basically, it uses a form to check an ID, and if they enter a specific number, it calls back the name.

Here is the code:
PHP Code:

<?


if ( isset($_POST['submit']) )
{
    
$customerID $_POST['customerID'];
    
$customerName 'Jim';
    
    if (
$customerID == "003")
    {
        
$customerInfo 'Hello, ' $customerName '.';
    }
    else
    {
        
$customerInfo 'We do not have any information for Customer ID # ' $customerID '';
    }
}

?>

<!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>
</head>
<body>
<form action="" method="post">
<div id="container">
    <div class="formRow">
        Customer ID:
        <input name="customerID" type="text" size="20" />
    </div>
    <div class="formRow">
        <input name="submit" type="submit" value="submit" />
    </div>
    <div class="formRow">
        <? echo $customerInfo?>
    </div>
</div>
</form>
</body>
</html>
If you would like to see it in action, go to this page. Customer # 003 has information stored, but others do not.

Is this what you are interested in?
Reply With Quote
  #5 (permalink)  
Old 04-02-09, 12:17 AM
reshma reshma is offline
Newbie Coder
 
Join Date: Mar 2009
Posts: 38
Thanks: 0
Thanked 2 Times in 2 Posts
Thank you so much. This exactly what i was trying to do, i hope i can get back to you in future if have any more doubts.The thing is i am completely new to this.Thanks again
Reply With Quote
  #6 (permalink)  
Old 04-02-09, 12:26 AM
kaceykeleher kaceykeleher is offline
Newbie Coder
 
Join Date: Mar 2009
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Not a problem! And just so you know, if you'd like to add more information to a specific ID, make sure you add the variables under $customerID before calling them anywhere else.

An example:
PHP Code:

if ( isset($_POST['submit']) )
{
    
$customerID $_POST['customerID'];
    
$customerName 'Jim';
    
$customerAddress '123 Jones Street';
    
$customerState 'Iowa';
         
    if (
$customerID == "003")
    {
        
$customerInfo 'Hello, ' $customerName '.<br />';
        
$customerInfo .= 'Your address is: ' $customerAddress ' ' $customerState ''//Be sure that any additional lines use $customerInfo .= 'info';
    

Good luck!
Reply With Quote
  #7 (permalink)  
Old 04-04-09, 06:27 PM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
I think the original issue in your script was that the form field name "customer_id" didn't match $_POST['customerid'];, so you would never get an accurate result.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 08:32 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.