Go Back   Webmaster Malaysia Forum » Website Design & Development » Website Design

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 27-08-2008, 02:26 PM
Novice Webmaster
 
Join Date: Aug 2008
Location: malaysia
Posts: 23
Rep Power: 0
areah is on a distinguished road
passing array from mysql to wml using php

<?php
session_start();
include "connect_to_MySQL.php";
?>

<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN" "http://www.wapforum.org/DTD/wml13.dtd">

<wml>
<card id="myprofile" title="My Profile">

<p>This is your profile. </p>

<?php

$query = "SELECT * FROM ownerdetails WHERE Login_id = '" . $_SESSION['user_logged'] . "' ";
$result = mysql_query($query) or die(mysql_error());

while ($row=mysql_fetch_array($result))
{
$Name=$row['Name'];

?>


<p> Full Name : <?php echo $Name; ?>

<?php
}
?>

</card>
</wml>


Is this the correct command to do it? I tried to open it in emulator but the data suppose to import from mysql didn't show up.
The only think whish show up is
<p>This is your profile. </p>

I tried to use the php command in html, it works fine.

regards
Areah
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 28-08-2008, 01:02 AM
Seanie's Avatar
Senior Webmaster
 
Join Date: Mar 2008
Location: pd
Posts: 261
Rep Power: 15
Seanie has a spectacular aura about Seanie has a spectacular aura about
If the contents of your while loop were not executed, that just means there were no rows in your SQL result.

You could check your PHP with a dummy query like:

Code:
select 'areah' as Name;
That would give your while loop something to work on. If your database is empty, just create some dummy records, they're easy enough to remove before you go live. I use phpMyAdmin for that kind of thing, it's los cojones del perro.

Maybe your query isn't working - remove the WHERE clause to get all rows from the db. If your code starts working, try echoing your original SQL statement, and typing it into the phpMyAdmin SQL box, you can edit it there until it gives you the results you want, then transfer it back.

Let us know how you get on.

I'm not a PHP programmer, so I borrowed some of your code to test some MySQL functions I've been working on - thanks, it worked just fine for connecting to a database and retrieving rows from a result. I notice the HTML in your while loop has an unclosed <p> element. Maybe this will cause problems for your emulator? I understand WML parsers can be quite 'weak'.

One more edit! I'm interested in doing some WML development myself, so just wondered if I could open a WML file (from w3schools) in FireFox. Seems like I can't, but Opera has very good support for WML - you can even check your block / style structure with a handy option in the 'View' menu. Not sure what the 'emulator' you mention is, but Opera might be an easier way to test your project.
__________________
Sean says:
Read my blog

Last edited by Seanie; 28-08-2008 at 09:35 AM. Reason: Unclosed <p> element
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 28-08-2008, 04:57 PM
Novice Webmaster
 
Join Date: Aug 2008
Location: malaysia
Posts: 23
Rep Power: 0
areah is on a distinguished road
Maybe you can try to use nokia s60 simulator. It works fine with me. You can download it in nokia forum. It is free.

Is it wml can not accept session command which embedded to the php?

It is because when user log in, i store the login ID ad password in session command. Hence i can recall it in another script to work on it. But it seems, it didn't store the data.

In the login.php, i have something:
session_start();
$_SESSION['user_logged']=$mylogin_id;
$_SESSION['password_logged']=$password;

And in myprofile.php, i recall the session to retrieve
data from mysql.

session_start();
$query = "SELECT * FROM ownerdetails WHERE Login_id = '" . $_SESSION['user_logged'] . "' ";
$result = mysql_query($query) or die(mysql_error());

It showed nothing. Hence, i tried to echo $_SESSION['user_logged']. It didn't shows any data.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 28-08-2008, 05:05 PM
Novice Webmaster
 
Join Date: Aug 2008
Location: malaysia
Posts: 23
Rep Power: 0
areah is on a distinguished road
And one more thing, the unclosed <p> element has nothing to do with the error. I tried to manually key in the login ID in the command, it shows my name.

$query = "SELECT * FROM ownerdetails WHERE Login_id = '" . 123 . "' ";
$result = mysql_query($query) or die(mysql_error());

I conclude, it is because the passing array using session. That is why i asked about the session command.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 28-08-2008, 10:12 PM
Seanie's Avatar
Senior Webmaster
 
Join Date: Mar 2008
Location: pd
Posts: 261
Rep Power: 15
Seanie has a spectacular aura about Seanie has a spectacular aura about
If you suspect the $_SESSION array, try a single file test like

