Simple Project

Discussion in 'PHP' started by msthac01, Sep 10, 2008.

  1. #1
    Here's what I'm trying to do...

    An interface should be written that displays a list of all users that have been imported. When displaying the list of users, the password field should be represented with a blank input box, allowing the user's password to be changed. Underneath the table there will be a "Save" button, which when pressed will change all the passwords for those users who have a password filled in and reload the page.

    When someone has input several passwords, each password needs to be validated in javascript prior to submit to ensure that it is of a minimum length of 4 characters. If it is not, the Save button should not work and a popup should explain what the problem is.

    I know how to loop through all of the data pulled from the query and display everything...I know how to display the textbox but not sure how to go about naming each item so that I can run through them and check to ensure something was typed in and then update accordingly. I've never done anything like that before and haven't been able to find anything helpful to this point..I've only been coding in php for about a year and this is a first for something like this...Any help would be greatly appreciated
     
    msthac01, Sep 10, 2008 IP
  2. msthac01

    msthac01 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Here's what I have so far but I'm pretty sure it won't work and also not sure how to go about the update part from the javascript once it determines if the input password was neither blank nor less than 4 characters.


    [php


    <?php

    $hostname_dbConnect = ""
    $database_dbConnect = "";
    $username_dbConnect = "";
    $password_dbConnect = "";
    $dbConnect = mysql_pconnect($hostname_dbConnect, $username_dbConnect, $password_dbConnect) or die(mysql_error());

    //Get User Record Source
    $query = "SELECT * FROM user";
    $result = mysql_query($query, $dbConnect) or die(mysql_error());

    ?>

    <html>
    <head>
    <title>Matt's Password Changing Page</title>
    <script type="text/javascript">
    function validate(f){
    var passwords = f.password;
    var usernames = f.username;
    for (i=0;i<passwords.length;i++){
    if (passwords.length < 4) {
    alert("Password Length is Less than 4 characters!");
    passwords.focus();
    return false;
    }
    elseif(passwords.value=='') {
    //Do nothing since not updating this record
    }
    else{

    //update the table accordingly

    }
    }
    return true;
    }

    </head>
    <body>
    <form name="UserUpdate" enctype="multipart/form-data" action="EmployeeUpdate.php" method="POST" onSubmit="return validate(this);">

    <table>
    <?php

    while($row = mysql_fetch_array($result))
    {
    ?>
    <tr bgcolor="white">

    <td align="center"><input type="text" name="username" value="<?php echo $row['user_name']; ?>"></td>
    <td align="center"><input type="text" name="firstname" value="<?php echo $row['first_name']; ?>"></td>
    <td align="center"><input type="text" name="lastname" value="<?php echo $row['last_name']; ?>"></td>
    <td align="center"><input type="text" name="password"></td>

    </tr>
    <?php
    }//end while
    ?>
    <tr>
    <td><input type="submit" name="Submit" value="Save"></td>
    </tr>
    </table>

    </form>
    </body>
    </html>



    php]

    Just not sure if this is going to work. I can't test it on the database until later tomorrow unfortunately. Just wondering it anyone could tell me if it even looks like it might work and if not what I need to address. Again thanks for any help
     
    msthac01, Sep 10, 2008 IP