WAP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreWAP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old April 25th, 2006, 07:09 AM
TheBoosht TheBoosht is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 9 TheBoosht User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 57 m 40 sec
Reputation Power: 0
Some help with login script

Hi guys, thanks for the help yesterday. Im trying to create a login script which will compare the input values with mysql and then redirect the user to a "welcome" page if it succeeds or else reject. ive created 3 cards but they dont seem to be working.



PHP Code:
login.wml
<wml>

<
card id="login1" title="login">
<
p align="center">


<
p>User Login Form</p>

<
FORM METHOD="POST" ACTION="login.php">
<
p><STRONG>Username:</STRONG><br>

<
INPUT TYPE="text" NAME="username"></p>

<
p><STRONG>Password:</STRONG><br>

<
INPUT TYPE="text" NAME="password"></p>

<
p><INPUT TYPE="SUBMIT" NAME="submit" VALUE="Login"></p>

</
p>
</
card>

</
wml




PHP Code:
login.php
<?php
header
('Content-Type: text/vnd.wap.wml, true'); 
echo 
'<?xml version="1.0" encoding="ISO-8859-1"?> 
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"  
"http://www.wapforum.org/DTD/wml_1.1.xml">'

?>

<wml>
    <card id="login" title="login">

  </p>

<?php
//check for required fields from the form
if ((!$_POST[username]) || (!$_POST[password])) {
    
header("Location: login.wml");
    exit;
}

//connect to server and select database
 
require($_SERVER["DOCUMENT_ROOT"]."/config/db_config.php");
  
$connection mysql_connect($db_host$db_user$db_password) or die("error connecting");
  
mysql_select_db($db_name$connection);

//create and issue the query
$sql "select f_name, l_name from owner_details where username = '$_POST[username]' AND password('$_POST[password]')";
$result mysql_query($sql,$connection) or die(mysql_error());

//get the number of rows in the result set; should be 1 if a match
if (mysql_num_rows($result) == 1) {

    
//if authorized, get the values of f_name l_name
    
$f_name mysql_result($result0'f_name');
    
$l_name mysql_result($result0'l_name');

    
//set authorization cookie
    
setcookie("auth""1"0"/""yourdomain.com"0);

    
//create display string
    
$display_block "<P>$f_name $l_name is authorized!</p>
    <P>Authorized Users' Menu:
    <ul>
    <li><a href=\"resultpage.php\">secret page</a>
    </ul>"
;

} else {

    
//redirect back to login form if not authorized
    
header("Location: login.wml");
    exit;
}
?>
        </p>
    </card>
</wml>



PHP Code:
result.php
<?php
header
('Content-Type: text/vnd.wap.wml, true'); 
echo 
'<?xml version="1.0" encoding="ISO-8859-1"?> 
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"  
"http://www.wapforum.org/DTD/wml_1.1.xml">'

?>

<wml>
 <card id="resultpage1" title="resultpage">
 <p align="left">
/p>


<?php
if ($_COOKIE[auth] == "1") {
    
$display_block "<p>You are an authorized user.</p>";


else 
{
    
//redirect back to login form if not authorized
    
header("Location: login.wml");
    exit;
}
<
p/>
?>
</wml>

Last edited by jabba_29 : April 25th, 2006 at 08:04 AM. Reason: code tags again :)

Reply With Quote
  #2  
Old April 25th, 2006, 08:09 AM
jabba_29's Avatar
jabba_29 jabba_29 is offline
Back in HEL
Dev Shed God 8th Plane (8500 - 8999 posts)
 
Join Date: Feb 2002
Location: Finland
Posts: 8,670 jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)  Folding Points: 57777 Folding Title: Beginner FolderFolding Points: 57777 Folding Title: Beginner FolderFolding Points: 57777 Folding Title: Beginner Folder
Time spent in forums: 3 Months 3 Weeks 4 Days 6 h 10 m 50 sec
Reputation Power: 1618
Send a message via ICQ to jabba_29 Send a message via AIM to jabba_29 Send a message via MSN to jabba_29 Send a message via Yahoo to jabba_29 Send a message via Google Talk to jabba_29 Send a message via Skype to jabba_29
Facebook
Look at the code that I provided yesterday, especially the postfield part. Your first card doesn't have them, so it won't be passing any data to the second card.

Also, your syntax is awful. Sorry to be so blunt, but as I stated yesterday (though I should add that tags need to be in lowercase too):
Quote:
Originally Posted by me yesterday
WML is based on xml, so the syntax / mark-up needs to be absolutely correct or is just won't display on a mobile device. This means that tags need to be in lower case and properly nested. So, this is wrong for example.
__________________
Cheers,

Jamie


# skiFFie | Home of the 'accessibility module' for Drupal
# Jamie Burns [me] Accessibility Module [drupal]
# guidelines | search | wap resources | not getting help | fold to cure

# Any form of employment is strictly prohibited ......


__________________

Let the might of your compassion arise to bring a quick end
to the flowing stream of the blood and tears .....
Please hear my anguished words of truth.

__________________

Reply With Quote
  #3  
Old April 25th, 2006, 09:46 AM
TheBoosht TheBoosht is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 9 TheBoosht User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 57 m 40 sec
Reputation Power: 0
Hi again jabba, i made some corrections to the from. not sure am i going in the right direction. Ive corrected as much as the syntax as i can

login.php

Code:
<?php
header('Content-Type: text/vnd.wap.wml, true'); 
echo '<?xml version="1.0" encoding="ISO-8859-1"?> 
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"  
"http://www.wapforum.org/DTD/wml_1.1.xml">'; 
?>


<wml>

<card id="login1" title="login">
<p align="center">

<?php
      // connect to mysql database
      require($_SERVER["DOCUMENT_ROOT"]."/config/db_config.php");
  $connection = mysql_connect($db_host, $db_user, $db_password) or die("error connecting");
  mysql_select_db($db_name, $connection);
  ?>
<p>

<p>User Login Form</p>

<form action="login1.php" method="POST">
<p><STRONG>Username:</STRONG><br>

<input type="text" name="username"></p>

<p><strong>Password:</strong><br>

<input type="text" name="password"></p>

<p><input type="submit" name="submit" value="go">

<do type="accept">
<go href="login1.php" method="post">
<postfield name="username" value="$(username)"/>
<postfield name="password" value="$(password)"/>
</go>

/do>

<a href="home.php">Back</a>
</p>
</card>

</wml>


login1.php

Code:

    
    <?php
header('Content-Type: text/vnd.wap.wml, true'); 
echo '<?xml version="1.0" encoding="ISO-8859-1"?> 
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"  
"http://www.wapforum.org/DTD/wml_1.1.xml">'; 
?>

<wml>
<card id="login2" title="login2">
</p>

<?php
//check for required fields from the form
if ((!$_POST[username]) || (!$_POST[password])) {
	header("Location: login.php");
	exit;
}

//connect to server and select database
 require($_SERVER["DOCUMENT_ROOT"]."/config/db_config.php");
  $connection = mysql_connect($db_host, $db_user, $db_password) or die("error connecting");
  mysql_select_db($db_name, $connection);

//create and issue the query
$sql = "select f_name, l_name from owner_details where username = '$_POST[username]' AND password('$_POST[password]')";
$result = mysql_query($sql,$connection) or die(mysql_error());

//get the number of rows in the result set; should be 1 if a match
if (mysql_num_rows($result) == 1) {

	//if authorized, get the values of f_name l_name
	$f_name = mysql_result($result, 0, 'f_name');
	$l_name = mysql_result($result, 0, 'l_name');

	//set authorization cookie
	setcookie("auth", "1", 0, "/", "yourdomain.com", 0);

	//create display string
	$display_block = "<P>$f_name $l_name is authorized!</p>
	<p>Authorized Users' Menu:
	<ul>
	<li><a href=\"resultpage.php\">secret page</a>
	</ul>";

} else {

	//redirect back to login form if not authorized
	header("Location: login.php");
	exit;
}
?>
<a href="home.php">Back</a>
</p>

</card>
</wml>

Reply With Quote
  #4  
Old April 25th, 2006, 10:50 AM
jabba_29's Avatar
jabba_29 jabba_29 is offline
Back in HEL
Dev Shed God 8th Plane (8500 - 8999 posts)
 
