SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot Harvy's Avatar
    Join Date
    Feb 2002
    Location
    Aberdeen, Scotland
    Posts
    101
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problem with mysql update

    Hi

    Im having problems getting this update script to work i have done some test and it appears the id variable has no value when it trys to update. hmm i dunno if i explained that very well but im afraid i dont understand it too well myself. Can anyone help me.

    PHP Code:
        if ($updateperf == "SUBMIT") {
            
    $sql "UPDATE performances SET perf='$perf' WHERE id='$id'";
            echo(
    "started update");
            if (@
    mysql_query($sql)) {
                echo(
    "<p>The Member has been Updated.<BR>perf?$perf<BR>id?$id<BR>idtest?$idtest</p>".mysql_affected_rows());
            } else {
                echo(
    "<p>Error Updating Member: " .
                
    mysql_error() . "</p>");
          }
        }


        
    $perflist = @mysql_query"SELECT id, perf FROM performances");
        echo(
    "started display for edit");
        if (!
    $perflist) {
        echo(
    "<p>Error performing query: " mysql_error() . "</p>");
        exit();
        } 

      while (
    $list mysql_fetch_array($perflist)) {
        
    $id $list["id"];
        
    $perf $list["perf"];

    echo(
    "<form action='$PHP_SELF' method='post'>\n");
    echo(
    "<textarea rows='10' cols='30' NAME='perf'>$perf</textarea><BR>\n");
    echo(
    "<input type='submit' name='updateperf' value='SUBMIT'>\n");
    echo(
    "</form><BR>\n");
     } 

  2. #2
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    Canada
    Posts
    174
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm assuming that you have some sort of relationship amongst your tables. I believe your id variable has no value because it's not passed through the form.

    So in your case, I think you would need to pull out all the things and ids and choose the person/thing you want to update. A simple way of doing this... (you would add this to your form):

    Code:
    <SELECT NAME="id" SIZE=1>
    <OPTION SELECTED VALUE="">Select Thing to Update
    <?php
    while ($row = mysql_fetch_array($query)) {
    	$id   = $row["ID"];
    	$name = $row["Thing"];
    	echo("<OPTION VALUE='$id'>$name\n");
    
    }
    
     ?>
     </SELECT>
    Of course, your "$query" would select the id and "thing" to update. The person would then make the selection from a drop down list in the form and the id will be submitted along with the form.

    Kix


Bookmarks

Posting Permissions

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