SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2003
    Location
    United Kingdom
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can I update all the fields of a record at once?

    I have a edit form where I would like to be able to allow users to edit some or all of the fields of a database record.

    Code from my form page:

    Code:
    $RaceInfo = mysql_query("SELECT Race_ID, Race_Name, Race_Date FROM Races WHERE Race_ID='".$searchrace."'",$db); 
    
    while ($record6 = mysql_fetch_array($RaceInfo)) {
    $raceidz = $record6["Race_ID"];
    $racename = $record6["Race_Name"];
    $racedate = $record6["Race_Date"];
    }
    
    echo "<form action='change_details4.php' method='post'>";
    
    echo "<table>";
    echo "<tr><td>";
    echo "<font size=4><b><center>Race ID: <input type='text' name='ud_raceid' size='3' value=$raceidz>";
    echo "</td><td>";
    echo "<font size=4><b><center>Race Name: <input type='text' name='ud_racename' size='30' value='".$racename."'>";
    echo "</td><td>";
    echo "<font size=4><b><center>Race Date: <input type='text' name='ud_racedate' size='10' value=$racedate>";
    echo "</td></tr>";
    echo "</table>";
    
    echo "<input type='Submit' value='Update'></form>";
    Code from the processing script (change_details4.php):

    Code:
    $ud_raceid=$_POST['ud_raceid'];
    $ud_racename=$_POST['ud_racename'];
    $ud_racedate=$_POST['ud_racedate'];
    
    mysql_query("UPDATE Races SET Race_ID = '".$ud_raceid."', Race_Name = '".$ud_racename."', Race_Date = '".$ud_racedate."' WHERE Race_ID='".$ud_raceid."'",$db);
    
    echo "Records Updated";
    But this is not working.... I'm pretty sure it must have something to do with the WHERE clause of the UPDATE command line, am I right? I somehow need to, for example, say 'change Race ID to AUS WHERE it currently equals AUT' or something similar...

    Can you help?

    kemi

    P.S. I deliberately left off database connections codes etc, and tried to just stick to providing the code that is relevant to my question. If you need more, just ask

  2. #2
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,001
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    First of all, I guess Race ID in the form should be in hidden field (<input type="hidden">).
    Then, SQL query will go like:
    Code:
    mysql_query("UPDATE Races SET Race_Name = '".$ud_racename."', Race_Date = '".$ud_racedate."' WHERE Race_ID='".$ud_raceid."'",$db);
    -- Jelena --

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2003
    Location
    United Kingdom
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, no, Race ID does not need to be hidden... I need it to be editable, along with the Race Name and Race Date...

  4. #4
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,001
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Well, how can you update that particular entry in db if race ID is editable?

    Then it cannot be in the WHERE part of the query.
    -- Jelena --

  5. #5
    SitePoint Enthusiast
    Join Date
    Aug 2003
    Location
    United Kingdom
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I have created a rid (Race ID) column in my table and used it as a hidden form element and in the WHERE clause of the UPDATE statement and it works!

    Cheers for the responses as always!

    kemi


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
  •