Jump to content

Update records - mysql


traxy

Recommended Posts

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

 

$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.

Link to comment
Share on other sites

I'd do it like this, make the cd list the link and have the relevant cd in query string:

 

<?php

    $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><a href=\"update.php?cd=$Row[1]\">{$Row[1]}</a></td>";

  echo "<td>{$Row[2]}</td>";

  echo "<td>{$Row[3]}</td></tr>";

 

  echo '<a href="index.html"> Delete</a>';

  $Row = mysqli_fetch_row($QueryResult); 

} while($Row);

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.