PHP webpage like MySQL, PART 2

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default PHP webpage like MySQL, PART 2

    Many hanks for ya'lls help earlier.

    I've figured out how to pull the data and edit it:
    [url]http://www.hedges.org/aoii/olemiss/updatesister.php[/url]

    However, for some reason I can't get it to edit whatever row. In the code
    (pasted below) I have to specificy $id=row to edit...

    I can't figure out how to make it to where the user can select the field
    (which is the id/row) and edit it. I've tried putting a ?id=# at the end of
    the url, but that doesn't work... Any thoughts? So what I want is where it
    says

    $id=1

    to have it someway where that is a variable that the user can define...



    <html>
    <head><title>Update Sister Info.</title></head>
    <body>
    <?php
    $host="host";
    $user="user";
    $password="pw";
    $database="db";
    $id=1;
    $connection = mysql_connect($host,$user,$password)
    or die ("couldn't connect to server");
    $db = mysql_select_db($database,$connection)
    or die ("Couldn't select database");

    if (@$first == "no")
    {

    $query = "UPDATE table SET
    FirstName='$FirstName',MiddleName='$MiddleName',La stName='$LastName',GradYea
    r='$GradYear',Email='$Email',MarriedName='$Married Name' WHERE id='$id'";
    $result = mysql_query($query)
    or die ("Couldn't execute query.");
    echo "Thank you! Information entered. <a href=actives.php>View
    Actives</a><br>";
    exit();

    }
    else
    {
    $query = "SELECT * FROM table WHERE id='$id'";
    $result = mysql_query($query)
    or die ("Couldn't execute query.");
    $row = mysql_fetch_array($result);
    extract($row);
    }

    /* Display user phone in a form */
    echo "<br><p align='center'>
    <font size='+1'><b>Please check the sister below and correct if
    necessary.</b></font>
    <hr>
    <form action='updatesister.php?first=no' method='post'>
    <div align='center'>
    <table width='50%' border='0' cellspacing='0' cellpadding='2'>
    <tr><td align='right'><B>$id</br></td>
    <td align='center'><input type='text' name='FirstName' size='20'
    maxlength='20' value='$FirstName' > </td>
    <td align='center'><input type='text' name='MiddleName' size='20'
    maxlength='20' value='$MiddleName' > </td>
    <td align='center'><input type='text' name='LastName' size='20'
    maxlength='20' value='$LastName' > </td>
    <td align='center'><input type='text' name='GradYear' size='20'
    maxlength='20' value='$GradYear' > </td>
    <td align='center'><input type='text' name='Email' size='20'
    maxlength='20' value='$Email' > </td>
    <td align='center'><input type='text' name='MarriedName'
    size='20' maxlength='20' value='$MarriedName' > </td>

    </tr>
    <tr><td></td><td align='center'>
    <br><input type='submit' value='Update Sister'></td>
    </tr>
    </table>
    </form>";
    ?>
    </body>
    </html>



    Thank you.
    Matt



    --
    ___________________________
    | Matt Hedges
    | [url]http://hedgesinnovations.com[/url]
    |


    Matt Hedges Guest

  2. Similar Questions and Discussions

    1. Whoops -- character limit per line in Mysql or dodgy debugging on my part?
      I accidentally posted the following message to mailing.databases.mysql, where I believe it is off-topic, so am reposting here with apologies to the...
    2. php+mysql-driven webpage
      Hi! I have a little problem: I have php-code stored in a mysql-table. How do i run this code? if i echo it, i see the code, but how do i...
    3. PHP Webpage like MySql- need to be able to see all fields and edit
      Hello. I am building a webpage for a sorority- http://www.olemissaoii.com . I built a basic php script where they add the sisters and their...
    4. [PHP] PHP Webpage like MySql- need to be able to see allfields and edit
      Just select the values out, and put them as the default in the value portion of the form inputs, example: $query = mysql_query('select...
    5. [PHP] PHP Webpage like MySql- need to be able to see all fields and edit
      Hello. I am building a webpage for a sorority- http://www.olemissaoii.com . I built a basic php script where they add the sisters and their...
  3. #2

    Default Re: PHP webpage like MySQL, PART 2

    Are you talking about editing mutiple rows at the same time?
    if so there is no efficient way to check what row has been edited and which
    haven't. What I would is use HTML variable arrays for the names of the
    fields.
    example you have <input type='text' name='FirstName' size='20'
    maxlength='20' value='Allison' > change the name attribute to name =
    [data][$id][FirstName], so now you have all variables grouped (note the use
    if a fixed index 'data', explination in foreach loop ). Then your script
    will loop through the POST variables and do sequential UPDATES
    example
    foreach ($_POST[data] as $ID => $Field) {
    $query = " Update tablename Set First = '$Field[FirstName'], Last =
    '$Field[LastName'], .... Where id = $ID"; #List all fields in the set clause
    mysql_query($query);

    }

    The reason for the initial 'data' index is so you can safely loop through a
    cetrain part of the post array. If you left that out you would deal with
    extra variables like submit, and other hidden fields.

    It's a little hard to work with multi-dimensional arrays, so what I usually
    do to help me is use the var_dump() on the passed POST array.
    So take a look at var_dimp(), HTML with array indexes, the foreach loop
    construct.

    HOWEVER, if you need to just let the user edit 1 row, what you have is fine
    all you have to do is pass the id number thourgh a HTML hidden field. So
    when you pull the rest of the fields and spitting out HTML spit this out
    somewhere in between the <form> tags :: <input type='hidden' name='id'
    value='$id' >

    Bobby


    "Matt Hedges" <matt@hedges.org> wrote in message
    news:20030724202124.43947.qmail@pb1.pair.com...
    > Many hanks for ya'lls help earlier.
    >
    > I've figured out how to pull the data and edit it:
    > [url]http://www.hedges.org/aoii/olemiss/updatesister.php[/url]
    >
    > However, for some reason I can't get it to edit whatever row. In the code
    > (pasted below) I have to specificy $id=row to edit...
    >
    > I can't figure out how to make it to where the user can select the field
    > (which is the id/row) and edit it. I've tried putting a ?id=# at the end
    of
    > the url, but that doesn't work... Any thoughts? So what I want is where
    it
    > says
    >
    > $id=1
    >
    > to have it someway where that is a variable that the user can define...
    >
    >
    >
    >
    > Thank you.
    > Matt
    >
    >
    >
    > --
    > ___________________________
    > | Matt Hedges
    > | [url]http://hedgesinnovations.com[/url]
    > |
    >
    >

    Bobby Patel Guest

  4. #3

    Default Re: [PHP] PHP webpage like MySQL, PART 2

    On Jul 24, 2003, "Matt Hedges" claimed that:

    |Many hanks for ya'lls help earlier.
    |
    |I've figured out how to pull the data and edit it:
    |[url]http://www.hedges.org/aoii/olemiss/updatesister.php[/url]
    |
    |However, for some reason I can't get it to edit whatever row. In the code
    |(pasted below) I have to specificy $id=row to edit...
    |
    |I can't figure out how to make it to where the user can select the field
    |(which is the id/row) and edit it. I've tried putting a ?id=# at the end of
    |the url, but that doesn't work... Any thoughts? So what I want is where it
    |says
    |
    |$id=1
    |
    |to have it someway where that is a variable that the user can define...

    [some code snipped]
    | else
    | {
    | $query = "SELECT * FROM table WHERE id='$id'";
    | $result = mysql_query($query)
    | or die ("Couldn't execute query.");
    | $row = mysql_fetch_array($result);
    | extract($row);
    | }
    |
    |Thank you.
    |Matt
    |

    Your page gives me "Warning: extract() expects first argument to be an
    array in /c36/mhedges/aoii/olemiss/updatesister.php on line 32." Are you
    sure you're using the correct table name? BTW, "table" is a MySQL
    reserved keyword, so if it is the table name, it should be enclosed in
    backticks: [url]http://www.mysql.com/doc/en/Reserved_words.html[/url]

    Jeff Harris
    --
    Registered Linux user #304026.
    "lynx -source [url]http://jharris.rallycentral.us/jharris.asc[/url] | gpg --import"
    Key fingerprint = 52FC 20BD 025A 8C13 5FC6 68C6 9CF9 46C2 B089 0FED
    Responses to this message should conform to RFC 1855.


    Jeff Harris Guest

  5. #4

    Default Re: [PHP] PHP webpage like MySQL, PART 2



    Matt Hedges wrote:
    > <html>
    > <head><title>Update Sister Info.</title></head>
    > <body>
    > <?php
    > $host="host";
    > $user="user";
    > $password="pw";
    > $database="db";
    > $id=1;
    Why $id=1, you want to edit any sister info
    > $connection = mysql_connect($host,$user,$password)
    > or die ("couldn't connect to server");
    > $db = mysql_select_db($database,$connection)
    > or die ("Couldn't select database");
    >
    > if (@$first == "no")
    > {
    >
    > $query = "UPDATE table SET
    > FirstName='$FirstName',MiddleName='$MiddleName',La stName='$LastName',GradYea
    > r='$GradYear',Email='$Email',MarriedName='$Married Name' WHERE id='$id'";
    > $result = mysql_query($query)
    > or die ("Couldn't execute query.");
    > echo "Thank you! Information entered. <a href=actives.php>View
    > Actives</a><br>";
    > exit();
    >
    > }
    > else
    > {
    > $query = "SELECT * FROM table WHERE id='$id'";
    > $result = mysql_query($query)
    > or die ("Couldn't execute query.");
    > $row = mysql_fetch_array($result);
    > extract($row);
    > }
    >
    > /* Display user phone in a form */
    > echo "<br><p align='center'>
    > <font size='+1'><b>Please check the sister below and correct if
    > necessary.</b></font>
    > <hr>
    > <form action='updatesister.php?first=no' method='post'>
    should be <form action='updatesister.php?first=no&id=$id' method='post'>
    > <div align='center'>
    > <table width='50%' border='0' cellspacing='0' cellpadding='2'>
    > <tr><td align='right'><B>$id</br></td>
    > <td align='center'><input type='text' name='FirstName' size='20'
    > maxlength='20' value='$FirstName' > </td>
    > <td align='center'><input type='text' name='MiddleName' size='20'
    > maxlength='20' value='$MiddleName' > </td>
    > <td align='center'><input type='text' name='LastName' size='20'
    > maxlength='20' value='$LastName' > </td>
    > <td align='center'><input type='text' name='GradYear' size='20'
    > maxlength='20' value='$GradYear' > </td>
    > <td align='center'><input type='text' name='Email' size='20'
    > maxlength='20' value='$Email' > </td>
    > <td align='center'><input type='text' name='MarriedName'
    > size='20' maxlength='20' value='$MarriedName' > </td>
    >
    > </tr>
    > <tr><td></td><td align='center'>
    > <br><input type='submit' value='Update Sister'></td>
    > </tr>
    > </table>
    > </form>";
    > ?>
    > </body>
    > </html>
    Visit this page as updatesister.php?id=#id#

    Marek Kilimajer Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139