Jump to content

Add a check box to a table?


tracy

Recommended Posts

The following code displays the contents of a mysql table fine.  However, I'd like to add a check box column to the far right or far left side of each row.  When said check box is 'checked' and then a 'select' button is clicked, I'd like that item to be selected for editing or deletion and a new php page would then display the contents of that row for said editing or deletion.  The main identifier is the stock number, or 'stock' in each row.  Any help is appreciated.

<?php
include ("link.php");

if($query= mysql_query("SELECT * FROM inventory"))
{
  $num = mysql_num_rows($query); 
}else
{
  die('There was an error with the query:<br>'.mysql_error());


if ($num == '0') {
echo "Nothing Exist.";
die();
}
else {

?>
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<td><font face=Arial>Stock#</font>
</td>
<td><font face=Arial>Year</font>
</td>
<td><font face=Arial>Make</font>
</td>
<td><font face=Arial>Model</font>
</td>
<td><font face=Arial>Price</font>
</td>
<td><font face=Arial>Miles</font>
</td>
<td><font face=Arial>Photo</font>
</td>
</tr>
<?

while ($info = mysql_fetch_array($query)) {
$stock = $info['stock'];
$year = $info['year'];
$make = $info['make'];
$model = $info['model'];
$price = $info['price'];
$miles = $info['miles'];
$photo1 = $info['photo1'];
echo ("
<tr>
<td> <font face=Arial>$stock</font>
</td>
<td> <font face=Arial>$year</font>
</td>
<td> <font face=Arial>$make</font>
</td>
<td> <font face=Arial>$model</font>
</td>
<td> <font face=Arial>$price</font>
</td>
<td> <font face=Arial>$miles</font>
</td>
<td> <font face=Arial>$photo1</font>
</td>
</tr>
");
}
?>
</table>
<?
}
?>

Link to comment
Share on other sites

  • Replies 51
  • Created
  • Last Reply

Top Posters In This Topic

First question: Are you really going to attempt to handle multiple edits on a single page? Based on your request, with checkboxes, you'll have to handle multiple record editing on a single page... definitely possible, but not the easiest way to handle things. The deletion is easy since it doesn't even have to go to another page. I'll handle that one here, and if you can explain how you want the editing handled, we can help you with that part, too:
[code]
<?php
// First, somewhere in the header of your page (usually the first logic of any), you want to check
// and see if the "Delete" button has been pressed and process accordingly
if (isset($_POST['del']) && count($_POST['del']) > 0) {
  // Run a query to delete all selected records
  $sql = "DELETE FROM inventory WHERE id IN ('" . implode(',', $_POST['del']) . "')";
  mysql_query($sql);
}

// Second, before your table starts, you'll want to start a form for your checkboxes:
echo "<form name=\"deleteForm\" action=\"\" method=\"post\">\n";

// Assuming you are already within the confines of your table:
while ($info = mysql_fetch_array($query)) {
  echo "<td>$info[stock]</td>\n";
  echo "<td>$info[year]</td>\n";
  echo "<td>$info[make]</td>\n";
  echo "<td>$info[model]</td>\n";
  echo "<td>$info[price]</td>\n";
  echo "<td>$info[miles]</td>\n";
  echo "<td>$info[photo1]</td>\n";
 
  // Here is your added checkbox. The value is assuming you have an "ID" column in your inventory table
  // to uniquely identify your records
  echo "<td><input type=\"checkbox\" name=\"del\" value=\"$info[id]\" /></td>\n";
}

// You must also add a submit button (I usually label mine according to its function):
echo "<tr><td colspan=\"8\"><input type=\"submit\" name=\"submit\" value=\"Delete Selected\" /></td></tr>\n";

// Then, once you wrap up your table, close the form
echo "</form>\n";
?>
[/code]

Hope this helps some
Link to comment
Share on other sites

I appreciate your response.  I was hoping to only use the check box to take me to a php page with one record displayed for editing.  One at a time only.  I am not sure about multiple edits on the same page as I am kind of new to php.  I am mainly trying to find an easy way to display the contents of the table and select one of the records at a time for editing.  I figured a check box would suit users best, as they would not have to remember any stock numbers.  I appreciate any feedback or suggestions.

The problem I have had is adding the check box or radio button or whatever method...to actually 'select' the record for edit/delete and have it subsequently displayed on another php page with the contents available for edit/delete, or just edit, as may the case now per your idea... 

Link to comment
Share on other sites

Ah, makes sense. Hence, I would suggest you simply hyperlink the name of the item (or add an [i]edit[/i] link to the end of the row) instead of a checkbox. This way, they can only select one item at a time. For instance:
[code]
<?php
// Assuming you are already within the confines of your table:
while ($info = mysql_fetch_array($query)) {
  echo "<td>$info[stock]</td>\n";
  echo "<td>$info[year]</td>\n";
  echo "<td>$info[make]</td>\n";
  echo "<td>$info[model]</td>\n";
  echo "<td>$info[price]</td>\n";
  echo "<td>$info[miles]</td>\n";
  echo "<td>$info[photo1]</td>\n";

  // here is your "edit" link
  echo "<td><a href=\"edit.php?id=$info[stock]\">edit</a></td>\n";
}
?>
[/code]

Then, on your edit.php page, you could simply grab the provided stock number, pull the information and populate your form with the data.

Does this make more sense? The trouble with checkboxes is that, by default, users think they can select multiple items ;)
Link to comment
Share on other sites

Yes, that makes sense.  I could possibly add another hyperlink for delete?

The issue for me is that when either the hyperlink for edit or the hyperlink for delete is selected and the browser goes to the corresponding php page, what causes the code to know which stock number (record) was selected? 

Perhaps your code that you supplied already took care of that?  I have not tried it yet and won't be able to try it until later today.  Thanks for all your help.
Link to comment
Share on other sites

Well, when you pass a value through [b]post[/b] (such as a form), you can use the $_POST variable to access it on your corresponding page. In the example of my "edit" links, you are passing the variable through the URL, and therefor, you can access it via the $_GET variable. Since my "edit" link passes ?id=$info['stock'] through the URL, I can then access that variable on the edit.php page like this:
[code]
<?php
$stock = $_GET['id'];
$sql = mysql_query("SELECT * FROM inventory WHERE stock = '$stock'");
?>
[/code]

As far as the delete links go, I like to put a little javascript confirmation in the mix so that you don't [i]accidentally[/i] remove an inventory item. In this case, your page would alter slightly from my first recommendation:
[code]
<?php
// This would be how to process a delete LINK as opposed to the form as mentioned before
if (isset($_GET['del'])) {
  $sql = "DELETE FROM inventory WHERE stock = '$_GET[del]'";
  mysql_query($sql);
}

// Instead of the form and checkboxes, you simply would add this link to the end of your row:
echo "<td><a href=\"?del=$info[stock]\" onclick=\"return confirm('Are you sure you wish to delete this item?');\">delete</a></td>\n";
?>
[/code]

The onclick attribute will give you the nice little popup confirmation before deleting an entry.

Hope this helps ;)
Link to comment
Share on other sites

