Announcement

Collapse
No announcement yet.

Problem with PHP coding

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with PHP coding

    I have some code which I give below. There are some textboxes and a submit button. When I give the username in a textbox and click submit, the other textboxes should fill with user info from the database according to the username. If I dont give username and just click submit, the other textboxes fill with user info of the first row in the database. My problem with the code is that if I give the username and click submit button twice, the text boxes fill with correct values. On the first click of submit, the text boxes fill with the values of previous username. I really would appreciate anybody's help.

    <?php
    $myServer = "192.168.0.163";
    $myUser = "sa";
    $myPass = " ";
    $myDB = "ITInfo";
    $s = @mssql_connect($myServer, $myUser, $myPass)
    or die("Couldn't connect to SQL Server on $myServer");
    $d = @mssql_select_db($myDB, $s)
    or die("Couldn't open database $myDB");
    $query = "SELECT * FROM UserAll";

    $result =mssql_query($query);
    $field = mssql_fetch_array($result)
    ?>


    <br>
    <hr width="370" align="center">
    <p align="center"><font size="5">Data-entry form for table User</font></p>
    <hr width="370" align="center">
    <form name="form1" method="post" action="" >

    <table border="0" align="center" cellpadding="5" cellspacing="0">

    <tr><td colspan=2>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspEnter Name:
    <input type="text" name="text" Value="">&nbsp&nbsp
    <input type="button" value="submit" onClick="testForm(this.form)">
    <br><br></td></tr>


    <tr>
    <td align="center" >User ID</td>
    <td><input align="left" type="text" name="text2" value="">
    </td>
    </tr>

    <tr>
    <td align="center" >Name</td>
    <td><input type="text" name="text3" value="">
    </td>
    </tr>

    <br>
    <tr>
    <td align="center" >Address</td>
    <td><input type="text" name="text4" value="">
    </td>
    </tr>
    <tr>
    <td align="center" >Contact No.</td>
    <td><input type="text" name="text5" value="">
    </td>
    </tr>

    <tr>
    <td align="center" >Office Email</td>
    <td><input type="text" name="text6" value="">
    </td>
    </tr>

    <tr>
    <td align="center" >Email Code</td>
    <td><input type="text" name= "text7" value="">
    </td>
    </tr>
    <tr>
    <td align="center" >Individual Backup Code</td>
    <td><input type="text" name="text8" value="">
    </td>
    </tr>

    <tr><td colspan=2><br></td></tr>

    <tr>
    <td align="right"><input type="submit" value="Previous Row">
    <td align="left"><input type="submit" value="Next Row">
    </td>
    </tr>
    <tr>
    <td align="right"><input type="submit" value="Save">
    <input type="submit" value="View Table">
    </td>
    <td align="left"><input type="submit" value="Clear Form">


    </td>
    </tr>

    <tr>
    <td align="center"><input type="submit" value="Insert Row">
    <input type="submit" value="Edit Row" >
    </td>
    <td align="left"><input type="submit" value="Delete Row">

    </td>
    </tr>

    </table>
    </form>
    <?php

    $uName4=$_POST['text'];

    $query3="SELECT * FROM UserAll WHERE uName LIKE '$uName4%'";

    $result3 =mssql_query($query3);

    $field3 = mssql_fetch_array($result3);

    ?>


    <SCRIPT LANGUAGE="JAVASCRIPT">

    function testForm(form) {

    if (form.text.value.length !=0)
    { form.text2.value="<?=$field3["uId"]?>";
    form.text3.value="<?=$field3["uName"]?>" ;
    form.text4.value="<?=$field3["address"]?>" ;
    form.text5.value="<?=$field3["contactNo"]?>" ;
    form.text6.value="<?=$field3["officeEmail"]?>";
    form.text7.value="<?=$field3["emailcodeNo"]?>" ;
    form.text8.value="<?=$field3["invidbackupcode"]?>";
    }


    if(form.text.value.length==0 )
    { form.text2.value="<?=$field["uId"]?>";
    form.text3.value="<?=$field["uName"]?>" ;
    form.text4.value="<?=$field["address"]?>" ;
    form.text5.value="<?=$field["contactNo"]?>" ;
    form.text6.value="<?=$field["officeEmail"]?>";
    form.text7.value="<?=$field["emailcodeNo"]?>" ;
    form.text8.value="<?=$field["invidbackupcode"]?>";
    }

    }
    </script>

  • #2
    You are currently showing up as unlicensed. To be able to receive support here at vBulletin.com, we ask you to please click HERE and enter your email address, to show us that you are licensed.

    You will need to use your customer number and password (which will be in the email you got when you paid for your license) to access that page. Please note that your email is case sensitive.

    Thank you.

    Comment

    widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
    Working...
    X