Current location: Hot Scripts Forums » Programming Languages » PHP » fail to get result using variable in php


fail to get result using variable in php

Reply
  #1 (permalink)  
Old 04-13-10, 03:12 AM
ycm ycm is offline
New Member
 
Join Date: Apr 2010
Posts: 4
Thanks: 0
Thanked 3 Times in 3 Posts
fail to get result using variable in php

Hi,

I am writing a code below, where it get the variable $nvesel from a form name login_page.php,
the issue here, if the nvesel is hardcode, the query can run correctly, but when using the variable
it failed to give any output. Pls can someone help? Im still new in this php thing. FYI, im using oracle db.
PHP Code:

#get data from login_page.php
$nvesel=$_POST["vesel"];
$kata_laluan=$_POST["pwd"];
#$nvesel=JHF1074T;  / if hardcode, this query can run

#check if data exist
$query_vesel"SELECT no_vesel,kata_laluan from STATUS_PENGGUNA where no_vesel=$nvesel"

# perform the query 
$result odbc_exec($connect$query_vesel);

# fetch the data from the database 
while(odbc_fetch_row($result))
$no_vesel odbc_result($result1); $id_pemilik odbc_result($result2); 
print(
"$no_vesel $id_pemilik\n"); } 

Last edited by job0107; 04-13-10 at 07:54 AM.
Reply With Quote
  #2 (permalink)  
Old 04-13-10, 07:55 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
You will need to post your form.
__________________
Jerry Broughton
Reply With Quote
The Following User Says Thank You to job0107 For This Useful Post:
mysamsung (04-17-10)
  #3 (permalink)  
Old 04-14-10, 01:12 AM
ycm ycm is offline
New Member
 
Join Date: Apr 2010
Posts: 4
Thanks: 0
Thanked 3 Times in 3 Posts
sorry, i dont get you. u want to see my form, is it?
HTML Code:
<body>
<form id="form1" name="login" method="post" action="check.php">
  <p>NO VESEL:
    <input type="text" name="vesel" id="vesel" />
</p>
  <p>KATA LALUAN:
    <input type="text" name="pwd" id="pwd" />
</p>
  <p>
    <input type="submit" name="hantar" id="hantar" value="HANTAR" />
  </p>
</form>
</body>

Last edited by job0107; 04-14-10 at 08:21 AM.
Reply With Quote
The Following User Says Thank You to ycm For This Useful Post:
mysamsung (04-17-10)
  #4 (permalink)  
Old 04-14-10, 08:27 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Assuming your form is in login_page.php and your query code is in check.php, then the data from the form should be getting to the query ok.

You might try quoting the variable in your query.
Unquoted variables will work if they are strictly numeric.
But your variable contains alpha-numeric characters.
PHP Code:

#get data from login_page.php
$nvesel=$_POST["vesel"];
$kata_laluan=$_POST["pwd"];
#$nvesel=JHF1074T;  / if hardcode, this query can run

#check if data exist
$query_vesel"SELECT no_vesel,kata_laluan from STATUS_PENGGUNA where no_vesel='$nvesel'";

# perform the query
$result odbc_exec($connect$query_vesel);

# fetch the data from the database
while(odbc_fetch_row($result))
$no_vesel odbc_result($result1); $id_pemilik odbc_result($result2);
print(
"$no_vesel $id_pemilik\n"); } 
__________________
Jerry Broughton
Reply With Quote
The Following User Says Thank You to job0107 For This Useful Post:
mysamsung (04-17-10)
  #5 (permalink)  
Old 04-14-10, 08:42 PM
ycm ycm is offline
New Member
 
Join Date: Apr 2010
Posts: 4
Thanks: 0
Thanked 3 Times in 3 Posts
Thanks for the reply, I've tried the suggestion still it' not working..
Reply With Quote
The Following User Says Thank You to ycm For This Useful Post:
mysamsung (04-17-10)
  #6 (permalink)  
Old 04-14-10, 08:50 PM
ycm ycm is offline
New Member
 
Join Date: Apr 2010
Posts: 4
Thanks: 0
Thanked 3 Times in 3 Posts
Problem solved..have to change the code this way:

$query_vesel= "SELECT no_vesel,kata_laluan from STATUS_PENGGUNA where no_vesel LIKE '%$nvesel%'";

Reply With Quote
The Following User Says Thank You to ycm For This Useful Post:
mysamsung (04-17-10)
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create an active link in a PHP search result? CountryGirlDesigns PHP 5 03-31-10 04:01 PM
php variable in .js file? adubb PHP 4 11-20-06 05:19 PM
Store result of function in variable HairySpider PHP 4 09-10-06 03:43 PM
PHP variable sharad PHP 2 09-10-04 02:06 PM
help query result mysql php paceno11 PHP 1 02-19-04 02:18 AM


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