Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
whats wrong with this code, I want to display 'contact'.
Old 09-20-2008, 03:45 AM whats wrong with this code, I want to display 'contact'.
Novice Talker

Posts: 4
Name: dhakalall chhetri
Trades: 0
i want to get contact number as output but i see no data and no error in code generated, plz help. i have written my code below:





<html>
<body>
<center>
<table border="1">
<form method="post" action="out.php">
<tr>
<td>Name:</td><td><input type="text" name="bhai" size="30"></td>
</tr>
<tr>
<td><input type="submit" value="get data" size="20"></td>
</tr>
</form> </table>
</center>
</body></html>
<?
$a="$_POST[name]";
$user="root";
$host="localhost";
$password="";
$database="diki";
$connection=mysql_connect($host,$user,$password);
$db=mysql_select_db($database,$connection) or die( "Unable to select database");
$query = "SELECT contact FROM member where f_name='$a'";
$result=mysql_query($query) or die ("couldnot execute qrery");
$row=mysql_fetch_array($result);
echo "contact:$a";
mysql_close();
?>
hotstar07 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-20-2008, 03:52 AM Re: whats wrong with this code, I want to display 'contact'.
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
is there an entry in the database of "$_POST[name]" ?
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-20-2008, 04:39 AM Re: whats wrong with this code, I want to display 'contact'.
Average Talker

Posts: 24
Trades: 0
You're trying to print "contact:$a" after end of page </body></html> ?
__________________
+
Please login or register to view this content. Registration is FREE

eugen is offline
Reply With Quote
View Public Profile
 
Old 09-20-2008, 05:39 AM Re: whats wrong with this code, I want to display 'contact'.
maxxximus's Avatar
Extreme Talker

Posts: 219
Name: Rob
Location: UK
Trades: 0
Try this for size
PHP Code:
<html>
<body>
<center>
<table border="1">
<form method="post" action="<?php $_SERVER['PHP_SELF'?>">
<tr>
<td>Name:</td><td><input type="text" name="bhai" size="30"></td>
</tr>
<tr>
<td><input type="submit" value="get data" size="20"></td>
</tr>
</form> </table>
<?php
if ($_POST)
{
$a=$_POST['bhai'];
$user="root";
$host="localhost";
$password="";
$database="diki";
$connection=mysql_connect($host,$user,$password);
$db=mysql_select_db($database,$connection) or die( "Unable to select database");
$query "SELECT contact FROM member where f_name='$a'";
$result=mysql_query($query) or die ("couldnot execute qrery");
$row=mysql_fetch_array($result);
echo 
"contact: ".$row['contact'];
mysql_close();
}
?>
</center>
</body></html>
maxxximus is offline
Reply With Quote
View Public Profile
 
Old 09-20-2008, 09:40 AM Re: whats wrong with this code, I want to display 'contact'.
stoot98's Avatar
Ultra Talker

Posts: 427
Name: Stuart
Location: Glasgow, Scotland
Trades: 0
Listen to Chris, your assignment of the $a variable is to a the string "$_POST[name]" rather than the value in the posted 'name' variable.

Should be -
PHP Code:
$a $_POST['name']; 
stoot98 is offline
Reply With Quote
View Public Profile
 
Old 09-20-2008, 10:01 AM Re: whats wrong with this code, I want to display 'contact'.
maxxximus's Avatar
Extreme Talker

Posts: 219
Name: Rob
Location: UK
Trades: 0
Quote:
Originally Posted by stoot98 View Post
Listen to Chris, your assignment of the $a variable is to a the string "$_POST[name]" rather than the value in the posted 'name' variable.

Should be -
PHP Code:
$a $_POST['name']; 
The POST array will not contain the key 'name' as none exists. The POST array will contain the key of 'bhai'so it is this that needs to be accessed.

PHP Code:
$a $_POST['bhai']; 
maxxximus is offline
Reply With Quote
View Public Profile
 
Old 09-20-2008, 11:49 AM Re: whats wrong with this code, I want to display 'contact'.
stoot98's Avatar
Ultra Talker

Posts: 427
Name: Stuart
Location: Glasgow, Scotland
Trades: 0
Neither it will. Good spot.
stoot98 is offline
Reply With Quote
View Public Profile
 
Old 09-20-2008, 04:49 PM Re: whats wrong with this code, I want to display 'contact'.
Average Talker

Posts: 25
Trades: 0
Quote:
Originally Posted by hotstar07 View Post
i want to get contact number as output but i see no data and no error in code generated, plz help. i have written my code below:





<html>
<body>
<center>
<table border="1">
<form method="post" action="out.php">
<tr>
<td>Name:</td><td><input type="text" name="bhai" size="30"></td>
</tr>
<tr>
<td><input type="submit" value="get data" size="20"></td>
</tr>
</form> </table>
</center>
</body></html>
<?
$a="$_POST[name]";
$user="root";
$host="localhost";
$password="";
$database="diki";
$connection=mysql_connect($host,$user,$password);
$db=mysql_select_db($database,$connection) or die( "Unable to select database");
$query = "SELECT contact FROM member where f_name='$a'";
$result=mysql_query($query) or die ("couldnot execute qrery");
$row=mysql_fetch_array($result);
echo "contact:$a";
mysql_close();
?>
By running the script exactly as you have it, I don't see the point in the database call. Your not using any data from the database.

You've refereed to a post variable that isn't available. But even with that change, your code doesn't make use of the DB. $a simply = Your post var, you could do that without the db call.
webhostingultra is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to whats wrong with this code, I want to display 'contact'.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.28383 seconds with 12 queries