seasexsun Posted November 29, 2007 Share Posted November 29, 2007 Hi: I have these two constants that I got from a tutorial and that are being called by: require_once '../library/config.php'; define('ALBUM_IMG_DIR', '../images/album/'); // all images inside an album are stored here define('GALLERY_IMG_DIR', '../images/gallery/'); The directories work fine, but what happens is when I from the add-album script "add an album" and upload an image, it only adds it to one table, which is tbl_album but not the other which is tbl_image. I have tried adding another INSERT INTO in the following script, but I just cannot seem to get it to function properly. I've gone through every book on my shelf and am pulling my hair out. Below is the script that is not uploading to both directories but only the tbl_album. Thanks in advance... and again, both directories and tables are working fine if I query them separately. <?php require_once '../library/config.php'; require_once '../library/functions.php'; if(isset($_POST['txtName'])) { $albumName = $_POST['txtName']; $albumDesc = $_POST['mtxDesc']; $imgName = $_FILES['fleImage']['name']; $tmpName = $_FILES['fleImage']['tmp_name']; // we need to rename the image name just to avoid // duplicate file names // first get the file extension $ext = strrchr($imgName, "."); // then create a new random name $newName = md5(rand() * time()) . $ext; // the album image will be saved here $imgPath = ALBUM_IMG_DIR . $newName; // resize all album image $result = createThumbnail($tmpName, $imgPath, THUMBNAIL_WIDTH); if (!$result) { echo "Error uploading file"; exit; } if (!get_magic_quotes_gpc()) { $albumName = addslashes($albumName); $albumDesc = addslashes($albumDesc); } $query = "INSERT INTO tbl_album (al_name, al_description, al_image, al_date) VALUES ('$albumName', '$albumDesc', '$newName', NOW())"; mysql_query($query) or die('Error, add album failed : ' . mysql_error()); // the album is saved, go to the album list echo "<script>window.location.href='index.php?page=list-album';</script>"; exit; } ?> <form action="" method="post" enctype="multipart/form-data" name="frmAlbum" id="frmAlbum"> <table width="100%" border="0" cellpadding="2" cellspacing="1" class="table_grey"> <tr> <th width="150">Album Name</th> <td width="80" bgcolor="#FFFFFF"> <input name="txtName" type="text" id="txtName"></td> </tr> <tr> <th width="150">Description</th> <td bgcolor="#FFFFFF"> <textarea name="mtxDesc" cols="50" rows="4" id="mtxDesc"></textarea> </td> </tr> <tr> <th width="150">Image</th> <td bgcolor="#FFFFFF"> <input name="fleImage" type="file" class="box" id="fleImage"></td> </tr> <tr> <td width="150" bgcolor="#FFFFFF"> </td> <td bgcolor="#FFFFFF"> <input name="btnAdd" type="submit" id="btnAdd" value="Add Album"> <input name="btnCancel" type="button" id="btnCancel" value="Cancel" onClick="window.history.back();"></td> </tr> </table> </form> Quote Link to comment https://forums.phpfreaks.com/topic/79348-constants/ Share on other sites More sharing options...
PHP_PhREEEk Posted November 29, 2007 Share Posted November 29, 2007 >it only adds it to one table, which is tbl_album You have only one INSERT query, which does an insert into `tbl_album`, and that's it.. that's all you're asking it to do, and that's all it does. You say you tried another separate INSERT query, but what was that query? Please restate your question, as it's a bit confusing when compared to your code. Also, please post code between BBCode code tags. [ code]your code goes here[ /code] * remove spaces after the opening bracket of the code tags Or, in the advanced editor, just press the # icon PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/79348-constants/#findComment-401815 Share on other sites More sharing options...
seasexsun Posted November 29, 2007 Author Share Posted November 29, 2007 Thanks. I did notice that too so I tried to add another query, but it didn't seem to work. That made sense to me too, but wonder what it is that I'm doing wrong. So please, let me ask you this. If I add the query like this, why won't it work??? $query = "INSERT INTO tbl_album (al_name, al_description, al_image, al_date) VALUES ('$albumName', '$albumDesc', '$newName', NOW())"; $sql = "INSERT INTO tbl_image (im_album_id, im_title, im_description, im_image, im_thumbnail, im_date) VALUES ($albumId, '$imgTitle', '$imgDesc', '$image', '$thumbnail', NOW())"; mysql_query($query) or die('Error, add album failed : ' . mysql_error()); [ /code] Quote Link to comment https://forums.phpfreaks.com/topic/79348-constants/#findComment-402445 Share on other sites More sharing options...
roopurt18 Posted November 29, 2007 Share Posted November 29, 2007 What's the output from mysql_error()? Quote Link to comment https://forums.phpfreaks.com/topic/79348-constants/#findComment-402446 Share on other sites More sharing options...
PHP_PhREEEk Posted November 30, 2007 Share Posted November 30, 2007 You've built 2 querys now, but you're still only sending one of them. Try the following code, and note that although you have proper single quotes around values, you should add back ticks ( ` ) to field names and tables names. <?php $sql = "INSERT INTO `tbl_album` (`al_name`, `al_description`, `al_image`, `al_date`) VALUES ('$albumName', '$albumDesc', '$newName', NOW()) "; if ( !$result = mysql_query($sql) ) { die('Error, add album failed for table tbl_album: ' . mysql_error()); } $sql = "INSERT INTO `tbl_image` (`im_album_id`, `im_title`, `im_description`, `im_image`, `im_thumbnail`, `im_date`) VALUES ($albumId, '$imgTitle', '$imgDesc', '$image', '$thumbnail', NOW()) "; if ( !$result = mysql_query($sql) ) { die('Error, add album failed for table tbl_image: ' . mysql_error()); } ?> PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/79348-constants/#findComment-402655 Share on other sites More sharing options...
seasexsun Posted December 4, 2007 Author Share Posted December 4, 2007 Ok, thanks. I'll give that a go. I'm just so frustrated with this tutorial. It operates though exactly how I want my database to look, and that's the sad part. I cannot seem to debug it. Thanks for your help... Quote Link to comment https://forums.phpfreaks.com/topic/79348-constants/#findComment-405699 Share on other sites More sharing options...
teng84 Posted December 4, 2007 Share Posted December 4, 2007 if ( !$result = mysql_query($sql) ) { <<<<<<<< i dont think this line is correct!!!! i believe that will always return false Quote Link to comment https://forums.phpfreaks.com/topic/79348-constants/#findComment-405701 Share on other sites More sharing options...
PHP_PhREEEk Posted December 4, 2007 Share Posted December 4, 2007 if ( !$result = mysql_query($sql) ) { <<<<<<<< i dont think this line is correct!!!! i believe that will always return false So why don't you try it before proclaiming that you believe it doesn't work? Let me ask you this... is this valid? <?php if ( $result = mysql_query($sql) ) { // carry on wayward son; } else { // generate an error; } Of course it is, as long as $result receives a resource and becomes 'live' with a value. If it does not, it is false and the branch is traversed. So if we can test for true, we can certainly test for false with <?php if ( !$result = mysql_query($sql) ) { // generate an error; } else { // carry on wayward son; } PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/79348-constants/#findComment-405816 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.