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 3 of 3
  1. #1
    New Coder
    Join Date
    Feb 2009
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Sorry me again....just trying to update a record

    Hey Guys,

    Sorry to bother you, im slightly stuck on updating a record in a database, i have an edit page with a form which shows a text box with text of a certain page in. Like this:

    PHP Code:
        <table width="400" border="0" align="center" cellpadding="3" cellspacing="1">
    <tr>
    <td><strong>Edit About Us English </strong></td>
    </tr>
    </table>

    <table width="400" border="0" align="center" cellpadding="0" cellspacing="1">
    <tr>
    <td><form name="form1" method="post" action="send_update_english.php">
    <table width="100%" border="0" cellspacing="1" cellpadding="3">

    <tr>
    <td>Detail</td>
    <td>:</td>
    <td><textarea name="detail" cols="50" rows="4" id="detail">

    [B]<?php

    mysql_connect
    ("localhost""web148""123") or die(mysql_error());
    mysql_select_db("web148") or die(mysql_error());

    mysql_query("SET names 'utf8'");

    $result mysql_query("SELECT body FROM aboutenglish WHERE ID = '1'");

     
    // get the first (and hopefully only) entry from the result
    $row mysql_fetch_array$result );
    // Print out the contents of each row into a table 

    echo nl2br($row['body']);


    ?>[/B]

    </textarea></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td>
    </tr>
    </table>
    </form>
    </td>
    </tr>
    </table>
    Im not sure if thats done correctly or not, but it does what i need to.

    From there i can edit the text but when i click the submit button the database is blank.

    The 'send form' code is like this:

    PHP Code:
    <?php

    // Details
    $message="$detail";

    mysql_connect("localhost""web148""123") or die(mysql_error());
    mysql_select_db("web148") or die(mysql_error());

    mysql_query("SET names 'utf8'");
    $result mysql_query("UPDATE aboutenglish SET body = '$message' where ID = '1'");


    ?>
    The actual update query works fine i think its just passing the values between the two pages i mean i have:

    edit page:
    PHP Code:
    <td><textarea name="detail" cols="50" rows="4" id="detail"
    send form page:
    PHP Code:
    $message="$detail";
    $result mysql_query("UPDATE aboutenglish SET body = '$message' where ID = '1'"); 

    If anyone could help id really appreciate it.

    Cheers

  • #2
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Assuming the second bit of code (the 'send form' code, as you put it) is the script 'send_update_english.php', let's examine what the script is doing.
    PHP Code:
    $message="$detail"
    Ok, so in this assignment, where does the variable $detail come from?

    Read this and this before you proceed.

    PHP Code:
    $result mysql_query("UPDATE aboutenglish SET body = '$message' where ID = '1'"); 
    How do you know that the record you want to update has the ID of '1'? You don't pass anything else to the script to allow for a specific ID value to be updated. I get that your form contains the SQL statement to pull the data from a record with ID = 1, but do you assume your application will always use that ID?

    The real issue for now is "where does $detail come from". Once you get that worked out you can figure out the rest, e.g targeting different records based on ID value.

    By the way, you do not need to quote "$detail" in your assignment - only use double quotes to parse variables inside a larger string. You can just assign $one_variable = $another_variable at any time.

  • #3
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,509
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    It should look like this ....

    // Details
    $message=$_POST['$detail'];
    $message=mysql_real_escape_string($message);







    .


  •  

    Posting Permissions

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