Code:
<?php
session_start();
/* your database connect and select code */
$query = "SELECT * FROM ownerdetails WHERE Login_id = '" . $_SESSION["mykey"] . "' ";
$result = mysql_fetch_array(mysql_query($query)) or die(mysql_error()); 
echo print_r($result, true);
$_SESSION["mykey"] = 123;
?>
your code should fail the first time you load it in your browser, and succeed the second time. You're probably not setting up your session variables the way you think you are.
__________________
Sean says:
Read my blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 29-08-2008, 01:24 PM
Novice Webmaster
 
Join Date: Aug 2008
Location: malaysia
Posts: 23
Rep Power: 0
areah is on a distinguished road
If i use the method you mentioned which i have tried, it works fine.

But, the problem with the session is that the session doesn't store the data which i have identified in the first script then i want to import it in the second script.

If the storing of the data in session is put in the same script while you you use it, it works fine. If put it in different script then the session can't pass the data.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 29-08-2008, 10:54 PM
Seanie's Avatar
Senior Webmaster
 
Join Date: Mar 2008
Location: pd
Posts: 261
Rep Power: 15
Seanie has a spectacular aura about Seanie has a spectacular aura about
If the single file version works, then the session is working. Try this 2 file version:

file1.php:
Code:
<?php
session_start();
$_SESSION["mykey"] = 123;
?>
file2.php:
Code:
<?php
session_start();
/* your database connect and select code */
$query = "SELECT * FROM ownerdetails WHERE Login_id = '" . $_SESSION["mykey"] . "' ";
$result = mysql_fetch_array(mysql_query($query)) or die(mysql_error()); 
echo print_r($result, true);
?>
If you browse them file2.php, file1.php, file2.php, you should get nothing, nothing, then the row from your database.

If you get nothing at all... we'll have to think of something else!

--edit--
Admins! Shouldn't this thread be in the "Website Programming" forum?
__________________
Sean says:
Read my blog

Last edited by Seanie; 29-08-2008 at 11:08 PM. Reason: Admin attention?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-09-2008, 03:35 PM
Novice Webmaster
 
Join Date: Aug 2008
Location: malaysia
Posts: 23
Rep Power: 0
areah is on a distinguished road
It can not be done either..
Still blank page.

It only can work if i staright away put in the key.Something like:

<?php
session_start();
/* your database connect and select code */
$query = "SELECT * FROM ownerdetails WHERE Login_id = '" . 123 . "' ";
$result = mysql_fetch_array(mysql_query($query)) or die(mysql_error());
echo print_r($result, true);
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 02-09-2008, 04:18 PM
Seanie's Avatar
Senior Webmaster
 
Join Date: Mar 2008
Location: pd
Posts: 261
Rep Power: 15
Seanie has a spectacular aura about Seanie has a spectacular aura about
Quote:
It can not be done either..
Still blank page.
Hmmm. When I posted the 2-file test, I wondered if it shouldn't be simpler. If the following 2 files don't work - remember to browse 2 then 1 then 2 - then there's something wrong.

Here's the simplest 2-file test I can think of:

file1.php:

Code:
<?php
session_start();
$_SESSION["mykey"] = 123;
?>
file2.php:

Code:
<?php
session_start();
echo print_r($_SESSION, true);
?>
If that really doesn't work... how about posting the 'session' section of phpinfo() for your server - it's apache, right? And are you testing this with a normal browser, or with the 'simulator' you mentioned earlier? I'm still a bit confused that you say the session works in the single-file version but not in the two-file version. I have no idea why that should be - there shouldn't be any difference.

Have you looked in apache's error_log?
__________________
Sean says:
Read my blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 03-09-2008, 10:09 AM
New kid on the block
 
Join Date: Sep 2008
Location: shah alam
Posts: 1
Rep Power: 0
shasi is on a distinguished road
Send a message via Yahoo to shasi
hyep

sya nk minta tlg mengenai mysql.boleh awak add sya kat ct_equanimity00@yahoo.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #11 (permalink)  
Old 04-09-2008, 04:30 PM
Novice Webmaster
 
Join Date: Aug 2008
Location: malaysia
Posts: 23
Rep Power: 0
areah is on a distinguished road
I test it with emulator i mentioned earlier.
Maybe you can try to download and take a look. It is nokia s60 emulator.

Quote:
Originally Posted by Seanie View Post
the session works in the single-file version but not in the two-file version. I have no idea why that should be - there shouldn't be any difference.
Works in single file. Ehm..i have test1.php file which ask users to input their name and password. The value i pass it to test2.php with coding as shown below.