Don't use a checkbox, use a radio button. That way you make sure only one record is selected. If you use a checkbox you could select multiple records and then on the update page you might end up looking at the wrong record.
I use this for mine
i use this little javascript in the head to double check that you want to delete the row

Then the form is like so
[code]<?php
include ("link.php");

if($query= mysql_query("SELECT * FROM inventory"))
{
   $num = mysql_num_rows($query);
}else
{
  die('There was an error with the query:
'.mysql_error());
}

if ($num == '0') {
echo "Nothing Exist.";
die();
}
else {

?>
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<td><font face=Arial>Stock#</font>
</td>
<td><font face=Arial>Year</font>
</td>
<td><font face=Arial>Make</font>
</td>
<td><font face=Arial>Model</font>
</td>
<td><font face=Arial>Price</font>
</td>
<td><font face=Arial>Miles</font>
</td>
<td><font face=Arial>Photo</font>
</td>
<td><font face=Arial>Select</font>
</td>
</tr>
<?

while ($info = mysql_fetch_array($query)) {
$id = $info['id']; // Put your id field here!!!
$stock = $info['stock'];
$year = $info['year'];
$make = $info['make'];
$model = $info['model'];
$price = $info['price'];
$miles = $info['miles'];
$photo1 = $info['photo1'];
echo ("
<tr>
<td> <font face=Arial>$stock</font>
</td>
<td> <font face=Arial>$year</font>
</td>
<td> <font face=Arial>$make</font>
</td>
<td> <font face=Arial>$model</font>
</td>
<td> <font face=Arial>$price</font>
</td>
<td> <font face=Arial>$miles</font>
</td>
<td> <font face=Arial>$photo1</font>
</td>
<td colspan=2 align=center><input type=radio name=baseid value=$id>
</td>
</tr>
<tr>
<td align=center colspan=8><input type=Submit name=edit value=Edit>&nbsp;&nbsp;&nbsp;<input type=Submit name=del onClick=\"return confirmSubmit()\" value=Delete>
</td>
");
}
?>
</table>
<?
}
?>[/code]

Then on your page that processes the script you would do this

[code]<?php
if(isset($_POST['del'])){
// put your code to delete here

} else (
if(isset($_POST['edit'])){
// put edit code here

} else {
// do nothing here
echo "No record was selected";
}
}
?>[/code]

As Obsidian said above, I tried to put in a little javascript do pop up when you hit the del button, but the site will not let me do it.

Ray
Link to comment
Share on other sites

[quote author=craygo link=topic=117718.msg480487#msg480487 date=1165500642]
Don't use a checkbox, use a radio button. That way you make sure only one record is selected.
[/quote]

I personally don't like that approach at all. Radio buttons imply that one [b]is to be checked[/b]. In fact, most of the time you see radio buttons, one is checked by default. Plus, what if you click on one to be deleted, then you decide not to? There's no way to [b]de[/b]-select a radio button without the use of some unnecessary javascript. That's why I suggested just adding the links like I did above.

Besides that, checkboxes are the perfect solution for deletion since it allows for multiple deletions with one click. Editing, on the other hand, is a whole different animal :P

Again, it's just a preference thing, but definitely worth some thought.
Link to comment
Share on other sites

What do you mean already within the confines of your table?  Already in the section of code that builds the table?  Could you explain this a little more.  I think I like the idea, just not sure where to tie it into my code...thanks again.

[quote author=obsidian link=topic=117718.msg480472#msg480472 date=1165498766]
Ah, makes sense. Hence, I would suggest you simply hyperlink the name of the item (or add an [i]edit[/i] link to the end of the row) instead of a checkbox. This way, they can only select one item at a time. For instance:
[code]

<?php
// Assuming you are already within the confines of your table:
while ($info = mysql_fetch_array($query)) {
  echo "<td>$info[stock]</td>\n";
  echo "<td>$info[year]</td>\n";
  echo "<td>$info[make]</td>\n";
  echo "<td>$info[model]</td>\n";
  echo "<td>$info[price]</td>\n";
  echo "<td>$info[miles]</td>\n";
  echo "<td>$info[photo1]</td>\n";

  // here is your "edit" link
  echo "<td><a href=\"edit.php?id=$info[stock]\">edit</a></td>\n";
}
?>
[/code]

Then, on your edit.php page, you could simply grab the provided stock number, pull the information and populate your form with the data.

Does this make more sense? The trouble with checkboxes is that, by default, users think they can select multiple items ;)
[/quote]
Link to comment
Share on other sites

I tried this since but it produced a radio button at the right side of each row (correctly) but with an edit and delete button below each row.  And nothing happens when I click them...any further thoughts?  Thanks.

[quote author=craygo link=topic=117718.msg480487#msg480487 date=1165500642]
Don't use a checkbox, use a radio button. That way you make sure only one record is selected. If you use a checkbox you could select multiple records and then on the update page you might end up looking at the wrong record.
I use this for mine
i use this little javascript in the head to double check that you want to delete the row

Then the form is like so
[code]<?php
include ("link.php");

if($query= mysql_query("SELECT * FROM inventory"))
{
   $num = mysql_num_rows($query);
}else
{
  die('There was an error with the query:
'.mysql_error());
}

if ($num == '0') {
echo "Nothing Exist.";
die();
}
else {

?>
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<td><font face=Arial>Stock#</font>
</td>
<td><font face=Arial>Year</font>
</td>
<td><font face=Arial>Make</font>
</td>
<td><font face=Arial>Model</font>
</td>
<td><font face=Arial>Price</font>
</td>
<td><font face=Arial>Miles</font>
</td>
<td><font face=Arial>Photo</font>
</td>
<td><font face=Arial>Select</font>
</td>
</tr>
<?

while ($info = mysql_fetch_array($query)) {
$id = $info['id']; // Put your id field here!!!
$stock = $info['stock'];
$year = $info['year'];
$make = $info['make'];
$model = $info['model'];
$price = $info['price'];
$miles = $info['miles'];
$photo1 = $info['photo1'];
echo ("
<tr>
<td> <font face=Arial>$stock</font>
</td>
<td> <font face=Arial>$year</font>
</td>
<td> <font face=Arial>$make</font>
</td>
<td> <font face=Arial>$model</font>
</td>
<td> <font face=Arial>$price</font>
</td>
<td> <font face=Arial>$miles</font>
</td>
<td> <font face=Arial>$photo1</font>
</td>
<td colspan=2 align=center><input type=radio name=baseid value=$id>
</td>
</tr>
<tr>
<td align=center colspan=8><input type=Submit name=edit value=Edit>&nbsp;&nbsp;&nbsp;<input type=Submit name=del onClick=\"return confirmSubmit()\" value=Delete>
</td>
");
}
?>
</table>
<?
}
?>[/code]

Then on your page that processes the script you would do this

[code]<?php
if(isset($_POST['del'])){
// put your code to delete here

} else (
if(isset($_POST['edit'])){
// put edit code here

} else {
// do nothing here
echo "No record was selected";
}
}
?>[/code]

As Obsidian said above, I tried to put in a little javascript do pop up when you hit the del button, but the site will not let me do it.

Ray
[/quote]
Link to comment
Share on other sites

[quote author=tracy link=topic=117718.msg480697#msg480697 date=1165521668]
What do you mean already within the confines of your table?  Already in the section of code that builds the table?
[/quote]

That's exactly what I meant. I just figured I'd leave all that markup off my code since you already had it.
Link to comment
Share on other sites

here is the new code, error on line 50, unexpected '/'...

I don't think this code is right...I think made an error...I just don't know where...

thanks.

// Second, before your table starts, you'll want to start a form for your checkboxes:
echo "<form name=\"deleteForm\" action=\"\" method=\"post\">\n";

<table border="0" cellspacing="2" cellpadding="2">
<tr>
// Assuming you are already within the confines of your table:
while ($info = mysql_fetch_array($query)) {
  echo "<td>$info[stock]</td>\n";
  echo "<td>$info[year]</td>\n";
  echo "<td>$info[make]</td>\n";
  echo "<td>$info[model]</td>\n";
  echo "<td>$info[price]</td>\n";
  echo "<td>$info[miles]</td>\n";
  echo "<td>$info[photo1]</td>\n";
 
  // Here is your added checkbox. The value is assuming you have an "ID" column in your inventory table
  // to uniquely identify your records
  echo "<td><input type=\"checkbox\" name=\"del\" value=\"$info[id]\" /></td>\n";
}

<td><font face=Arial>Stock#</font>
</td>
<td><font face=Arial>Year</font>
</td>
<td><font face=Arial>Make</font>
</td>
<td><font face=Arial>Model</font>
</td>
<td><font face=Arial>Price</font>
</td>
<td><font face=Arial>Miles</font>
</td>
<td><font face=Arial>Photo</font>
</td>

// You must also add a submit button (I usually label mine according to its function):
echo "<tr><td colspan=\"8\"><input type=\"submit\" name=\"submit\" value=\"Delete Selected\" /></td></tr>\n";

</tr>

<?
");
}
?>
</table>
<?
}

// Then, once you wrap up your table, close the form
echo "</form>\n";

?>
Link to comment
Share on other sites

ok guys...here is the new code...it says unexpected $end on line 74...I can't figure it out. 

<?php
// First, somewhere in the header of your page (usually the first logic of any), you want to check
// and see if the "Delete" button has been pressed and process accordingly
if (isset($_POST['del']) && count($_POST['del']) > 0) {
  // Run a query to delete all selected records
  $sql = "DELETE FROM inventory WHERE id IN ('" . implode(',', $_POST['del']) . "')";
  mysql_query($sql);
}

include ("link.php");

if($query= mysql_query("SELECT * FROM inventory"))
{
  $num = mysql_num_rows($query); 
}else
{
  die('There was an error with the query:
'.mysql_error());


if ($num == '0') {
echo "Nothing Exist.";
die();
}
else {

?>

// Second, before your table starts, you'll want to start a form for your checkboxes:
echo "<form name=\"deleteForm\" action=\"\" method=\"post\">\n";

<table border="0" cellspacing="2" cellpadding="2">
<tr>
// Assuming you are already within the confines of your table:
while ($info = mysql_fetch_array($query)) {
  echo "<td>$info[stock]</td>\n";
  echo "<td>$info[year]</td>\n";
  echo "<td>$info[make]</td>\n";
  echo "<td>$info[model]</td>\n";
  echo "<td>$info[price]</td>\n";
  echo "<td>$info[miles]</td>\n";
  echo "<td>$info[photo1]</td>\n";
 
  // Here is your added checkbox. The value is assuming you have an "ID" column in your inventory table
  // to uniquely identify your records
  echo "<td><input type=\"checkbox\" name=\"del\" value=\"$info[id]\" /></td>\n";
}

// You must also add a submit button (I usually label mine according to its function):
echo "<tr><td colspan=\"8\"><input type=\"submit\" name=\"submit\" value=\"Delete Selected\" /></td></tr>\n";
<td><font face=Arial>Stock#</font>
</td>
<td><font face=Arial>Year</font>
</td>
<td><font face=Arial>Make</font>
</td>
<td><font face=Arial>Model</font>
</td>
<td><font face=Arial>Price</font>
</td>
<td><font face=Arial>Miles</font>
</td>
<td><font face=Arial>Photo</font>
</td>
</tr>

<?
");
}
?>
</table>
<?
}
Link to comment
Share on other sites

You have a few errors with your echo statements

try this
[code]<?php
// First, somewhere in the header of your page (usually the first logic of any), you want to check
// and see if the "Delete" button has been pressed and process accordingly
if (isset($_POST['del']) && count($_POST['del']) > 0) {
 // Run a query to delete all selected records
 $sql = "DELETE FROM inventory WHERE id IN ('" . implode(',', $_POST['del']) . "')";
 mysql_query($sql);
}

include ("link.php");

if($query= mysql_query("SELECT * FROM inventory"))
{
  $num = mysql_num_rows($query);
}else
{
 die('There was an error with the query:
'.mysql_error());
}

if ($num == '0') {
echo "Nothing Exist.";
die();
}
else {

// Second, before your table starts, you'll want to start a form for your checkboxes:
echo "<form name=\"deleteForm\" action=\"\" method=\"post\">\n

<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\">
<tr>";
// Assuming you are already within the confines of your table:
while ($info = mysql_fetch_array($query)) {
 echo "<td>$info[stock]</td>\n";
 echo "<td>$info[year]</td>\n";
 echo "<td>$info[make]</td>\n";
 echo "<td>$info[model]</td>\n";
 echo "<td>$info[price]</td>\n";
 echo "<td>$info[miles]</td>\n";
 echo "<td>$info[photo1]</td>\n";

 // Here is your added checkbox. The value is assuming you have an "ID" column in your inventory table
 // to uniquely identify your records
 echo "<td><input type=\"checkbox\" name=\"del\" value=\"$info[id]\" /></td>\n";
}

// You must also add a submit button (I usually label mine according to its function):
echo "<tr><td colspan=\"8\"><input type=\"submit\" name=\"submit\" value=\"Delete Selected\" /></td></tr>\n
<td><font face=Arial>Stock#</font>
</td>
<td><font face=Arial>Year</font>
</td>
<td><font face=Arial>Make</font>
</td>
<td><font face=Arial>Model</font>
</td>
<td><font face=Arial>Price</font>
</td>
<td><font face=Arial>Miles</font>
</td>
<td><font face=Arial>Photo</font>
</td>
</tr>";
}
?>
</table>[/code]

Ray
Link to comment
Share on other sites

OK I have 2 pages for ya. These will aloow you to edit/delete one or multiple rows in the database.

first page
stackmanage.php
[code]<?php
include ("link.php");
// Check to see if the edit button was pressed
if(isset($_GET['edit'])){
// start your array of id's
$ids = array();
// fill your array with the id's selected
    foreach($_GET['stockid'] as $id){
    $ids[] = $id;
    }
// start your form
echo "<form name=edit action=\"update.php\" method=POST>";
// Loop through the id's. query database to get infor for each id
  foreach($ids as $stockid){
  $sql = "SELECT * FROM inventory WHERE id = $stockid";
  $res = mysql_query($sql) or die (mysql_error());
  $i=0;
  $r = mysql_fetch_array($res);
// print the form for each id
  echo "<table width=500 align=center>";
    while($i < mysql_num_fields($res)){
    $meta = mysql_fetch_field($res, $i);
      if($meta->name <> "id"){
      echo "<input type=hidden name=stockid[".$r['id']."] value=\"".$r['id']."\">";
      print '<tr>
            <td width=150>'.$meta->name.'</td>
            <td width=350><input type=text size=50 name="'.$meta->name.'['.$r['id'].']" value="'.$r[$i].'"></td>
            </tr>';
      }
    $i++;
    }
  echo "<hr>";
  }
  print '<tr>
        <td colspan=2 align=center><input type=submit value=Change></td>
        </tr>
        </table>
        </form>';
} else {
// check to see if the delete button has been pressed
  if(isset($_GET['del'])){
  // Start array of id's
  $ids = array();
  // Fill array with values
  foreach($_GET['stockid'] as $id){
  $ids[] = $id;
  }
  // Loop through array and delete each id
  foreach($ids as $stockid){
  $sql = "DELETE FROM inventory WHERE id = $stockid";
  $res = mysql_query($sql) or die (mysql_error());
    if(!$res){
    echo "Could not DELETE stock# $stockid<br>SQL: $sql<br> Error: ".mysql_error();
    } else {
    echo "Stock# $stockid Sucessfully deleted<br>";
    }
  }
  echo "Click <a href=\"stockmanage.php\">HERE</a> To return to stock list</p>";
} else {
// If nothing has been pressed show list of stock items
  if($query= mysql_query("SELECT * FROM inventory")){
  $num = mysql_num_rows($query);
  } else {
  die('There was an error with the query:'.mysql_error());
  }
  if ($num == '0') {
  echo "Nothing Exist.";
  die();
} else {
?>
<form action="" method=get>
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<td><font face=Arial>Stock#</font>
</td>
<td><font face=Arial>Year</font>
</td>
<td><font face=Arial>Make</font>
</td>
<td><font face=Arial>Model</font>
</td>
<td><font face=Arial>Price</font>
</td>
<td><font face=Arial>Miles</font>
</td>
<td><font face=Arial>Photo</font>
</td>
<td><font face=Arial>Select</font>
</td>
</tr>
<?
$bgcolor = "FFFFFF";
while ($info = mysql_fetch_array($query)) {
$id = $info['id']; // Put your id field here!!!
$stock = $info['stock'];
$year = $info['year'];
$make = $info['make'];
$model = $info['model'];
$price = $info['price'];
$miles = $info['miles'];
$photo1 = $info['photo1'];
// Alternate row color
if ($bgcolor == "#E0E0E0"){
  $bgcolor = "#FFFFFF";
} else {
  $bgcolor = "#E0E0E0";
}
echo ("
<tr bgcolor=$bgcolor>
<td> <font face=Arial>$stock</font>
</td>
<td> <font face=Arial>$year</font>
</td>
<td> <font face=Arial>$make</font>
</td>
<td> <font face=Arial>$model</font>
</td>
<td> <font face=Arial>$price</font>
</td>
<td> <font face=Arial>$miles</font>
</td>
<td> <font face=Arial>$photo1</font>
</td>
<td colspan=2 align=center><input type=checkbox name=stockid[] value=$id>
</td>
</tr>
");
}
echo "<tr>
<td align=center colspan=8>
<input type=Submit name=edit value=Edit>&nbsp;&nbsp;&nbsp;
<input type=Submit name=del onclick=\"return confirm('Are you sure you wish to delete the selected item(s)?');\" value=Delete>
</td>
<tr>
</table>
</form>";
}
}
}
?>[/code]

And here is update.php
[code]<?php
echo "<p align=center>";
// Connect to mysql below

foreach($_POST['stockid'] as $val){
$stock = $_POST['stock'][$val];
$year = $_POST['year'][$val];
$make = $_POST['make'][$val];
$model = $_POST['model'][$val];
$price = $_POST['price'][$val];
$miles = $_POST['miles'][$val];
$photo1 = $_POST['photo1'][$val];
$sql = "UPDATE inventory SET
        stock = '".$stock."',
        year = '".$year."',
        make = '".$make."',
        model = '".$model."',
        price = '".$price."',
        miles = '".$miles."',
        photo1 = '".$photo1."' WHERE id = '".$val."'";
$res = mysql_query($sql);
  if(!$res){
  echo "Could not update stock# $stock<br>SQL: $sql<br> Error: ".mysql_error();
  } else {
  echo "Stock# $stock Sucessfully updated<br>";
  }
}
echo "Click <a href=\"stockmanage.php\">HERE</a> To return to stock list</p>";
?>[/code]

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