drewwales Posted November 13, 2012 Share Posted November 13, 2012 For some reason my query is not working, mysql_select_db("UPDATE tbl_products SET p_feat='y',P_title=iPad Case, p_desc='Over the years since the launch of the iPhone and the iPad a whole ecosystem of cute little cases and stickers has sprung up to cover the svelte outlines of the Apple gadgets. Whether the case are to protect the devices, customise them or - in the case of the iPhone 4 - improve the antennae reception, Apple has always encouraged cases.' WHERE p_id='1'"); for some reason it will not update the record in the table, it does connect to the database as the rest of the page is doing what it needs to. here is the entire page code <?php session_start(); // if session is not set redirect the user if(empty($_SESSION['u_name'])) header("Location:index.html"); //if logout then destroy the session and redirect the user if(isset($_GET['logout'])) { session_destroy(); header("Location:index.html"); } else { //Connect to database from here $link = mysql_connect('localhost', 'root', ''); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db("db_name"); } if(isset($_SERVER["REQUEST_METHOD"])=="POST") if(!isset($_GET['p_feat'])) $feat = "n"; else $feat = "y"; { mysql_select_db("UPDATE tbl_products SET p_feat='".$feat."',P_title=".$_GET['p_title'].", p_desc='".$_GET['p_desc']."' WHERE p_id='".$_GET['P_ID']."'"); } $result = mysql_error(); if (isset($_POST["Delete"])) { $file = $_REQUEST['imgfile']; $filemain = $_REQUEST['imgfilemain']; $num_files=count($file); $num_filesmain=count($filemain); for($i=0;$i<$num_files;$i++) { unlink ("$file[$i]"); unlink ("$filemain[$i]"); } } if (!is_dir('../uploads/'.$_GET['P_ID'].'')) { mkdir('../uploads/'.$_GET['P_ID'].''); } if (!is_dir('../uploads/'.$_GET['P_ID'].'/thumbs')) { mkdir('../uploads/'.$_GET['P_ID'].'/thumbs'); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="css/admin-main.css" rel="stylesheet" type="text/css"> <link href="css/jquery.validate.css" rel="stylesheet" type="text/css"> <link href="css/style.css" rel="stylesheet" type="text/css"> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script> <script src="js/jquery.validate.js" type="text/javascript"></script> <script src="js/validatefields.js" type="text/javascript"></script> </head> <body> <div class="container"> <div class="logo"> <img src="images/logo.png" /> </div> <div class="content"> <div class="left"> <?php $result = mysql_query("SELECT * FROM tbl_cats"); while($row = mysql_fetch_array($result)) { echo "<a href='secure.php?CAT_ID=" . $row['cat_id'] . "'>" . $row['cat_title'] . "</a>"; echo "<br />"; } ?> </div> <div class="page-modify"> <?php if(isset($_GET['CAT_ID'])) { $result = mysql_query("SELECT * FROM tbl_cats inner join tbl_products p on p.p_catlink = " . $_REQUEST['CAT_ID'] . " where cat_id = P_catlink and cat_id = " . $_GET['CAT_ID'] . ""); while($row = mysql_fetch_array($result)) echo "<p><a href='secure.php'><u>Main</u></a> > <a href='secure.php?CAT_ID=" . $_REQUEST['CAT_ID'] . "'><u>" . $row['cat_title'] . "</u></a> > " . $row['p_title'] . "</p>"; echo "<p><b>Step 2: Product Images</b></p>"; echo "<div class='TabBody'>"; if (isset($_POST["submit"])) { if (isset($_POST["submit"])) { $uploadpath = "../uploads/".$_GET['P_ID']."/"; $uploadpath = $uploadpath.basename($_FILES["imgfile"]["name"]); if (!move_uploaded_file($_FILES["imgfile"]["tmp_name"], $uploadpath)) die("There was an error uploading the file, please try again!"); $image_name = "../uploads/".$_GET['P_ID']."/".$_FILES["imgfile"]["name"]; list($width,$height) = getimagesize($image_name); $new_image_name = "../uploads/".$_GET['P_ID']."/thumbs/thumb_".$_FILES["imgfile"]["name"]; if ($width > $height) { $ratio = (75/$width); $new_width = round($width*$ratio); $new_height = round($height*$ratio); } else { $ratio = (75/$height); $new_width = round($width*$ratio); $new_height = round($height*$ratio); } $image_p = imagecreatetruecolor($new_width,$new_height); $img_ext = $_FILES['imgfile']['type']; if ($img_ext == "image/jpg" || $img_ext == "image/jpeg") { $image = imagecreatefromjpeg($image_name); } else if ($img_ext == "image/png") { $image = imagecreatefrompng($image_name); } else if ($img_ext == "image/gif") { $image = imagecreatefromgif($image_name); } else { die('this is no valid image resource'); } imagecopyresampled($image_p,$image,0,0,0,0,$new_width,$new_height,$width,$height); imagejpeg($image_p,$new_image_name,100); } imagecopyresampled($image_p,$image,0,0,0,0,$new_width,$new_height,$width,$height); imagejpeg($image_p,$new_image_name,100); } ?> <form method="post" enctype="multipart/form-data"> Please select a picture to upload:<br /> <input type="file" name="imgfile" /> <br /> <input type="submit" name="submit" value="Add Image" /> </form> <hr /> <form method="post" action=""> <?php //lets assign the folder name in $title //You can assign any name $title= "../uploads/".$_GET['P_ID']; /*$directory corresponds to whole path. Edit to your preference. (i assume u store your images in directory named "images") */ $directory = "$title"; //The array specifies the format of the files $allowed_types=array('jpg','jpeg','gif','png'); $file_parts=array(); $ext=''; $title=''; $i=0; $dir_handle = @opendir($directory) or die("There is an error with your image directory!"); while ($file = readdir($dir_handle)) { if($file=='.' || $file == '..') continue; $file_parts = explode('.',$file); $ext = strtolower(array_pop($file_parts)); $title = implode('.',$file_parts); $title = htmlspecialchars($title); $nomargin=''; if(in_array($ext,$allowed_types)) { if(($i+1)%4==0) $nomargin='nomargin'; echo' <div id="picture" style="float:left;"> <img src="../uploads/'.$_GET['P_ID'].'/thumbs/thumb_'.$file.'"><br> Select <input type="checkbox" value="'.$directory.'/'.$file.'" name="imgfile[]"> <input type="hidden" value="'.$directory.'/thumbs/thumb_'.$file.'" name="imgfilemain[]"> </div>'; } $i++; } closedir($dir_handle); //Now we have the list of images within form elements ?><div class="clearboth"><br /></div> <input type="submit" value="Delete" name="Delete"> </form> <div class="clearboth"></div> <?php echo "</div>"; echo "</div>"; echo "</div>"; } ?> <div class="clearboth"></div> </div> </div> <div id="footer"><a href="secure.php?logout"><b>Logout</b></a></div> </body> </html> im not getting any errors or anything its just not updating the database, any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/270646-mysql_select_db-not-updating-tables/ Share on other sites More sharing options...
Jessica Posted November 13, 2012 Share Posted November 13, 2012 That's not what mysql_select_db is for. Did you read the manual page for that function? The manual is filled with examples on how to interact with mysql. You should move to mysqli and PDO however. Quote Link to comment https://forums.phpfreaks.com/topic/270646-mysql_select_db-not-updating-tables/#findComment-1392129 Share on other sites More sharing options...
drewwales Posted November 13, 2012 Author Share Posted November 13, 2012 That's not what mysql_select_db is for. Did you read the manual page for that function? The manual is filled with examples on how to interact with mysql. You should move to mysqli and PDO however. that being the case as im extremely tired even mysql_query("UPDATE tbl_products SET p_feat='y',P_title=iPad Case, p_desc='Over the years since the launch of the iPhone and the iPad a whole ecosystem of cute little cases and stickers has sprung up to cover the svelte outlines of the Apple gadgets. Whether the case are to protect the devices, customise them or - in the case of the iPhone 4 - improve the antennae reception, Apple has always encouraged cases.' WHERE p_id='1'"); is refusing to work. Quote Link to comment https://forums.phpfreaks.com/topic/270646-mysql_select_db-not-updating-tables/#findComment-1392133 Share on other sites More sharing options...
mikosiko Posted November 13, 2012 Share Posted November 13, 2012 ...and while you do that, enable error reporting and display errors ON, either in your php.ini conf. file (preferred) or in your particular script during development; doing that you would easily find this error ... and probably at least another that you have in your UPDATE sentence Quote Link to comment https://forums.phpfreaks.com/topic/270646-mysql_select_db-not-updating-tables/#findComment-1392135 Share on other sites More sharing options...
Jessica Posted November 13, 2012 Share Posted November 13, 2012 There is an error in your query. See the link in my signature on debugging your SQL. Quote Link to comment https://forums.phpfreaks.com/topic/270646-mysql_select_db-not-updating-tables/#findComment-1392136 Share on other sites More sharing options...
drewwales Posted November 13, 2012 Author Share Posted November 13, 2012 Still cant figure it out, I think I'm being dumb but should this be correct? //Connect to database from here $link = mysql_connect('localhost', 'root', ''); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db("db_here"); mysql_query("UPDATE tbl_products SET p_feat='".$feat."',P_title=".$_GET['p_title'].", p_desc='".$_GET['p_desc']."' WHERE p_id='".$_GET['P_ID']."'",$link); Quote Link to comment https://forums.phpfreaks.com/topic/270646-mysql_select_db-not-updating-tables/#findComment-1392139 Share on other sites More sharing options...
Jessica Posted November 13, 2012 Share Posted November 13, 2012 If you would do what I suggested, it'd be obvious. There is an error IN your query, which you could easily find out about by using the functions I talk about in the link I suggested you visit. Quote Link to comment https://forums.phpfreaks.com/topic/270646-mysql_select_db-not-updating-tables/#findComment-1392140 Share on other sites More sharing options...
drewwales Posted November 13, 2012 Author Share Posted November 13, 2012 If you would do what I suggested, it'd be obvious. There is an error IN your query, which you could easily find out about by using the functions I talk about in the link I suggested you visit. I haven't used php in years, I'm looking but not seeing anything useful. Quote Link to comment https://forums.phpfreaks.com/topic/270646-mysql_select_db-not-updating-tables/#findComment-1392143 Share on other sites More sharing options...
Jessica Posted November 13, 2012 Share Posted November 13, 2012 mysql_error Quote Link to comment https://forums.phpfreaks.com/topic/270646-mysql_select_db-not-updating-tables/#findComment-1392145 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.