#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Location
    Sharjah
    Posts
    3
    Rep Power
    0
    Could anyone me on this ..
    I want to retrieve fields from mysql table into html form to update those fields.
    Please show me what to do using php3
    Thank you
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    first call table row values in html form.then simply update it.

    i am writing an example here .just modify this as per your requirment.

    test.php3

    <?php
    $con=mysql_connect (localhost,username,password);

    //connect to the database...

    mysql_select_db("databasename",$con);

    //select your database..

    if($submit=="update"){
    //when user clicks on update button

    $rows=mysql_query("UPDATE test set name='$name' where sno=$sno",$con);

    //update the row where sno=1

    if (mysql_affected_rows($rows)==1){

    //successfully updated.

    print "Succesfully updated!!"

    }else{
    print "Error while updating the record!!";
    }

    }else{

    // this portion will populate values to the html form.

    $result=mysql_query("select * from test where sno=1",$con);

    //get the data from data from the table where sno=1.you can pass the variable value insted of one.


    if ($row = mysql_fetch_array($result))
    {
    //get that row to the form
    ?>
    <form method="post" action="<?php echo $PHP_SELF ?">
    Name : <input type="text" name="name" value="<? print $row["name"];?>">

    <input type="hidden" name="sno" value="<? print $row["sno"];?>">
    <input type="submit" name="submit" value="update">
    </form>
    <?

    }else{
    // no record for your query...

    print "No Records!!";
    }
    }
    ?>

    when you run this test.php3.you should see the form with name value.when you click on "update" button .it will update the particular row.



    GOOD LUCK!!!



    ------------------
    SR -
    shiju.dreamcenter.net

    "The fear of the LORD is the beginning of knowledge..."

    [This message has been edited by Shiju Rajan (edited May 16, 2000).]
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    26
    Rep Power
    0
    Hello all,

    Iam currently designing an application that would benefit from the above code. However the code above dose have some errors such as missing ; " etc. After changing appropriate table names etc the code still fails. Does anyone know what is wrong with the above code or do they know of any similar code that I could use?

    Any help would be appreciated.

    Regards

    Richard
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    15
    Personally I would do it like this
    <?php
    $db=mysql_connect($dbhost,$dbuser,$dbpass);
    mysql_select_db($dbname,$con);
    if($submit){
    $result = mysql_query("UPDATE test set name='$name' where id = '$id'",$db);

    if (mysql_num_rows($result) > 0){
    print "Succesfully updated!!";
    }
    else {
    print "Error while updating the record!!";
    }
    }

    $result=mysql_query("select * from test where id = '1'",$db);

    while ($myrow = mysql_fetch_array($result)) {
    printf('<form method="post" action="%s">', $PHP_SELF );
    printf('Name : <input type="text" name="name" value="%s">', $myrow["Name"]);
    printf('<input type="hidden" name="id" value="%s">', $myrow["id"]);
    print '<input type="submit" name="submit" value="update">';
    print '</form>';

    }
    ?>
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    15
    Sorry I screwed up on this part:
    Should be:
    $db=mysql_connect($dbhost,$dbuser,$dbpass);
    mysql_select_db($dbname,$db);
  10. #6
  11. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    Richard,

    Which line(line number) showing error?..


    ------------------
    SR -
    webshiju.com

    "The fear of the LORD is the beginning of knowledge..."
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    26
    Rep Power
    0
    Hi Shiju,

    The following are the errors that I get when using your code. I have also tried using 'freddydoesphp' version and it seems to fail as well.

    Warning: 0 is not a MySQL result index in test.php3 on line 28

    Parse error: parse error in test.php3 on line 33

    Thanks

    Richard
  14. #8
  15. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    Richard,
    just check it out wether your table field names are correct or not.The script is ok..i think something wrong with your database table..



    ------------------
    SR -
    webshiju.com

    "The fear of the LORD is the beginning of knowledge..."
  16. #9
  17. No Profile Picture
    ...try and try again
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Lake Forest, CA, USA
    Posts
    182
    Rep Power
    15
    This might give some help to the originator.
    It goes through reading sql entries and displaying them in a form and then using UPDATE. The scripts work - I tried them.
    http://hotwired.lycos.com/webmonkey/99/21/index3a.html

    Hope this helps.

    Sharky
  18. #10
  19. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    26
    Rep Power
    0
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by Shiju Rajan:
    <form method="post" action="<?php echo $PHP_SELF ?">



    [/quote]

    I have managed to find the error on this line an > is missing between ? and " Should be as follows:

    <form method="post" action="<?php echo $PHP_SELF ?>">

    For some reason I have an error on line 39. The code for these lines are:

    Line 38 }else{
    Line 39 // no record for your query...

    The code that Iam using is listed below:


    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="">
    </head>

    <body bgcolor="#FFFFFF"><?php
    $con=mysql_connect ('localhost','username','password');
    //connect to the database...
    mysql_select_db("database",$con);
    //select your database..
    if($submit=="update"){
    //when user clicks on update button
    $rows=mysql_query("UPDATE horoscope set horo='$horo' where sno=$sno",$con);
    //update the row where sno=1
    if (mysql_affected_rows($rows)==1){
    //successfully updated.
    print "Succesfully updated!!";
    }else{
    print "Error while updating the record!!";
    }
    }else{
    // this portion will populate values to the html form.
    $result=mysql_query("select * from horoscope where uid='$id'",$con);
    //get the data from data from the table where sno=1.you can pass the variable value insted of one.

    if ($row = mysql_fetch_array($result));
    {

    //get that row to the form
    ?>
    <form method="post" action="<?php echo $PHP_SELF?>">
    Name : <input type="text" name="horo" value="<? print $row["horo"];?>">
    <input type="hidden" name="sno" value="<? print $row["sno"];?>">
    <input type="submit" name="submit" value="update">
    </form>
    <?php
    }else{
    // no record for your query...
    print "No Records!!";
    }
    }
    ?>


    </body>
    </html>


    Regards

    Richard



    [This message has been edited by rway (edited July 29, 2000).]

Similar Threads

  1. Replies: 9
    Last Post: January 29th, 2004, 07:33 AM
  2. using xml data in an html form via javascript
    By jason2584 in forum JavaScript Development
    Replies: 2
    Last Post: January 28th, 2004, 03:42 PM
  3. Can't retrieve elseif data from a form
    By johnny0990 in forum PHP Development
    Replies: 2
    Last Post: January 28th, 2004, 03:28 PM
  4. Need help with posting data onto a form
    By onLOoker in forum Perl Programming
    Replies: 2
    Last Post: January 25th, 2004, 08:58 PM
  5. HTTP Error 400: Bad Request, with basic form
    By crackwombat in forum PHP Development
    Replies: 1
    Last Post: January 23rd, 2004, 06:40 PM

IMN logo majestic logo threadwatch logo seochat tools logo