SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: update error

  1. #1
    SitePoint Member
    Join Date
    May 2003
    Location
    Philippines
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question update error

    hey guys i made an if-else script that updates or inserts data, the making new data part works fine but if you want to change something to an already existing data by updating... it wont work!

    heres my code:

    include("database.php");

    if ($submit) {

    if ($userid=="" or $password=="" or $first=="" or $middle=="" or
    $last=="" or $position=="") {
    error("One or more required fields were left blank.\\n".
    "Please fill them in and try again.");
    }

    if ($id) {

    $sql = "UPDATE employee SET userid = '$userid',
    password = '$password',
    first = '$first',
    middle = '$middle',
    last = '$last',
    position = '$position',
    WHERE id = $id";

    } else {

    $date = date("Y-m-d");

    $sql = "INSERT INTO employee (userid,password,first,middle,
    last,position,date)
    VALUES ('$userid','$password','$first','$middle',
    '$last','$position','$date')";
    }

    $result = mysql_query($sql);

    echo "<form action=eview.php>
    <table border=0 align=center width=500>
    <tr>
    <td>Record Saved.
    <hr color=orangered>
    <input type=submit value=Back>
    </td>
    </tr>
    </table>
    </form>";

    everything else works fine... except for the update part... cant find the error.

    this code is the same with the other tables...

    ive tried changing the table name but nothing changed...

    this only happens in my employee table.

    please help...

  2. #2
    We like music. weirdbeardmt's Avatar
    Join Date
    May 2001
    Location
    Channel Islands Girth: Footlong
    Posts
    5,882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Remove the comma after position='$position'
    I swear to drunk I'm not God.
    Matt's debating is not a crime
    Hint: Don't buy a stupid dwarf Clicky


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
  •