Jump to content

fife

Members
  • Posts

    381
  • Joined

  • Last visited

Everything posted by fife

  1. fife

    Help

    Sorry I wouldn't know what to call this question. Right I have this query if(isset($_POST['insert_club'])){ //Process data for validation $name = trim($_POST['name']); $cat = trim($_POST['cat']); $memberID = trim($_POST['memberID']); $validationID = trim($_POST['validationID']); $creation_date = trim($_POST['CreationDate']); $new_cat = trim($_POST['newCat']); //perform validations $errors = array(); if(empty($name)) { $errors[] = "Please enter a name for your club"; } //Check if there were errors if(count($errors)===0) { // Prepare data for db insertion $name = mysql_real_escape_string($name); $cat = mysql_real_escape_string($cat); $memberID = mysql_real_escape_string($memberID); $validationID = mysql_real_escape_string($validationID); $creation_date = mysql_real_escape_string($creation_date); //post the details of the new category to me $query = "INSERT INTO clubs (`name`, `cat`, `memberID`, `validationID`, `CreationDate` ) VALUES ('$name', '$cat', '$memberID', '$validationID', '$creation_date' )"; $result= mysql_query($query) or die(mysql_error()); $url = "address.php?new_club=$validationID"; header("Location: $url"); }} It works great. Within that query there is a unused post $new_cat = trim($_POST['newCat']); Now I dont ever want this field entered into the database. Firstly. If its empty then I want nothing to happen with it but, if the user has entered something into the field then I want the contents of the field emailed to an address without effecting the rest of the query. Is this possible? I have written it so many different ways now and none of them seem to work.
  2. thank you I will hunt these down now
  3. Hi. I have two select fields one called category and the other sub category. Both are in the format. <select name="category" value=" <?php $qGetCat = "SELECT * FROM club_category" ; $rGetCat = mysql_query($qGetCat); while ($Cat = mysql_fetch_assoc($rGetCat)) { ?>" /> <option value="<?php echo $Cat['categorys'];?>"><?php echo $Cat['categorys']; ?></option> <?php } ?> </select> <select name="sub_category" value=" <?php $qGetSubCat = "SELECT * FROM sub_categorys" ; $rGetSubCat = mysql_query($qGetSubCat); while ($SubCat = mysql_fetch_assoc($rGetSubCat)) { ?>" /> <option value="<?php echo $SubCat['sub_categorys'];?>"><?php echo $SubCat['sub_categorys']; ?></option> <?php } ?> </select> Now I want to make it so that when a particular category is chosen for example self defence. The sub category when clicked shows all the self defence stuff. If watersports was chosen sub category would show things like swimming. What do I need to look up to do this? At the minute there is no link the way I have coded these to fields. In the database its self there is a; category table with categoryID and category_name sub category table with sub_cat_name and categoryID I think this will work but I have never done this so its making my head hurt just thinking about it. Does anyone have any advice, tuts or scripts to do this? Thank you
  4. Brillient thank you but I'm still having trouble with calling the array individually. heres what I have now function GetUser($user = "") { $qFindUser = "SELECT * FROM members WHERE email = '$user'"; $rFindUser = mysql_query($qFindUser) or die (mysql_error()); $UserInfo = mysql_fetch_array($rFindUser); return $UserInfo; } So to feed the function my parameters.. $User = GetUser($_SESSION['MM_Username']); echo $UserInfo['forename']; echo $UserInfo['surname']; I'm sorry but functions are really confusing me at the minute. lol. I will not stop till I understand them though.
  5. Hi. I am trying to write a function but they are new to me and confusing me. On multiple pages I am requesting users details. I thought instead of writing out the query every time I want to do this I would include a functions page with the query in it. The only variable I carry from the user is the user name as a session when they log in. The user name is the email address of the person signed in. so here is my first function. As im sure you can see it doesn't work but I don't understand why or how to call it properly. Can someone please explain.... function GetUser($user = "") { $qFindUser = "SELECT * FROM members WHERE email = '$user'"; $rFindUser = mysql_query($qFindUser) or die (mysql_error()); $UserInfo = mysql_fetch_array($rFindUser); } calling the function to return all details of a member as an array. <?php $Name = $_SESSION['MM_Username']; $UserInfo = GetUser($Name); echo $UserInfo['forename']; ?>
  6. perfect thank you
  7. Hi. Right I'm trying to write a little script that selects one random image from a group and displays it on the page. Here is my code... $TheCat = $data['album_name']; $GetAPicy = "SELECT photo_name, album FROM photos WHERE album = '$TheCat' ORDER BY rand LIMIT 1"; $rGetAPicy = mysql_query($GetAPicy) or die(mysql_error()); $Picy = mysql_fetch_array($rGetAPicy); With this code I get the following error Unknown column 'rand' in 'order clause' Obviously I can see the error but I dont understand where they are supposed to be placed. Can anyone help?
  8. here the new link and still no echo of the image_name http://www.website.co.uk/manage/gallery/add_image_to_album.php?image_name=events.png I'm just escaping the php so I can see my code correctly with putting those quotes in. I have never had it effect anything else before
  9. cool that has changed but still nothing echo's in the really annoyingly simple statement
  10. what do you mean I don,t understand. I don,t want to display the image. Just the name
  11. http://www.website.uk/manage/gallery/add_image_to_album.php?image_name='landscapes.png' Im asking it to echo image_name but nothing is displayed
  12. no sorry i explained that wrong. There is no error here is what the link looks like....... http://www.website.co.uk/manage/gallery/add_image_to_album.php?image_name='landscapes.png' Im asking it to echo the image_name but it echos nothing
  13. Ok strange one. I have an image upload script. It works fine and the image uploads and puts its name in my database. I also then post the name to the next page. Here is the image uploader <?php if (isset($_POST['insert_image'])) { $folder = "../../images/image_box/"; move_uploaded_file($_FILES["photo"]["tmp_name"] , "$folder".$_FILES["photo"]["name"]) or die(mysql_error()); //connect to database include('../../Connections/database.php'); $photo = $_FILES["photo"]["name"]; $qInsert = "INSERT INTO `photos` (`photo_name`) VALUES ('".$photo."')"; $rInsert = mysql_query($qInsert) or die(mysql_error()); //Tells you if its all ok if ($rInsert) { $url = "add_image_to_album.php?image_name='".$photo."'" or die(mysql_error()); header("Location: ".$url.""); } else { $errors = "There was an error inserting the image into the database"; } } ?> Notice I then post the image name to the next page. Now on the next page I have only this <?php include('../../Connections/database.php'); session_start();?> <?php echo '".$_GET['image_name']."' ;?> But there is an error at line one but I have tested the connection and its fine so its erroring displaying for example; landscape.png Does it have something to do with the .png in the name? If so how do i solve this?
  14. fife

    Show more

    Hi I have made a view all albums page for my website and I want it to only show 10 records. If there are more than 10 I would like a next or previous button to appear and for them to take you to the next 10 records or previous 10 records. Please can somebody show me where I can learn how to do this? I know it has something to do with msql_num_rows so I have a variable called $numrows I'll post the code I currently have here <form name="view_all_albums_frm" id="view_all_albums_frm"> <table width="793" border="0" cellspacing="5" id="all_albums_tbl" cellpadding="0"> <tr> <th scope="col">ID</th> <th scope="col">Album</th> <th scope="col">Album Description</th> <th scope="col">Edit</th> <th scope="col">Delete</th> </tr> <tr> <?php $qGetAlbums = ("SELECT * FROM albums ORDER BY `id` asc"); $rGetAlbums = mysql_query($qGetAlbums) or die(mysql_error()); $numrows = mysql_num_rows($rGetAlbums); while($AllAlbums = mysql_fetch_assoc($rGetAlbums)) { ?> <th height="26" scope="col"><?php echo $AllAlbums['id']; ?></th> <th height="26" scope="col"><?php echo $AllAlbums['album_name']; ?></th> <th scope="col"><?php echo $AllAlbums['album_description']; ?></th> <th scope="col"> </th> <th scope="col"> </th> </tr> <?php } ?> </table> </form>
  15. fife

    Auto delete

    Well I just ran the code from the changes above and simplified the query as I did not need all of that data but it still does not work. Here is the code as it stands at the minute <div id="editindexpage"> <?php $qGetId = "SELECT * FROM `polaroids` WHERE id='".$_GET['delete_polaroid']."'"; $result = mysql_query($qGetId) or die (mysql_error()); $pola=mysql_fetch_array($result); ?> <p class="bold">Are you sure you want to delete this polaroid from the database?</p><br/> <a href="deleting_stuff_check.php?delete_comp=1">Yes</a> <?php $action = $_GET['delete_comp']; if(isset($action)) { if($action == "1") { mysql_query("DELETE FROM polaroids WHERE id='".$_GET['delete_polaroid']."'"); echo "Complete"; } } ?> <a href="polaroids.php">No</a> </div> Here is the funny thing. When I click the yes button to run the query the echo statement of Complete appears but the image reference is still in the database.
  16. I have an issue with my delete feature on my site. A user selects a photo to delete. It then takes them to the are you sure you want to do this page with the id of the image under delete polaroid. This page has the following code on it.... <div id="editindexpage"> <?php $qGetId = "SELECT * FROM `polaroids` WHERE id='".$_GET['delete_polaroid']."'"; $result = mysql_query($qGetId) or die (mysql_error()) ; $pola=mysql_fetch_array($result); $GetCat = "SELECT * FROM category WHERE cat_name='".$pola['catid']."'"; $Result = mysql_query($GetCat); $GotCat = mysql_fetch_assoc($Result); ?> <p class="bold">Are you sure you want to delete <?php echo $GotCat['cat_name'];?> and its image from the database?</p><br/> <a href="polaroids.php?delete_comp= <?php mysql_query("DELETE FROM polaroids WHERE id='".$_GET['delete_polaroid']."'"); mysql_query("DELETE FROM category WHERE cat_name='".$pola['catid']."'"); ?>">Yes</a> <a href="polaroids.php">No</a> </div> My issue is this. Even if you select no for some reason it deletes the selected file. I dont understand how this is possible can anybody please help? Thank you
  17. Hi and Merry Christmas to all Right I am looking for an image uploading script that as well as uploads images to a folder but also stores its name in a sql database. Does anybody know of any good scripts? There seems to be loads of them an I dont know which is best! Thank you
  18. yes I thought of both of these issues but..... The the include('photoconnect.php') is correct. The code is exactly the same as on another page with the same include in the same folder. I just dont understand whats wrong.
  19. Hi I have this script which I hope to upload an image to my images folder and put the name of the image in my database along with what category it belongs too. I keep getting this error though.... Access denied for user 'websitename.co.uk'@'localhost' (using password: NO) Now when I check the server logs I get the following error to go with it... [Thu Dec 23 13:53:30 2010] [error] [client 0.0.0.0] PHP Warning: mysql_query() [<a href='function.mysql-query'>function.mysql-query</a>]: A link to the server could not be established in /home/sites/website name.co.uk/public_html/manage/upload.php on line 14, referer: http://www.websitename.co.uk/manage/add_image.php?cat='Robbers' Lie 14 is this... mysql_query("INSERT INTO `polaroids` VALUES ('$pic', '$category')") or die (mysql_error()); Ok so here is the code from the beginning. Ill start with the form its self.... <form enctype="multipart/form-data" action="upload.php" id="polaroidfrm" method="POST"> Please upload a PNG for the category <?php echo $_GET['cat']; ?>:<br> <input name="photo" type="file" size="40"/> </p> <br/> <input type="hidden" name="category" Value="<?php echo $_GET['cat']; ?>"> <input type="submit" value="Submit" name="insert_polaroid"> </form> then the upload page.... <?php //This is the directory where images will be saved $target = "images/polaroids/"; $target = $target . basename( $_FILES['photo']['name']); //This gets all the other information from the form $category=$_POST['catid']; $pic=($_FILES['photo']['name']); // Connects to your Database include('../../Connections/photoconnect.php'); session_start(); //Writes the information to the database mysql_query("INSERT INTO `polaroids` VALUES ('$pic', '$category')") or die (mysql_error()); //Writes the photo to the server if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { //Tells you if its all ok $success = "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; $url = "polaroids.php?polaroidpass='".$success."'" or die(mysql_error()); header("Location: ".$url.""); } else { //Gives and error if its not $fail = "Sorry, there was a problem uploading your file."; $url = "polaroids.php?polaroidfail='".$fail."'" or die(mysql_error()); header("Location: ".$url.""); } ?>
  20. cool thank you
  21. Hi. I am building an update table form. In this table there are only two fields, Header and Intro. Now I have the form and currently it displays whats already in the database. Now when the user edits these two fields and presses edit. Obviously I want it to update these fields. I have the code here but there is an issue with it. At the end of the update I believe I need a update fields WHERE....... which would be used if there was more than one entrance in the table but there is and only ever will be one entry. WHERE what? I dont have a where anything. Do I need this or can it be omitted somehow? <?php if(isset($_POST['edit'])){ //Process data for validation $header = trim($_POST['header']); $intro = trim($_POST['intro']); //Perform validations next //Prepare data for db insertion $header = mysql_real_escape_string($header); $intro = mysql_real_escape_string($intro); //insert $qUpdateDetails = "UPDATE index SET `header` = '".$header."', `intro` = '".$intro."', WHERE ???????='".?????????."'"; $rUpdateDetails = mysql_query($qUpdateDetails) or die(mysql_error()); //next page $page_edit = "Index page has been edited"; $url = "signed.php?edit='".$page_edit."'" or die(mysql_error()); header("Location: ".$url."") or die(mysql_error()); exit(); } } ?>
  22. fife

    num_rows

    ok really simple question. I'm going blind staring at this code so can someone please help. All I want to do is echo the number of rows in a table. Here is the code <?php $qCheckFirstLog = "SELECT * FROM logindetails WHERE email = '".$_SESSION['email']."'"; $rCheckFirstLog = mysql_query($qCheckFirstLog); $num_rows = mysql_num_rows($rCheckFirstLog); ?> Now there are 15 records with the session emails name in the table. I know the session email is there as it echos an email if I ask it too so thats not missing but when I put <?php echo $num_rows; ?> I get nothing!!!!!! Can someone please tell me what I'm doing wrong Thank you
  23. Hi I have a login script which goes at the top of several pages in my site. It works fine but I am trying to save some coding and re-writing out my script at the top of each of the pages. Instead I have made a page called login.php and put all of the code for the script in there. Looks like this.... <?php //login script if(isset($_POST['log'])) { $emaillog = stripslashes($_POST['emaillog']); $passwordlog = stripslashes($_POST['passwordlog']); $emaillog = mysql_real_escape_string($_POST['emaillog']); $passwordmd5 = md5($passwordlog); //generate random session id which i want to follow the user round the site! $CheckUser = "SELECT * FROM members WHERE email='".$emaillog."' AND password='".$passwordmd5."'"; $userDetails2 = mysql_query($CheckUser); $userInfo = mysql_fetch_array($userDetails2); $count = mysql_num_rows($userDetails2); if($count != 0) { $_SESSION['memberID'] = $userInfo['memberID']; $_SESSION['accesslevel']= $userInfo['accesslevel']; $_SESSION['email']= $userInfo['email']; //add an id that will be carried throughout the user until the session is destroyed function getUniqueCode2($length2 = "") { $code2 = md5(uniqid(rand(), true)); if ($length2 != "") return substr($code2, 0, $length2); else return $code2; } $randomKey = getUniqueCode2(25); $_SESSION['key'] = $randomKey; //the user must have an access level of 2, before they can login if($_SESSION['accesslevel']=='2') $url = "loggedin/index.php"; header("Location: ".$url.""); $success = '1'; } else { $success = '0'; $logged = "incorrect login details" or die(mysql_error()); } //now we need to update the login table to reflect a login if($success =='1'){ $time = date("Y-m-d h:m:s"); $qupdate_mem_logins = "INSERT INTO logindetails (`email`,`time`) VALUES ('".$emaillog."','".$time."')"; $rupdate_mem_logs = mysql_query($qupdate_mem_logins) or die(mysql_error()); ?> Now on the index page how do I reffer to this login script when someone fills in the form At the minute I have the following code but it is not checking or running anything. <?php //login script if(isset($_POST['log'])) { include('login.php'); } } ?>
  24. Hi. Completely new to Java script this day! I have been looking for a plugin image slider with captions for my site. I found a very simple to use one but for some reason it does not work. I have spent hours now reading the code to see what the error is but I cant find it. Can anybody help. Here is the code..... <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"> var SlideShowSpeed = 3000; var CrossFadeDuration = 3; var Picture = new Array(); var Caption = new Array(); Picture[1] = 'images/york_road/first_slide.jpg'; Picture[2] = 'images/york_road/last_slide.jpg'; Caption[1] = "This is the first caption."; Caption[2] = "This is the second caption."; var tss; var iss; var jss = 1; var pss = Picture.length-1; var preLoad = new Array(); for (iss = 1; iss < pss+1; iss++){ preLoad[iss] = new Image(); preLoad[iss].src = Picture[iss];} function runSlideShow(){ if (document.all){ document.images.PictureBox.style.filter="blendTrans(duration=2)"; document.images.PictureBox.style.filter="blendTrans(duration=CrossFadeDuration)"; document.images.PictureBox.filters.blendTrans.Apply();} document.images.PictureBox.src = preLoad[jss].src; if (document.getElementById) document.getElementById("CaptionBox").innerHTML= Caption[jss]; if (document.all) document.images.PictureBox.filters.blendTrans.Play(); jss = jss + 1; if (jss > (pss)) jss=1; tss = setTimeout('runSlideShow()', SlideShowSpeed); } </script> Then The html <table border=0 cellpadding=0 cellspacing=0> <tr> <td width=350 height=234> <img src=images/york_road/first_slide.jpg name=PictureBox width=350 height=234> </td> </tr> <tr> <td id=CaptionBox class=Caption align=center bgcolor=#6633FF> Kitchen Development. </td> </tr> </table> and the css .Caption { font-family: Arial; font-weight: bold; color: #000000; }
  25. Hi I have this script i wrote which show four random business from my database inline. Now I want this script to show the four results for 5 seconds and then show another 4 businesses for 5 seconds and so on. Can someone please point me in the right direction as to what I need to be looking up to do this as I dont know where to begin. here is the code by the way <?php $qGetUsers = "SELECT * FROM business ORDER BY rand() LIMIT 4"; $rGetUsers = mysql_query($qGetUsers) or die(mysql_error()); while($allUsers = mysql_fetch_array($rGetUsers)) { ?> <table id="top4tbl" width="150px" height="141px" border="0" cellpadding="0" cellspacing="5"> <tr> <td width="150" ><div align="center"><img src="<?php echo $allUsers['image_location'];?>" /> </div></td> </tr> <tr> <td width="150" ><div align="center"><strong><?php echo $allUsers['Business_name'];?> </strong></div></td> </tr> <tr> </tr> <tr> <td width="150" height="20"><div align="center"><a href="businessinformation.php?businessid=<?php echo $allUsers['businessid'];?>">More Info</a></div></td> </tr> </table> <?php } ?>
×
×
  • 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.