1.11M Members

Data did not display

 
0
 

Hello there. I used this code for user and it works but when I use and alter a bit for admin side system, there is no data inside of the text field and the username keep on changing to 0 eventhough I type in other username. This is the code.

password.php

<?php 

session_start();
$admin=$_POST['admin_id'];
$adpass=$_POST['admin_password'];

$conn = mysql_connect("localhost", "root", "")or die("Could not connect to server");
$db = mysql_select_db("Smartlocker", $conn)or die("Could not connect to database");
$sql = "SELECT * FROM admin WHERE admin_id='$admin' ";
$result = mysql_query($sql) or die ("Could not execute query");
$info=mysql_fetch_row($result);

?>

<?php
    do{
    echo "
    <table width='172' border='0'>
        <tr>
            <td width='62' height='32'><i><b>Username</b></i></td>
            <td width='10'><strong>:</strong></td>
            <td width='100'><input name='admin_id' type='text' size='30' value='$info[0]'></td>
        </tr>
        <tr>
            <td width='62' height='30'><i><b>Password</b></i></td>
            <td width='10'><strong>:</strong></td>
            <td width='100'><input name='admin_password' type='password' size='30' value='$info[1]'></td>
        </tr>        
        <tr>
            <td></td>
            <td></td>
            <td><div align ='right'><form name='pass' method='post' action='savepassword.php'>
            <input type='submit' name='submit' value='Edit'>                                 
            </form></div></td>
        </tr>
    </table> ";
    }while($info=mysql_fetch_row($result));
?>

and this is the process.
savepassword.php

<?php

session_start();

$conn = mysql_connect("localhost", "root", "")or die("Could not connect to server");
$db = mysql_select_db("Smartlocker", $conn)or die("Could not connect to database");
$sql = "UPDATE admin SET admin_id='$admin_id', admin_password='$admin_password'
        WHERE admin_id='$admin' ";
$result = mysql_query($sql) or die ("Could not execute query");

if($result)
{
    echo "  

<table width='1291' height='401' border='1' bordercolor='C0F7FE' bgcolor='E9F1EA'>
    <tr>
        <td>Password successfully updated</td>
    </tr>
</table> ";
}

?>

Did I miss out some codes or there is something wrong with it?

 
0
 
<form name='pass' method='post' action='savepassword.php'>
    <table width='172' border='0'>
    <tr>
    <td width='62' height='32'><i><b>Username</b></i></td>
    <td width='10'><strong>:</strong></td>
    <td width='100'><input name='admin_id' type='text' size='30' value='$info[0]'></td>
    </tr>
    <tr>
    <td width='62' height='30'><i><b>Password</b></i></td>
    <td width='10'><strong>:</strong></td>
    <td width='100'><input name='admin_password' type='password' size='30' value='$info[1]'></td>
    </tr>
    <tr>
    <td></td>
    <td></td>
    <td><div align ='right'>
    <input type='submit' name='submit' value='Edit'>
  </div></td>
    </tr>
    </table></form>";
 
0
 

try this may be work

 
0
 

it didn't work either.. :(

 
0
 

can you give your table structure? and as what arti18 posted..there is a form as you save the username and password cause from your code there is no form..

from the savepassword.php file
this line
$sql = "UPDATE admin SET admin_id='$admin_id', admin_password='$admin_password' WHERE admin_id='$admin' "; $admin_id should contain post or get variable like $admin_id = $_POST['admin_id']; and $admin as well

 
0
 

table structure? you mean like this?

<table width='172' border='0'>
    <tr>
        <td width='62' height='32'><i><b>Username</b></i></td>
        <td width='10'><strong>:</strong></td>
        <td width='100'>
        <input name='admin_id' type='text' size='30' value='$info[0]'></td>
    </tr>
    <tr>
        <td width='62' height='30'><i><b>Password</b></i></td>
        <td width='10'><strong>:</strong></td>
        <td width='100'>
        <input name='admin_password' type='password' size='30' value='$info[1]'></td>
    </tr>
    <tr>
        <td></td>
        <td></td>
        <td><div align ='right'>
        <form name='pass' method='post' action='savepassword.php'>
        <input type='submit' name='submit' value='Edit'>
        </form></div></td>
    </tr>
</table>