Join Date: Feb 2002
Location: Finland
Posts: 8,670 jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)  Folding Points: 57777 Folding Title: Beginner FolderFolding Points: 57777 Folding Title: Beginner FolderFolding Points: 57777 Folding Title: Beginner Folder
Time spent in forums: 3 Months 3 Weeks 4 Days 6 h 10 m 50 sec
Reputation Power: 1618
Send a message via ICQ to jabba_29 Send a message via AIM to jabba_29 Send a message via MSN to jabba_29 Send a message via Yahoo to jabba_29 Send a message via Google Talk to jabba_29 Send a message via Skype to jabba_29
Facebook
I have commented the first card you posted again, see below. Please run your scripts through a validator, you can easily work out the correct syntax if you stop trying to do everything in such a hurry and actually read a couple of the tutorials.
PHP Code:
login.php
<?php
header
('Content-Type: text/vnd.wap.wml, true'); 
echo 
'<?xml version="1.0" encoding="ISO-8859-1"?> 
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"  
"http://www.wapforum.org/DTD/wml_1.1.xml">'

?>


<wml>

<card id="login1" title="login">
<p align="center"><!-- THIS IS EXTRA / REMOVE -->

<!-- DONT CONNECT TO THE DB UNLESS YOU HAVE TO / REMOVE -->
<?php
  
// connect to mysql database
  
require($_SERVER["DOCUMENT_ROOT"]."/config/db_config.php");
  
$connection mysql_connect($db_host$db_user$db_password) or die("error connecting");
  
mysql_select_db($db_name$connection);
?>


<p><!-- THIS IS EXTRA / REMOVE -->

<p>User Login Form</p>
<!-- THIS IS HTML NOT WML, THAT IS WHAT POSTFIELD IS FOR -->
<form action="login1.php" method="POST">
<p><STRONG>Username:</STRONG><br><!-- SHOULD BE <BR /> NEED TO CLOSE THE TAG, IN LOWER CASE -->

<input type="text" name="username"></p>

<p><strong>Password:</strong><br><!-- SHOULD BE <BR /> NEED TO CLOSE THE TAG -->

<input type="text" name="password"></p>

<!-- THIS IS HTML NOT WML, THAT IS WHAT DO IS FOR -->
<p><input type="submit" name="submit" value="go">

<do type="accept">
<go href="login1.php" method="post">
<postfield name="username" value="$(username)"/>
<postfield name="password" value="$(password)"/>
</go>

</do>

<a href="home.php">Back</a>
</p>
</card>

</wml>
Links to validators in the wap resources link in my signature in previous post.

Reply With Quote
  #5  
Old May 1st, 2006, 05:21 PM
TheBoosht TheBoosht is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 9 TheBoosht User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 57 m 40 sec
Reputation Power: 0
Thanks for the help last week jabba, i got the scripts running fine. The login is grand now and displays what i want. Im having a little trouble with one final part of the site, ive created a php srcipt which enables a user to update pr add a premises when they login. For now i just want to feature an option which enables a new user, after they login 2 add a premises. Ive got to the stage where it diplays the fields in the form, how do i create a simple submit in the end which adds the premises into the database?

PHP Code:
<?php
header
('Content-Type: text/vnd.wap.wml, true');
echo 
'<?xml version="1.0" encoding="ISO-8859-1"?> 
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"  
"http://www.wapforum.org/DTD/wml_1.1.xml">'

?>

<wml>

<card id="update" title="update">
<?php
require($_SERVER["DOCUMENT_ROOT"]."./config/db_config.php");
  
$connection = @mysql_connect($db_host$db_user$db_password) or die("error connecting");
  
mysql_select_db($db_name$connection);



$prem_id $_GET["prem_id"];