<anchor>
<go method="post" href="test2.php">
<postfield name="user" value="$(myloginid)"/>
<postfield name="pass" value="$(mypassword)"/>
</go>
Submit
</anchor>
</p>



In my test2.php, i start the session:
session_start();
$_SESSION['user_logged']=$mylogin_id;
$_SESSION['password_logged']=$password;

the value of $mylogin_id comes from the submission from test1.php which is <postfield name="user" value="$(myloginid)"/>

After i started the session, is used the session:

<?php
echo "Thank you for logging in, ";
$Name="SELECT Name FROM ownerdetails WHERE Login_id='" . $_SESSION['user_logged'] . "'";
$result=mysql_query($Name)
or die(mysql_error());
while ($row=mysql_fetch_assoc($result))
{
extract($row);
echo $Name;
echo "<br>";
}
?>

In here, the session works fine. It can retrive the data from mysql.

Afterward, in test3.php, i use the same method to retrieve the data which is :
session_start();
$query = "SELECT * FROM ownerdetails WHERE Login_id = '" . $_SESSION['user_logged'] . "' ";
$result = mysql_query($query) or die(mysql_error());
while ($row=mysql_fetch_array($result))
{
$Name=$row['Name'];
}


But, it showed nothing.
This is what i mean. Both of the coding use session to retrieve the data.

And where can i find apache's error_log?


Thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12 (permalink)  
Old 04-09-2008, 05:19 PM
Seanie's Avatar
Senior Webmaster
 
Join Date: Mar 2008
Location: pd
Posts: 261
Rep Power: 15
Seanie has a spectacular aura about Seanie has a spectacular aura about
Quote:
Maybe you can try to download and take a look.
I got the job without an interview? When do I get paid? How much? I can hardly wait to get started!

Did you try the simple two-file example from my previous post? Your problem could be with a typo in your database code or even your HTML output. If you believe it's a session problem, delete everything except the session code that you think is not working properly. Or better still, just use the code I posted. If my code works, your problem isn't with sessions.

In test3.php - no HTML output, how could you see anything?

Code:
{
$Name=$row['Name'];
}
Quote:
And where can i find apache's error_log?
I think in a previous post you mentioned editing httpd.conf, apache's configuration file. There's an option in there to use a specific location for the error log, it's called 'ErrorLog'. If your server is Linux-based it'll probably be /var/log/httpd/error_log
__________________
Sean says:
Read my blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13 (permalink)  
Old 05-09-2008, 02:06 PM
Novice Webmaster
 
Join Date: Aug 2008
Location: malaysia
Posts: 23
Rep Power: 0
areah is on a distinguished road
Oops..sorry in the last reply i forget to paste out that to show the data i have this code.

<p> Full Name : <?php echo $Name; ?>

I just said if you want then you can take a look at the simulator because you mentioned earlier that you interested to do some WML development yourself.
That's all.

If i do it without session. Something like your code:
Quote:
Originally Posted by Seanie View Post

Code:
<?php
session_start();
$_SESSION["mykey"] = 123;
?>
file2.php:

Code:
<?php
session_start();
echo print_r($_SESSION, true);
?>

They work fine.

I found folder call "error" under apache. But can't really find the 'error log". I will go through all the files in the error folder one by one to see if i can find anything.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14 (permalink)  
Old 05-09-2008, 03:16 PM
Seanie's Avatar
Senior Webmaster
 
Join Date: Mar 2008
Location: pd
Posts: 261
Rep Power: 15
Seanie has a spectacular aura about Seanie has a spectacular aura about
Try echoing, copying and pasting your $query variable into whatever you use to do admin on your MySQL database. Just echoing it might show you where you're going wrong. If the problem is a bit harder to spot, pasting the statement into phpMyAdmin or whatever you're using will reveal any errors if that's what's giving you trouble.

I notice you're building up your queries by concatenating strings. I've just gone through a couple of Java applications converting all the joined string SQL statements to PreparedStatements. It might be worth your while checking out the mysqli interface in PHP:

PHP: Prepared statements and stored procedures - Manual
__________________
Sean says:
Read my blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
please help...shopping cart passing values to another page angie_wnv Website Programming 0 08-03-2007 05:53 PM
passing value nov8998 Website Programming 4 18-08-2004 11:15 AM
mcm mane nak insert array dalm database kasih Website Programming 7 24-09-2002 12:07 PM
error jika x masukkan value tuk array kasih Website Programming 16 24-09-2002 10:06 AM
array sorting joyce Website Programming 2 16-06-2002 01:26 AM



All times are GMT +8. The time now is 07:43 PM. Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0 vBulletin skin by