tracy Posted December 27, 2006 Share Posted December 27, 2006 I have tried to change some php code and it won't quite work. I don't know if I'm on the right path here.I had a form that used php to update/delete the database (mysql)...it displayed the contents of the tableand allowed a checkbox for selection of the file for edit or delete. Then, it used an update to actually performthe changes...this was called update.php.I also have a form that now sends the picture file into a file folder on the server and the NAME of the same picture fileinto the database table...I'm trying to incorporate the two together so that the old update, which sent the actualpicture file into the database will send the picture file NAME only into the database and send the picture file to a file folder.Here is what I have so far. Obviously, the delete portion works. The update part on the TRIALinsert.php does nothingto the table...any thoughts are appreciated.[code][color=red]//here is the update file...named TRIALupdate.php[/color]<?phpecho "<p align=center>";// Connect to mysqlinclude "link.php";$absolute_path = "/home/working/public_html/misc"; $thumb_path = "/home/working/public_html/misc/thumbs"; $size_limit = "yes"; $limit_size = "600000"; $limit_ext = "yes"; $ext_count = "1"; $extensions = array(".jpg"); function resampimagejpg($forcedwidth, $forcedheight, $sourcefile, $destfile, $imgcomp) { $g_imgcomp=100-$imgcomp; $g_srcfile=$sourcefile; $g_dstfile=$destfile; $g_fw=$forcedwidth; $g_fh=$forcedheight; if(file_exists($g_srcfile)) { $g_is=getimagesize($g_srcfile); if(($g_is[0]-$g_fw)>=($g_is[1]-$g_fh)) { $g_iw=$g_fw; $g_ih=($g_fw/$g_is[0])*$g_is[1]; } else { $g_ih=$g_fh; $g_iw=($g_ih/$g_is[1])*$g_is[0]; } $img_src=imagecreatefromjpeg($g_srcfile); $img_dst=imagecreatetruecolor($g_iw,$g_ih); imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, $g_iw, $g_ih, $g_is[0], $g_is[1]); imagejpeg($img_dst, $g_dstfile, $g_imgcomp); imagedestroy($img_dst); return true; } else return false; }if(!isset($_POST['submit'])){ if (($extensions == "") or ($extensions == " ") or ($ext_count == "0") or ($ext_count == "") or ($limit_ext != "yes") or ($limit_ext == "")) { $extens = "any extension"; } else { $ext_count2 = $ext_count+1; for($counter=0; $counter<$ext_count; $counter++) { $extens = " $extensions[$counter]"; } } if (($limit_size == "") or ($size_limit != "yes")) { $limit_size = "any size"; } else { $limit_size .= " bytes"; $mb_size = ($limit_size/1000000); } $pichead = "<li><font size=\"2\" color=660000>File extension must be $extens<b>"; $pichead .="</b></font> <li><font size=\"2\" color=660000>Maximum file size is $limit_size ($mb_size MB)</font></li> <li><font size=\"2\" color=660000>No spaces in the filename</font></li>";?><?php} else {$i=0;$photoarray = array(); foreach ($_FILES["pictures"]["error"] as $key => $error) { $file_name = $_FILES["pictures"]['name'][$i]; // can call this anything you like this will take the original name $file = $_FILES["pictures"]['tmp_name'][$i]; $photoarray[$i+1]= $file_name; $endresult = "<font size=\"4\" color=990000>$file_name uploaded successfully</font>"; if ($file_name == "") { $pic = $i+1; $endresult = "<font size=\"4\" color=990000>Pic#$pic Not selected</font>"; }else{ if(file_exists("$absolute_path/$file_name")) { $endresult = "<font size=\"4\" color=990000>File Already Existed</font>"; } else { if (($size_limit == "yes") && ($limit_size < $file_size)) { $endresult = "<font size=\"4\" color=990000>File was to big</font>"; } else { $ext = strrchr($file_name,'.'); if (($limit_ext == "yes") && (!in_array($ext,$extensions))) { $endresult = "<font size=\"4\" color=990000>File is wrong type</font>"; }else{ // Save full size image with max width/height resampimagejpg(1000,1000,$file,"$absolute_path/$file_name",0); // Save thumb image with max width/height of 200 resampimagejpg(200,200,$file,"$thumb_path/$file_name",0); //copy($file, "$absolute_path/$file_name") or $endresult = "<font size=\"4\" color=990000>Couldn't Copy File To Server</font>"; } } } } $i++; echo $endresult."<br>"; }/********* Connection to mysql below **********/include "link.php";/*********** End connection string ************/$sql = "INSERT INTO inventory SET stock = '".$_POST['stock']."', year = '".$_POST['year']."', make = '".$_POST['make']."', model = '".$_POST['model']."', miles = '".$_POST['miles']."', price = '".$_POST['price']."', photo1 = '".$photoarray[1]."', photo2 = '".$photoarray[2]."', photo3 = '".$photoarray[3]."', photo4 = '".$photoarray[4]."', photo5 = '".$photoarray[5]."', photo6 = '".$photoarray[6]."'";$res = mysql_query($sql);if(!$res){echo "Could not insert Row<br>Error: ".mysql_error()."<br>SQL: ".$sql;} else {echo "Row inserted";}}?></body></html>[color=red]//here is the actual TRIALeditDELETE.php file...[/color]//used to display the contents of database table and selection for edit and deletion<?phpinclude ("link.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] Quote Link to comment https://forums.phpfreaks.com/topic/31964-phpmysql-update-file-code-changes-not-working/ Share on other sites More sharing options...
tracy Posted December 28, 2006 Author Share Posted December 28, 2006 Any ideas, anyone? Quote Link to comment https://forums.phpfreaks.com/topic/31964-phpmysql-update-file-code-changes-not-working/#findComment-148972 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.