if (
$_GET["action"] == "submit")
{
    if (
$_GET["prem_id"])
    {
//code here to update the prem details table with prem_id = $prem_id
$sql "UPDATE premises_details SET premises_name = '$prem_name', premises_type = '$prem_type', address = '$address', town_id = '$town_id', county = '$county', contact_number = '$contact_number', email = $email_address', WHERE prem_id =".$_GET['prem_id'];

          }
    
//code here to insert new premises
    
else
    {
$sql "INSERT INTO premises_details (premises_name,premises_type,address,town_id,county,contact_number,email_address)
VALUES ('$prem_name','$prem_type','$address','$town_id','$county','$contact_number','$email_address')"
;
    }
}
else
{
    if (
$_GET["action"] == "update")
    {

        
//$result = mysql_query("SELECT * FROM premises_details where prem_id = $prem_id",$connection);
        
$sql "SELECT * FROM premises_details WHERE prem_id=$prem_id";
        
        
$result mysql_query($sql);
        
$myrow mysql_fetch_array($result);
        
$prem_id $myrow["id"];
        
$premises_name $myrow["prem_name"];
        
$premises_id $myrow["prem_id"];
        
$owner_id $myrow["owner_id"];
        
$address $myrow["address"];
        
$town_id $myrow["town_id"];
        
$prem_type_id $myrow["prem_type_id"];
        
$county $myrow["county"];
        
$contact_number $myrow["contact_number"];
        
$email $myrow["email_address"];
    }
    if (
$_GET["action"] == "update")
    {
        echo 
"<hr>";

        
printf('<form method="post" action=premises_details.php?action=submit&prem_id=%d>',$_GET["prem_id"]);
echo  
'<form method="post" action=premises_details.php?action=submit&prem_id=',$prem_id,'>';
 }
 else{
      echo
'<form method="post" action=premises_details.php?action=submit>';
 }
 
?>

 Premises name:<input type="Text" name="premises name" value="<?php echo $premises_name ?>"><br>

  Premises Type: <select name = 'prem_type'>
        <option value ="0">Select Premises Type</option>
        <?
      $query 
"SELECT * FROM premises_type";
      
$result mysql_query($query$connection);
      for (
$i 0$i mysql_num_rows($result); $i++)
      {
          
$prem_type mysql_result($result$i,"prem_type");
          
$prem_type_id1 mysql_result($result$i,"prem_type_id");
          if (
$prem_type_id == $prem_type_id1)
          {
           
printf("\n<option selected value =%s>%s</option>",$prem_type_id,$prem_type);
          }
          else   
printf("\n<option value =%s>%s</option>",$prem_type_id1,$prem_type);
      }
      
?>
        </select><br>

   <input type="hidden" name="premises ID" value="<?php echo $premises_id ?>">

  Address:<input type="Text" name="address" value="<?php echo $address ?>"><br>


  
  Town: <select name = 'town'>
        <option value ="0">Select Town</option>
        <?
      $query 
"SELECT * FROM town";
      
$result mysql_query($query$connection); 
      for (
$i 0$i mysql_num_rows($result); $i++)
      {
          
$town_name mysql_result($result$i"town_name");
          
$town_id1 mysql_result($result$i"town_id"); 
          if (
$town_id == $town_id1)
          {
           
printf("\n<option selected value =%s>%s</option>",$town_id1,$town_name);
          }
          else   
printf("\n<option value =%s>%s</option>",$town_id1,$town_name); 
      }
      
?>
        </select>
        <br>
  County:<input type="text" name="county" value="<?php echo $county ?>"><br>

  Contact Number:<input type="text" name="contact number" value="<?php echo $contact_number ?>"><br>

  Email:<input type="text" name="email" value="<?php echo $email ?>"><br><br>



  <input type="Submit" name="submit" value="Enter information">

  </form>
  <?
  
}
  
?>
  <br>
  <br>
  <a href="home.php">Back</a>
   </card>
</wml>

Last edited by jabba_29 : May 1st, 2006 at 07:37 PM.

Reply With Quote
  #6  
Old May 1st, 2006, 07:40 PM
jabba_29's Avatar
jabba_29 jabba_29 is offline
Back in HEL
Dev Shed God 8th Plane (8500 - 8999 posts)
 
Join Date: Feb 2002
Location: Finland
Posts: 8,670 jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)jabba_29 User rank is General 10th Grade (Above 100000 Reputation Level)  Folding Points: 57777 Folding Title: Beginner FolderFolding Points: 57777 Folding Title: Beginner FolderFolding Points: 57777 Folding Title: Beginner Folder
Time spent in forums: 3 Months 3 Weeks 4 Days 6 h 10 m 50 sec
Reputation Power: 1618
Send a message via ICQ to jabba_29 Send a message via AIM to jabba_29 Send a message via MSN to jabba_29 Send a message via Yahoo to jabba_29 Send a message via Google Talk to jabba_29 Send a message via Skype to jabba_29
Facebook
Yet again, you have no fieldset in your form - you are using HTML forms and HTML, not xml/wml. You are also confusing methods for your forms, your submit action. You have used "post" but you are checking against $_GET['submit'] which is never going to be set.

Reply With Quote
  #7  
Old May 2nd, 2006, 07:31 AM
andymoo's Avatar
andymoo andymoo is offline
Timelord
Dev Shed Novice (500 - 999 posts)
 
Join Date: Oct 2003
Location: Loughborough, Leicestershire
Posts: 605