Page 3 of 3

Posted: Tue Aug 31, 2004 3:56 pm
by Kingo
I was not able to make it out. I added the code. but i'm getting error.

Code: Select all

if($worked)
{
   
   //accepted values
$accepted_passed_vars = array('cvalue1','cvalue2'); 
foreach($accepted_passed_vars as $v) 
  if(isset($_GET[$v]) $$v = $_GET[$v]; 
  else $$v = ''; 

   
   //End accepted values
   
$changeover = array( 
'Uname' => array('text'=>'Username:','element'=>'username','type'=>'text'), 
'cvalue1' => array('text'=>'cvalue1:','element'=>'cvalue1','type'=>'text'), 
'cvalue2' => array('text'=>'cvalue2:','element'=>'cvalue2','type'=>'text'), 
'dvalue1' => array('text'=>'dvalue1:','element'=>'dvalue1','type'=>'text'), 
'dvalue2' => array('text'=>'dvalue2:','element'=>'dvalue2','type'=>'text'), 

); 

foreach($changeover as $key => $val) 
{ 
  if(isset($worked[$key])) 
  { 
    echo $val['text'] . '<input type="' . $val['type'] . '" name="' . $val['element'] . '" value="' . $worked[$key] . '" /><br />'; 
  } 
}
echo " <input type="Submit" value="Submit"> ";

   }

   else
   {
   echo "The Username and Password donot match";
   }

Error

Posted: Tue Aug 31, 2004 4:21 pm
by Kingo
Getting an error for $$

Posted: Tue Aug 31, 2004 4:23 pm
by markl999
if(isset($_GET[$v]) $$v = $_GET[$v];
should be:
if(isset($_GET[$v])) $$v = $_GET[$v];

Posted: Tue Aug 31, 2004 4:23 pm
by feyd
does the form post or get?

Posted: Tue Aug 31, 2004 7:34 pm
by Kingo
I can display the results ...But I cant update it ... I mean nothingh is happening when i click the submit button

Posted: Tue Aug 31, 2004 7:38 pm
by Kingo
I guess I have to write an update query and insert the form tags. But i donot know where exactly to insert the form tags and write the query. ANy help is appreciated.
Here is my code.

Code: Select all

<?php 
// Connection to Host and Database
require_once('Connections/mysql_conn.php'); 

$username = $_POST["name"];
$password = $_POST["pass"];

$result = MYSQL_QUERY("SELECT * from constant WHERE Uname='$username'and Password='$password'")
   or die ("Name and password not found or not matched");

$worked = mysql_fetch_array($result);

if($worked)
{
   
   //accepted values
$accepted_passed_vars = array('cvalue1','cvalue2'); 
foreach($accepted_passed_vars as $v) 
  if(isset($_GET[$v])) $$v = $_GET[$v]; 
  else $$v = ''; 

   
   //End accepted values
   
$changeover = array( 
'Uname' => array('text'=>'Username:','element'=>'username','type'=>'text'), 
'cvalue1' => array('text'=>'cvalue1:','element'=>'cvalue1','type'=>'text'), 
'cvalue2' => array('text'=>'cvalue2:','element'=>'cvalue2','type'=>'text'), 
'dvalue1' => array('text'=>'dvalue1:','element'=>'dvalue1','type'=>'text'), 
'dvalue2' => array('text'=>'dvalue2:','element'=>'dvalue2','type'=>'text'), 

); 

foreach($changeover as $key => $val) 
{ 
  if(isset($worked[$key])) 
  { 
    echo $val['text'] . '<input type="' . $val['type'] . '" name="' . $val['element'] . '" value="' . $worked[$key] . '" /><br />'; 
  } 
}
echo " <input type="Submit" value="Submit"> ";

   }

   else
   {
   echo "The Username and Password donot match";
   }



?>

Found an Easy Solution---But get an error in the Last part

Posted: Tue Aug 31, 2004 9:27 pm
by Kingo
Here is my first Page to login [login.html]

Code: Select all

&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Login&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;form name="form1" method="post" action="login1.php"&gt;
  &lt;p align="center"&gt;&lt;strong&gt;&lt;font color="#FF0000" size="2" face="Arial, Helvetica, sans-serif"&gt;&lt;u&gt;Login 
    Information&lt;/u&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;
  &lt;p align="center"&gt;&lt;font size="2" face="Arial, Helvetica, sans-serif"&gt;&lt;strong&gt; 
    Name: 
    &lt;input type="text" name="name"&gt;
    &lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;
  &lt;p align="center"&gt;&lt;font size="2" face="Arial, Helvetica, sans-serif"&gt;&lt;strong&gt;Password: 
    &lt;input type="password" name="pass"&gt;
    &lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;
  &lt;p align="center"&gt;&lt;strong&gt;&lt;font size="2"&gt;
    &lt;input type="submit" name="Submit" value="Submit"&gt;
    &lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;
  &lt;p&gt;&lt;br&gt;
  &lt;/p&gt;
  &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
Here is my Second Page [login1.php]

Code: Select all

<html>
<head>
<title>Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php 
// Connection to Host and Database
require_once('Connections/mysql_conn.php'); 

$username = $_POST["name"];
$password = $_POST["pass"];

$result = MYSQL_QUERY("SELECT * from constant WHERE Uname='$username'and Password='$password'")
   or die ("Name and password not found or not matched");

$worked = mysql_fetch_array($result);

if($worked)
{


$cval1 = $worked["cvalue1"];
$cval2 = $worked["cvalue2"];
$dval1 = $worked["dvalue1"];
$dval2 = $worked["dvalue2"];


echo "<br><br><form name="frm1" method="POST" action="review.php" >";
echo "<input type="hidden" value ="$username" name="un"> ";
echo "<input type="hidden" value ="$password" name="pw"> ";
echo " <br><br>CValue1 = <input type ="text" value= "$cval1" name="cv1"> ";
echo " <br><br>CValue2 = <input type ="text" value= "$cval2" disabled name="cv2"> ";
echo " <br><br>DValue1 = <input type ="text" value= "$dval1" name="dv1"> ";
echo " <br><br>DValue2 = <input type ="text" value= "$dval2" disabled name="dv2"> ";
echo "<br><br><input type="Submit" value="Submit">";

echo "</form>";

}

   else
{
   echo "The Username and Password donot match";
}



?>

</body>
</html>

Here is my Third Page [review.php]

Code: Select all

<html>
<head>
<title>Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php 
// Connection to Host and Database
require_once('Connections/mysql_conn.php'); 

$username = $_POST["un"];
$password = $_POST["pw"];

$ncv1 = $_POST["cv1"];
$ncv2 = $_POST["cv2"];
$ndv1 = $_POST["dv1"];
$ndv2 = $_POST["dv2"];



$result = MYSQL_QUERY("UPDATE constant SET cvalue1='$ncv1', cvalue2='$ncv2', dvalue1='$ndv1', dvalue2='$ndv2' where Uname='$username' and Password='$password' ")
   or die ("Name and password not found or not matched");



if($result)
{
echo " <a href= "login1.php">Click here to review the Changes</a>";

}

   else
{
   echo "The Username and Password donot match";
}



?>

</body>
</html>
MY PROBLEM:
After the second submit button is hit, i get an error saying that User Name and Password donot match.
And I get an notice for the disabled fields and when i login again, the disabled fields dis-appear.

Any help is really appreciated.

Posted: Tue Aug 31, 2004 10:05 pm
by Kingo
I'm having problem passing the VARIABLES OF USERNAME AND PASSWORD.
I guess using the SESSION variables will solve this problem. I have'nt used sessions before.
ANY HELP to IMPLEMENT SESSIONS in this program would be appreciated. I have tried a lot but, cant make it.

Thanx for all ur help

Posted: Wed Sep 01, 2004 12:29 am
by feyd
read the docs.. and the user comments for sessions, most everything is explained in those pages.
http://www.php.net/session