tracy Posted December 11, 2006 Author Share Posted December 11, 2006 would it be possible for you to demonstrate, using the code I supplied for the table, exactly what your suggestion should look like in php? I tried it but fell painfully short...it was simply a mess...I'd like to see your way work and compare it to the checkbox method...If it's too much trouble, fine. Thanks for all your help so far...[quote author=obsidian link=topic=117718.msg480482#msg480482 date=1165500180]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 beforeif (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 ;)[/quote] Quote Link to comment Share on other sites More sharing options...
tracy Posted December 11, 2006 Author Share Posted December 11, 2006 I think we're close on your method-to getting it to work for me. Any further help is appreciated. Sorry I don't have more info regarding the error, just what I posted.[quote author=craygo link=topic=117718.msg482167#msg482167 date=1165767929]Not sure if all the fields I used are the same as yours. Check for spelling and case. Let me know. Also if you could give the entire error and the line it is on.Ray[/quote] Quote Link to comment Share on other sites More sharing options...
craygo Posted December 11, 2006 Share Posted December 11, 2006 Can you give me all the fields that are in the inventory table. I think my code may not match your table structure.Ray Quote Link to comment Share on other sites More sharing options...
tracy Posted December 11, 2006 Author Share Posted December 11, 2006 Here they are...Stock (this is the main category that is to be used for selection, etc. It represents the stock number)YearMakeModelPriceMilesPhoto Quote Link to comment Share on other sites More sharing options...
simcoweb Posted December 11, 2006 Share Posted December 11, 2006 Ok, Tracy..continuing here from your other thread. You've got some heavy hitters helping you here already. The only suggestion I can make is to use a different less complicated method. I just did something very similar for a client and it works like a charm. No checkboxes, though. Which, IMHO, complicate what you're trying to accomplish. You could easily display the product list and have text links pointing to the delete script and/or the update script. If that interests you then let me know. Quote Link to comment Share on other sites More sharing options...
tracy Posted December 11, 2006 Author Share Posted December 11, 2006 I agree, I have some talented people helping me. I am very interested in the hyperlinks to the edit/delete pages you mentioned. Could you demonstrate that using my table? I have trouble getting the hyperlink associated with the actual data for that line of the table... Quote Link to comment Share on other sites More sharing options...
simcoweb Posted December 11, 2006 Share Posted December 11, 2006 Yes, these guys rock. No doubt. Ok, here's my method. It's simple.The checkbox is really only useful if you are, in fact, thinking of modifying multiple items at once which could be dangerous. ;)I'm shooting from the hip here but it appears what you want to do is display a list of your items and have the choice to edit or delete them. If you edit them then it would naturally update your MySQL database when doing so.First, you'd run the query to get your results from the database/table. This can be simple since you want everything:[code]<?php$sql = "SELECT * FROM table_name";$results = mysql_query($sql) or die(mysql_error());?>[/code]To display the results it would be something like:[code]<?php// start our table for results with table headersecho "<table width='700' border='1' align='center'><tr>";echo "<th>Produc ID</th><th>Product Name</th><th>Update</th><th>Delete</th></tr>";// loop through query results to display productswhile ($row = mysql_fetch_array($results)){ echo "<tr><td><font class='bodytext'>" . $row['Product_ID'] . "</td><td><font class='bodytext'>" . $row['Product_Name'] . "</td><td><font class='bodytext'><a href='updateproduct.php?Product_ID=" . $row['Product_ID'] . "'>Update</a></td> <td><font class='bodytext'><a href='delete.php?Product_ID=" . $row['Product_ID'] . "'>Delete</a></font></td></tr>";}// close tableecho "</table>\n";?>[/code]This would display your products in rows like this:Product ID Product Name Update Delete1001 Bozo Doll (link) (link)1002 Paris Doll (link) (link)The 'Update' link would take you to a page where all the details are viewable about that product in a form view meaning all the form fields are prepopulated with the current data. You'd make the changes and hit the Update/Submit button which runs a script using the UPDATE function pointing to a WHERE product_id=$product_id. Now, pay close attention to this snippet. We're going to pass the product ID through the URL:[code]<?php<a href='delete.php?Product_ID=" . $row['Product_ID'] . "'>Delete</a>?>[/code]Basically this is the hyperlink code that the 'Update' link points to. It points to my delete.php script (which, when clicked on, runs the DELETE function from the Mysql table) and passes the product ID through the URL. The delete.php script snags it via the $_GET statement as a variable:$product_ID = $_GET['product_ID'];Which sets the value of that variable which then tells the Delete or the Update script which product you're talking about. Then the queries for either of those functions uses that variable like this:"UPDATE table_name SET 'col_1', 'col_2', 'col_3', 'etc' WHERE product_ID=$product_ID";Here's the actual code for the site that I did. This is for the UPDATE functionality only. But it illustrates how it would perform the action, identify the proper product with the $_GET function and so on.[code]<?php// insert updates into product databaseinclude 'db_config.php';include 'header.php';// post our variables$URL = $_POST['URL'];$Product_ID = $_POST['Product_ID'];$Product_Name = $_POST['Product_Name'];$Price = $_POST['Price'];$Sale_Price = $_POST['Sale_Price'];$Description = $_POST['Description'];$Category = $_POST['Category'];$Image = $_POST['Image'];$Postage = $_POST['Postage'];$Brand = $_POST['Brand'];$Availability = $_POST['Availability'];$Thumbnail = $_POST['Thumbnail'];$ThumbnailWidth = $_POST['ThumbnailWidth'];$ThumbnailHeight = $_POST['ThumbnailHeight'];//make connection to databasemysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());mysql_select_db($dbname) or die(mysql_error());$sql = "UPDATE Datafeed SET URL='$URL', Product_ID='$Product_ID', Product_Name='$Product_Name', Price='$Price', Sale_Price='$Sale_Price', Description='$Description', Category='$Category', Image='$Image', Postage='$Postage', Brand='$Brand', Availability='$Availability', Thumbnail='$Thumbnail', ThumbnailWidth='$ThumbnailWidth', ThumbnailHeight='$ThumbnailHeight' WHERE Product_ID='$Product_ID'";$results = mysql_query($sql) or die(mysql_error());if(! $results) { echo "<center><h3>Results Error</h3><br> Unable to update product.<br />\n";} else { echo "<h3>Product Updated</h3><br> Product was successfully updated.<br> <a href='updateproduct.php'>Click here</a> to update another";}include 'footer.php';?>[/code] Quote Link to comment Share on other sites More sharing options...
craygo Posted December 11, 2006 Share Posted December 11, 2006 Ok the script I gave you has a field called id which is a unique auto increment field I used when recreating your table. Obviously you do not have this field.Is your stock field an autoincrement field?? You should have one field as a unique identifier which auto increments so it cannot be duplicated. In any case here is a revised script. Also since the fields are case sensitive make sure they match.stockmanage.php[code]<?phpinclude ("link.php");// Check to see if the edit button was pressedif(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 formecho "<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 Stock = $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 <> "stock"){ echo "<input type=hidden name=stockid[".$r['stock']."] value=\"".$r['Stock']."\">"; print '<tr> <td colspan=2 align=center>Details for Stock# '.$r['Stock'].'</td> </tr> <tr> <td width=150>'.$meta->name.'</td> <td width=350><input type=text size=50 name="'.$meta->name.'['.$r['Stock'].']" 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 Stock = $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)) {$stock = $info['Stock'];$year = $info['Year'];$make = $info['Make'];$model = $info['Model'];$price = $info['Price'];$miles = $info['Miles'];$photo1 = $info['Photo1'];// Alternate row colorif ($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=$stock></td></tr>");}echo "<tr><td align=center colspan=8><input type=Submit name=edit value=Edit> <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]update.php[code]<?phpecho "<p align=center>";// Connect to mysql belowforeach($_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 Year = '".$year."', Make = '".$make."', Model = '".$model."', Price = '".$price."', Miles = '".$miles."', Photo1 = '".$photo1."' WHERE Stock = '".$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 Quote Link to comment Share on other sites More sharing options...
tracy Posted December 11, 2006 Author Share Posted December 11, 2006 That might be a big part that is messing up my efforts...the auto increment. The stock number is not auto incremented. It is uniquely assigned by the dealer. There is no way to auto incr that...however, the stock number is the main id number for each piece of inventory, so I must use it. If there is a way to associated it with a hidden auto incremented number, fine by me...Will the table/php work fine without an auto incr. number?Thanks. Quote Link to comment Share on other sites More sharing options...
craygo Posted December 11, 2006 Share Posted December 11, 2006 Yes it will work just fine without it. You will have to make sure you do not duplicate any stock numbers though. If you duplicate a stock number the script will update both rows with the same stock number even though you did not select that one. Where with an auto increment field you would select the correct stock number you want but all queries would be based on the unique identifier and not the stock number. So theoretically you could have duplicate stock numbers and still only update the stock you selected.if you want an example of the difference let me know.Ray Quote Link to comment Share on other sites More sharing options...
tracy Posted December 11, 2006 Author Share Posted December 11, 2006 Yes, that would be much better...thanks...I'd like that...That way duplicate numbers would be fine... Quote Link to comment Share on other sites More sharing options...
craygo Posted December 11, 2006 Share Posted December 11, 2006 In order to use the unique identifier you have to create a field. Do you use phpmyadmin?? if you do, bring up the structure of the table. Click on add field "at beginning of table". This way it will make it the first field. Then make it an interger field , length can be 11,Attributes = unsignedNull = "not Null"Default = "0"Extra = "Auto Increment"Click the radio button for "Primary"If you do not have phpmyadmin I will give you a script to do it through a web page.Post back when you have it. Or if you like I can give you an sql statement with the proper setup that you can run.Ray Quote Link to comment Share on other sites More sharing options...
tracy Posted December 11, 2006 Author Share Posted December 11, 2006 I can do it with phpmyadmin, no problem. I typically call that field 'id' (short for identifier)...Do you need me to do this first or can you demo the code now that you know the name...I will make the other data regarding this field per your instructions above...thanks... Quote Link to comment Share on other sites More sharing options...
craygo Posted December 11, 2006 Share Posted December 11, 2006 Actually the first code I used above with the 2 pages will work fine. Just make sure the fields match, both in case and spelling. I used all lower case for my code but I think you used upper/lower case. Let me know exactly what your table looks like and I will get it for ya. If you want use phpmyadmin to export the table and copy and paste the sql it creates.Ray Quote Link to comment Share on other sites More sharing options...
tracy Posted December 11, 2006 Author Share Posted December 11, 2006 Great...it appears to work fine...Turns out, the addition of the unique id column helped quite a bit. Thanks a lot for your help. I really appreciate it. Quote Link to comment Share on other sites More sharing options...
tracy Posted December 11, 2006 Author Share Posted December 11, 2006 One quick question...I was informed recently (perhaps by you) that I can only enter TEXT via the html form (that I am using to get the data into the mysql database). Is there any way to add some security (EASILY--SIMPLY) at that level...at the input level of the html form or the corresponding php post commands?I thought about the real escape string...Of course, that page is password protected anyway, but any php attack prevention is an additional help. Thanks again. Quote Link to comment Share on other sites More sharing options...
craygo Posted December 11, 2006 Share Posted December 11, 2006 Well since your query is now based on a number and not a string. I do not think you will have a problem. If you like you can change everything from $_GET to $_POST and that way no information will be passed through the url. Simple security thing for basic users. There are no queries now that look for any type of string. the delete and update queries are based on the id field now. I would probably change it from $_GET to $_POST since someone could substitute the id in the url and delete other rows.Ray Quote Link to comment Share on other sites More sharing options...
tracy Posted December 11, 2006 Author Share Posted December 11, 2006 Thanks. I appreciate it. Have a good one... Quote Link to comment Share on other sites More sharing options...
tracy Posted December 12, 2006 Author Share Posted December 12, 2006 I replaced all the $_GET with $_POST and it shows a table with no data...any thoughts? This is a security effort only. I'm just trying to go back and make the code more secure. If I need to start a new thread I will. Thanks again for all your help.[quote author=craygo link=topic=117718.msg482898#msg482898 date=1165867443]Well since your query is now based on a number and not a string. I do not think you will have a problem. If you like you can change everything from $_GET to $_POST and that way no information will be passed through the url. Simple security thing for basic users. There are no queries now that look for any type of string. the delete and update queries are based on the id field now. I would probably change it from $_GET to $_POST since someone could substitute the id in the url and delete other rows.Ray[/quote] Quote Link to comment Share on other sites More sharing options...
craygo Posted December 12, 2006 Share Posted December 12, 2006 OK reason why is you probably forgot to make the form method POST instead of GETHere is a modified script for both pages. Like before please check the spelling and case of field names. I also added some comments for the stock field. I was not sure of you wanted to be able to modify the stock number. So this code defaults to NO. but there are notes to change it.stockmanage.php[code]<?php// include ("link.php");require('config.php');include('includes/mysql.php');// Check to see if the edit button was pressedif(isset($_POST['edit'])){// start your array of id's$ids = array();// fill your array with the id's selected foreach($_POST['stockid'] as $id){ $ids[] = $id; }// start your formecho "<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>"; echo "<tr><td colspan=2 align=center><font color=red size=4><b>Now editing Stock# ".$r['stock']."</b></font></td></tr>"; while($i < mysql_num_fields($res)){ $meta = mysql_fetch_field($res, $i); /***************** If you would like to modify the stock number, remove **** && $meta->name <> "stock" **** below ******************/ if($meta->name <> "id" && $meta->name <> "stock"){ 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($_POST['del'])){ // Start array of id's $ids = array(); // Fill array with values foreach($_POST['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=POST><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 colorif ($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> <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]update.php[code]<?phpecho "<p align=center>";// Connect to mysqlrequire('config.php');include('includes/mysql.php');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];/****************************If you want to be able to modify the stock number add **** stock = '".$stock."', **** belowand uncomment the $stock variable above.*****************************/$sql = "UPDATE inventory SET 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]Let me know how you make outRay Quote Link to comment Share on other sites More sharing options...
tracy Posted December 12, 2006 Author Share Posted December 12, 2006 thanks Quote Link to comment Share on other sites More sharing options...
tracy Posted December 12, 2006 Author Share Posted December 12, 2006 What are lines 3 and 4? I took them out because they were causing errors. The delete works fine. But when I try to edit, I get these errors...Warning: require(config.php) [function.require]: failed to open stream: No such file or directory in /home/inv/public_html/update.php on line 4Warning: require(config.php) [function.require]: failed to open stream: No such file or directory in /home/inv/public_html/update.php on line 4Fatal error: require() [function.require]: Failed opening required 'config.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/inv/public_html/update.php on line 4[quote author=craygo link=topic=117718.msg483328#msg483328 date=1165936867]OK reason why is you probably forgot to make the form method POST instead of GETHere is a modified script for both pages. Like before please check the spelling and case of field names. I also added some comments for the stock field. I was not sure of you wanted to be able to modify the stock number. So this code defaults to NO. but there are notes to change it.stockmanage.php[code]<?php// include ("link.php");require('config.php');include('includes/mysql.php');// Check to see if the edit button was pressedif(isset($_POST['edit'])){// start your array of id's$ids = array();// fill your array with the id's selected foreach($_POST['stockid'] as $id){ $ids[] = $id; }// start your formecho "<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>"; echo "<tr><td colspan=2 align=center><font color=red size=4><b>Now editing Stock# ".$r['stock']."</b></font></td></tr>"; while($i < mysql_num_fields($res)){ $meta = mysql_fetch_field($res, $i); /***************** If you would like to modify the stock number, remove **** && $meta->name <> "stock" **** below ******************/ if($meta->name <> "id" && $meta->name <> "stock"){ 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($_POST['del'])){ // Start array of id's $ids = array(); // Fill array with values foreach($_POST['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=POST><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 colorif ($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> <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]update.php[code]<?phpecho "<p align=center>";// Connect to mysqlrequire('config.php');include('includes/mysql.php');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];/****************************If you want to be able to modify the stock number add **** stock = '".$stock."', **** belowand uncomment the $stock variable above.*****************************/$sql = "UPDATE inventory SET 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]Let me know how you make outRay[/quote] Quote Link to comment Share on other sites More sharing options...
tracy Posted December 12, 2006 Author Share Posted December 12, 2006 Here's the reason I took out lines three and four...Warning: require(config.php) [function.require]: failed to open stream: No such file or directory in /home/inv/public_html/NEWWORKINGTESTEDIT.php on line 3Warning: require(config.php) [function.require]: failed to open stream: No such file or directory in /home/inv/public_html/NEWWORKINGTESTEDIT.php on line 3Fatal error: require() [function.require]: Failed opening required 'config.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/inv/public_html/NEWWORKINGTESTEDIT.php on line 3These happen when the lines are there...I also noticed they are not in the original php script that works, using get, not post... Quote Link to comment Share on other sites More sharing options...
craygo Posted December 12, 2006 Share Posted December 12, 2006 Damn I always forget something. Those 2 includes are how I connect to my database server. Sorry I remembered and took them out of the original script, but forgot on the new one ;DSubstitute those line with your own connection to mysql.Ray Quote Link to comment Share on other sites More sharing options...
tracy Posted December 12, 2006 Author Share Posted December 12, 2006 Since I took them out, any thoughts on the new errors...The delete works fine. But when I try to edit, I get these errors...Warning: require(config.php) [function.require]: failed to open stream: No such file or directory in /home/inv/public_html/update.php on line 4Warning: require(config.php) [function.require]: failed to open stream: No such file or directory in /home/inv/public_html/update.php on line 4Fatal error: require() [function.require]: Failed opening required 'config.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/inv/public_html/update.php on line 4 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.