Selecting which record to update - mysql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
traxy
Forum Newbie
Posts: 9
Joined: Thu Mar 26, 2009 11:34 pm

Selecting which record to update - mysql

Post by traxy »

Hey Guys,

Im currently working on project, its basically an online store to sell CD's. When the site administrator searches for a CD to update a list of CD's will appear that match the search criteria entered. When the list appears they are able to click on which CD they want to update (eg. update the price) but im unsure of how to actually pass the information of what CD has been selected to the next php page. Here is an example of my code:

This is my bit of my search.php

Code: Select all

 
    $Row = mysqli_fetch_row($QueryResult);
do {
    echo "<table width='100%' border='1'>";
    echo "<tr><th>CD Type</th><th>CD Name</th><th>Price</th><th>Artist</th></tr>";
    echo "<tr><td>{$Row[0]}</td>";
    echo "<td>{$Row[1]}</td>";
    echo "<td>{$Row[2]}</td>";
    echo "<td>{$Row[3]}</td></tr>";
    echo '<a href="update.php">Update </a>';
    echo '<a href="index.html"> Delete</a>';
    $Row = mysqli_fetch_row($QueryResult);  
} while($Row);  
 
The above code returns all CD's that matched the search criteria with a link to update.php above each CD. But whenever I click on the update.php it always returns the values of the first row, I need to somehow let update.php know which CD I want to update. Create a handle (is that the correct terminology) to each row so update.php knows which record we want to update.

Hope that makes sense, please let me know if you need more information.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Selecting which record to update - mysql

Post by Benjamin »

You would either want to use html radio options or a select menu. You can use the primary key of the cd as the value in the menu. The primary key will be passed to next page for processing.
Post Reply