do you mean like, it need to have 3 steps from form -> password.php -> savepassword.php?
is it something like this?

is it a must to put

$admin=$_POST['admin_id'];
$adpass=$_POST['admin_password'];

after

session_start();
 
0
 

give link to update password and in that link pass admin id throught query string and then update password on savepassword page.

 
0
 

sorry.. but I don't get you.

 
0
 
  <?php 
    session_start();
$conn = mysql_connect("localhost", "root", "carina")or die("Could not connect to server");
    $db = mysql_select_db("test", $conn)or die("Could not connect to database");


     if(isset($_POST['submit']))
    {

    $admin=$_POST['admin_id'];
    $adpass=$_POST['admin_password'];



      $sql = "SELECT * FROM admin WHERE admin_id='$admin' ";
    $result = mysql_query($sql) or die ("Could not execute query");
    $info=mysql_fetch_array($result);
     $admin_id=$info['admin_id'];
     $_SESSION['admin_id']=$admin_id;
     //echo $admin_id;
     header('location:savepassword.php');
}
   ?>
  <body>

    <form name='pass' method='post'>
    <table width='172' border='0'>
    <tr>
    <td width='62' height='32'><i><b>Username</b></i></td>
    <td width='10'><strong>:</strong></td>
    <td width='100'><input name='admin_id' type='text' size='30' value=''></td>
    </tr>
    <tr>
    <td width='62' height='30'><i><b>Password</b></i></td>
    <td width='10'><strong>:</strong></td>
    <td width='100'><input name='admin_password' type='password' size='30' value=''></td>
    </tr>
    <tr>
    <td></td>
    <td></td>
    <td><div align ='right'>
    <input type='submit' name='submit' value='Login'>
  </div></td>
    </tr>
    </table></form> 

   </body>



savepassword.php

    <?php
    session_start();
    $conn = mysql_connect("localhost", "root", "carina")or die("Could not connect to server");
    $db = mysql_select_db("test", $conn)or die("Could not connect to database");
    $admin='';
    $adpass='';
    if(isset($_SESSION['admin_id']))
    {
    $admin=$_SESSION['admin_id'];
    //$adpass=$_POST['admin_password'];


    $sql = "SELECT * FROM admin WHERE admin_id='$admin' ";
    $result = mysql_query($sql) or die ("Could not execute query");
    $info=mysql_fetch_array($result);
     $admin_id=$info['admin_id'];
     echo $admin_id;
}
     if(isset($_POST['submit']))
     {
        $admin=$_POST['admin_id'];
    $adpass=$_POST['admin_password'];

    $sql = "UPDATE admin SET admin_id='$admin', admin_password='$adpass'
    WHERE admin_id='$admin_id'";
    //echo $sql;
    $result = mysql_query($sql) or die ("Could not execute query");
    if($result)
    {
    echo "
    <table width='1291' height='401' border='1' bordercolor='C0F7FE' bgcolor='E9F1EA'>
    <tr>
    <td>Password successfully updated</td>
    </tr>
    </table> ";
}
}
    ?>

    <html>
    <head>
        <title></title>
    </head>
    <body>
        <form method='post'>
       Admin Id:<input name='admin_id' type='text' size='30' value=''>
       <br>
    Password:<input name='admin_password' type='password' size='30' value=''>
    <input type='submit' name='submit' value='Edit'>
    </form>
    </body>
    </html>

test this i run your code it has so many errors all solved and change database coonection to your database connection,i think that's the thing you want

 
0
 

okay. but wait. starting from the first line until 47th, it didn't show any data on the text field or is that one for login?

 
0
 

yes it is for login you have to give login permition to user after that user can change password without login how can user change the password for her/himself

 
0
 

heres the process
1. <form method="post" action="savepassword.php"></form>
2. redirect from savepassword.php
3. get all $_POST value (as youve seen from 1 you used post method)
$_POST - is an array that contains the input element from the form(see #1)

$_POST['<name of the element>']

for example <input type="text" name="student_id"> so you could get the value of the posted student id by $_POST['student_id']
4. then you can use them to the preceeding code.

 
0
 

I did like you ask me to but it shows this message.
Parse error: parse error, expecting T_STRING' orT_VARIABLE' or `T_NUM_STRING'

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: