Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Apr 2007
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Does anyone have an Update script/demo?

    Hi

    Say I have two forms: name and surname which puts the data into my sql.
    How can I make a update page that you see your name and surname once on the update page?

    Must I like put <? echo"$name?> in the form?

    Does anyone have a script I can look at or have a demo?

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts

  • #3
    New Coder
    Join Date
    Apr 2007
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    No, I want to echo a name into the form.

    example:

    Enter Name

    [ ]
    ---------------
    Then
    --------------

    Result Displays

    Your Name [peter]
    your surname [smiht ]
    {button(update)}

    -------------------------
    Updated

    Your name [peter]
    your suraname [smith]

    I want to see the text to display from mysql into my fields.

    Thanks

  • #4
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,042
    Thanks
    19
    Thanked 42 Times in 42 Posts

  • #5
    New Coder
    Join Date
    Apr 2007
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi, I made this code but it still need some editing. (Please note I'm learning php adn not yet familiar with updating the way I want to...)

    Write a name to extract the name with surname for updating
    ----------------------------------------------------------

    [HTML]
    <form id="form1" name="form1" method="post" action="up2.php">
    <label>
    Enter
    <input name="name" type="text" id="name" />
    </label>
    <p>
    <label>
    <input type="submit" name="Submit" value="Submit" />
    </label>
    </p>
    </form>
    [/HTML]


    Update page
    ---------------
    PHP Code:
    <?PHP 
    header
    "cache-control: no-cache, must-revalidate" );
    header"Pragma: no-cache" );
    $self $_SERVER['PHP_SELF'];
    if (!isset(
    $_POST['submit'])){
    ?>
    <?php
    $con 
    mysql_connect("localhost","design","superdesign");
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }
    mysql_select_db("gptesting_co_za_-_contact"$con);$result mysql_query("SELECT * FROM persons");while($row mysql_fetch_array($result))
      {
      
    $name "name"
      
    $name "name";
      } 

    mysql_close($con);
    ?>

    <form id="form1" name="form1" method="post" action="<?php echo( $self ); ?>">
      <label>
      Name 
      <input name="dname" type="text" VALUE="<? echo "$name"?>" id="name" />
      </label>
      <p>Surname: 
        <input name="dsurname" type="text" VALUE="<? echo "$surname"?>" id="name2" />
      ghgh</p>
      <p>
        <label>
        <input type="submit" name="Submit" value="update" />
        </label>
      </p>
    </form>


    <?php
    }else{
    $dname $_POST['dname'];
    $dsurname $_POST['dsurname'];

    $con mysql_connect("localhost""user""pass");
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }
    mysql_select_db("mydb"$con);

    mysql_query("UPDATE persons SET name = '$name' and '$surname' WHERE name = '$dname' AND surname = '$surname'");mysql_close($con);
    mysql_close($con);

        
        echo 
    "Record updated!<br/> Would you like to <a href=\"up.php\">update</a>one more record?" ;
       } 
    ?>

    </body>
    </html>
    Last edited by webandwe; 04-25-2007 at 03:37 PM.

  • #6
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    You're turning the results into an array, so you need to call the results in an array format.
    PHP Code:
    $name "name" 
    Will be
    PHP Code:
    $name $row['name'];
    $surname $row['surname']; 

  • #7
    New Coder
    Join Date
    Apr 2007
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks...It looks like it is almost working...The only problem now is it only shows the second entry of mysql.

    Must I fix this on my coding page or the form and where/wat causes this?

    Thanks


  •  

    Posting Permissions

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