Jump to content

kiksy

New Members
  • Posts

    9
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

kiksy's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. ahhhh! Thanks so much! Kicking myself now! Thanks again, hope I can help you some other day.
  2. Hi there, Im guessing im missing something obvious and making this hard for myself.... Running : 5.0.81-community $result = 'Select ID FROM comments HAVING MAX(id) > 1'; $row = mysql_query($result); echo $row['0']; Table structure is ID as primary, then USERNAME , COMMENT, DATE, VALIDATED All im trying to do is select the highest ID and then echo it , Ive searched around and found a few solutions but none seemed to work. All I want is the ID number as a $ . Any help at all appreciated. Thanks in advance.
  3. Thanks, I was jut away entering what you suggested when you put that second post down. It works perfectly with : $stringData = '"; $dbresult = mysql_query("SELECT * FROM PhotoUsers WHERE id = '; fwrite($fh, $stringData); $stringData = '\'$idselect\''; fwrite($fh, $stringData); Thanks for the quick response!
  4. Hi there, Ive searched around , but due to the grammatical style of my problem its been hard to find an answer on Google or here. I am inserting some PHP/MySQL commands into a new .php file using 'fwrite' : $stringData = '"; $dbresult = mysql_query("SELECT * FROM PhotoUsers WHERE id = "'; fwrite($fh, $stringData); $stringData = '$idselect'; fwrite($fh, $stringData); $stringData = '"); When run the resulting .php file contains : $dbresult = mysql_query("SELECT * FROM PhotoUsers WHERE id = "$idselect""); Where as it needs to be : $dbresult = mysql_query("SELECT * FROM PhotoUsers WHERE id = '$idselect'"); with '' instead of "" around $idselect. The issue is that when I put ' around $stringData = '$idselect'; in the first page it closes it. I hope Ive explained my issue clearly, thanks in advance for any help, Im sure its a simple fix!
  5. Ok, so the search from the dropdown has been sort of fixed. Changing the MySQL query so that there were no ANDs in it fixed it. Although that obviously limits my results a bit, I can live with it. The paging though is still an issue . It shows the results on the first page, and then all other pages are blank. Code on search.php now looks like: <? session_start(); require("connection.php"); // pagination if (!(isset($_GET['page']))) { $page = 1; } else { $page = $_GET['page']; } //secect everything from users table if (isset($_POST['search'])) { $s = $_POST['search']; $_SESSION['searchedfor'] = $s; } else { $s = $_SESSION['searchedfor']; } if (isset($_POST['dropdown'])) { $where = $_POST['dropdown']; $_SESSION['searchtype'] = $where; } else { $where = $_SESSION['searchtype']; } $result = mysql_query("SELECT * FROM gallery WHERE title LIKE '%$s%' AND type = '$where' ORDER BY id ASC") or die(mysql_error()); // set limit for number of results on page $rows = mysql_num_rows($result); $num = mysql_num_rows($result); if ($rows > 0) { $limit = 15; $last = ceil($rows/$limit); if($page < 1) { $page =1; } elseif ($page > $last) { $page = $last; } $max = "LIMIT ". ($page -1) * $limit . "," .$limit ; echo "searching for " . $s; echo " - in " . $where; echo $max; // issue here $result = mysql_query("SELECT * FROM gallery WHERE title LIKE '%$s%' AND type = '$where' ORDER BY id ASC $max ") or die(mysql_error()); } ?> and further down <? if (isset($_POST['submit'])) { if ($_POST['search'] != "") { $s = mysql_real_escape_string($_POST['search']); if ($where == "Users") { echo "<h3> you serched for:" . $s . "..</h3>"; echo "<h4> there were " . $num . " results </h4>"; while ($row = mysql_fetch_assoc($result)) { echo "<p> Username: " . $row['username'] . "</p>"; echo "<p> Bio : " . $row['bio'] . " </p>"; echo "<hr />"; } } else if ($where == "Video") { echo "<h3> you serched for:" . $s . "..</h3>"; echo "<h4> there were " . $num . " results </h4>"; while ($row = mysql_fetch_assoc($result)) { echo "<p> Video Name: " . $row['title'] . "</p>"; echo "<p> Made by: " . $row['author'] . " </p>"; echo "<hr />"; } } else if ($where == "Interactive") { echo "<h3> you serched for:" . $s . "..</h3>"; echo "<h4> there were " . $num . " results </h4>"; while ($row = mysql_fetch_assoc($result)) { echo "<p> Interactive Name: " . $row['title'] . "</p>"; echo "<p> Made by: " . $row['author'] . " </p>"; echo "<hr />"; } } else if ($where == "Radio") { echo "<h3> you serched for:" . $s . "..</h3>"; echo "<h4> there were " . $num . " results </h4>"; while ($row = mysql_fetch_assoc($result)) { echo "<p> Radio Name: " . $row['title'] . "</p>"; echo "<p> Made by: " . $row['author'] . " </p>"; echo "<hr />"; } } else if ($where == "Script") { echo "<h3> you serched for:" . $s . "..</h3>"; echo "<h4> there were " . $num . " results </h4>"; while ($row = mysql_fetch_assoc($result)) { echo "<p> Script Name: " . $row['title'] . "</p>"; echo "<p> Made by: " . $row['author'] . " </p>"; echo "<hr />"; } } else if ($where == "All") { echo "<h3> you serched for:" . $s . "..</h3>"; echo "<h4> there were " . $num . " results </h4>"; while ($row = mysql_fetch_assoc($result)) { echo "<p> Name: " . $row['title'] . "</p>"; echo "<p> Made by: " . $row['author'] . " </p>"; echo "<hr />"; } } else { echo "<p> Please type something</p>"; } } } ?> <!-- pagniation start --> <? echo "<p>you re on page " .$page. " of " .$last."</p>"; ?></p> <p> </p> <p></p> <? echo "<p><a href='search.php?page=".($page-1)."'>BACK</a>"; echo " - <a href='search.php?page=".($page+1)."'>FORWARD</a>"; ?> <? mysql_close($connect); ?> Where I have commented '//issue here ' seems to be the problem area. // issue here $result = mysql_query("SELECT * FROM gallery WHERE title LIKE '%$s%' AND type = '$where' ORDER BY id ASC $max ") or die(mysql_error()); Anyone got any ideas? Thanks.
  6. Hello. Not sure if anyones going to be able to help here, im pretty stuck with it and everythings pretty messy. Just started out learning PHP and have been making good progress. Ive been stuck now for a few days with these 2 problems : Firstly, I want to make a Search from a dropdown that then brings up results based on the choice from the dropdown On my first page the code is : <form action="search.php" method="post"/> <input type="text" name="search" /> <select size="1" name="dropdown"> <option value="All" selected>Search All</option> <option value="Users">Users</option> <option value="Video">Videos</option> <option value="Interactive">Interactive</option> <option value="Radio">Radio</option> <option value="Script">Script</option> </select> <input name="submit" type="submit" class="submitcolour" /> </form> This works fine. On my search.php page the code is <? if (isset($_POST['submit'])) { if ($_POST['search'] != "") { $s = mysql_real_escape_string($_POST['search']); // $typequery = "SELECT * FROM gallery WHERE $dropdown='$search'" or die (mysql_error()); //$result = mysql_query($typequery) or die (mysql_error()); // % adds wildcard.... // $where = $_POST['dropdown']; if ($where == "Users") { $searchSQL = "SELECT * FROM users WHERE username LIKE '%$s%' OR bio LIKE '%$s%' OR email LIKE '%$s%' ORDER BY id ASC"; } else if ($where == "All") { $searchSQL = "SELECT * FROM gallery WHERE title LIKE '%$s%' OR author LIKE '%$s%' OR description LIKE '%$s%' "; } else if ($where == "Video") { $searchSQL = "SELECT * FROM gallery WHERE title LIKE '%$s%' OR author LIKE '%$s%' OR description LIKE '%$s%' AND type = 'Video' ORDER BY id ASC"; } else if ($where == "Interactive") { $searchSQL = "SELECT * FROM gallery WHERE title LIKE '%$s%' OR author LIKE '%$s%' OR description LIKE '%$s%' AND type = 'Interactive' ORDER BY id ASC"; } else if ($where == "Radio") { $searchSQL = "SELECT * FROM gallery WHERE title LIKE '%$s%' OR author LIKE '%$s%' OR description LIKE '%$s%' AND type = 'Radio' ORDER BY id ASC"; } else if ($where == "Script") { $searchSQL = "SELECT * FROM gallery WHERE title LIKE '%$s%' OR author LIKE '%$s%' OR description LIKE '%$s%' AND type = 'Script' ORDER BY id ASC"; } $result = mysql_query($searchSQL, $connect) or die(mysql_error()); $num = mysql_num_rows($result); // mysql_close($connect); // echo "<div class=\"user \"; if ($where == "Users") { echo "<h3> you serched for:" . $s . "..</h3>"; echo "<h4> there were " . $num . " results </h4>"; while ($row = mysql_fetch_assoc($result)) { echo "<p> Username: " . $row['username'] . "</p>"; echo "<p> Bio : " . $row['bio'] . " </p>"; echo "<hr />"; } } else if ($where == "Video") { echo "<h3> you serched for:" . $s . "..</h3>"; echo "<h4> there were " . $num . " results </h4>"; while ($row = mysql_fetch_assoc($result)) { echo "<p> Video Name: " . $row['title'] . "</p>"; echo "<p> Made by: " . $row['author'] . " </p>"; echo "<hr />"; } } else if ($where == "Interactive") { echo "<h3> you serched for:" . $s . "..</h3>"; echo "<h4> there were " . $num . " results </h4>"; while ($row = mysql_fetch_assoc($result)) { echo "<p> Interactive Name: " . $row['title'] . "</p>"; echo "<p> Made by: " . $row['author'] . " </p>"; echo "<hr />"; } } else if ($where == "Radio") { echo "<h3> you serched for:" . $s . "..</h3>"; echo "<h4> there were " . $num . " results </h4>"; while ($row = mysql_fetch_assoc($result)) { echo "<p> Radio Name: " . $row['title'] . "</p>"; echo "<p> Made by: " . $row['author'] . " </p>"; echo "<hr />"; } } else if ($where == "Script") { echo "<h3> you serched for:" . $s . "..</h3>"; echo "<h4> there were " . $num . " results </h4>"; while ($row = mysql_fetch_assoc($result)) { echo "<p> Script Name: " . $row['title'] . "</p>"; echo "<p> Made by: " . $row['author'] . " </p>"; echo "<hr />"; } } else if ($where == "All") { echo "<h3> you serched for:" . $s . "..</h3>"; echo "<h4> there were " . $num . " results </h4>"; while ($row = mysql_fetch_assoc($result)) { echo "<p> Name: " . $row['title'] . "</p>"; echo "<p> Made by: " . $row['author'] . " </p>"; echo "<hr />"; } } else { echo "<p> Please type something</p>"; } } } ?> Whatever option you choose , all results are shown from the database with that keyword, not just the ones based on 'type'. So say I have a video called "Video 1" which Type is 'Video' , if I search with "radio" from the dropdown, Video 1 still comes up in the search results. My second problem is with the paging. Ive got this to work fine on other pages , but not the search one . The code for this on search.php is : <? session_start(); require("connection.php"); // pagination if (!(isset($_GET['page']))) { $page = 1; } else { $page = $_GET['page']; } //secect everything from users table $result = mysql_query("SELECT * FROM gallery ORDER BY id ASC"); // set limit for number of results on page $rows = mysql_num_rows($result); $limit = 2; $last = ceil($rows/$limit); if($page < 1) { $page =1; } elseif ($page > $last) { $page = $last; } $max = "LIMIT ". ($page -1) * $limit . "," .$limit ; $result = mysql_query("SELECT * FROM gallery $max ") or die(); ?> and <? echo "<p>you re on page " .$page. " of " .$last."</p>"; ?></p> <p> </p> <p></p> <? echo "<p><a href='search.php?page=".($page-1)."'>BACK</a>"; echo " - <a href='search.php?page=".($page+1)."'>FORWARD</a>"; ?> What happens is that it will show all of the results on one page (even though the limit is set to 2) and then have a number of blank pages afterwards. So say my search has 6 results, all the results will be on the one page instead of 2 ,and I will be on page 1 of 5. The other 4 pages will be blank. There is obviously other code on the pages , ive just posted the bits that I think are causing the problems. If anyone could help in anyway at all I would be most grateful. Even if its just down to helping me lay out my code in a more readable fashion .
  7. WOW! thank you so much! Works perfectly. Thanks too for the comments, I now understand explode and exactly why this works. Security isnt really an issues for this site as it will be running in a pretty closed environment, but thanks for the info, its always good to learn best practices. Once again, thanks so much for your time and knowledge.
  8. Hi thanks for the quick reply. my $filetype works as Ive tested it with an echo at the end and it works. If I upload an image file , then my $filetype is "Image", if I upload a text file then my $filetype is "text". All I need to know is how to get this part of the code to work . if ($error == "" && $imgName != "" && $filetype == "image" ) { $filePath = "uploads/images/".$imgName; move_uploaded_file($imgTmp, $filePath); if ($error == "" && $imgName != "" && $filetype == "text" ) { $filePath = "uploads/text/".$imgName; move_uploaded_file($imgTmp, $filePath); Im pretty new to PHP , and youve completely lost me with your response. If you could elaborate on what you mean by "use explode" that would be great. Thanks again.
  9. Hello, first post , and asking for help im afraid. Very new to PHP, was making good progress I thought , but im stuck with this part. I have a uploading form that works perfectly and uploads everything to "uploads/images" . What Im trying to do is upload .txt or .rtf files to "uploads/text" and .jpg and .gif's to "uploads/images . I thought this wasnt going to be too difficult but im totally stuck and have spent hours trying to solve this. If anyone could help at all and show my what I'm doing wrong, Id be very very grateful! This is the code as it stands. Right now, it ALWAYS goes to "uploadfail.php" and the file does not upload. If I remove all the code relating to filetype then both the text and image files succesully upload and I go to "uploadsucess.php" <? require('connection.php'); //my_sql_real..... makes it safe against mysql injection $title = mysql_real_escape_string($_POST['title']); $date = mysql_real_escape_string($_POST['date']); $author = mysql_real_escape_string($_POST['author']); $description = mysql_real_escape_string($_POST['description']); $type = mysql_real_escape_string($_POST['type']); $imgName = $_FILES['pic']['name']; $imgTmp = $_FILES['pic']['tmp_name']; $imgSize = $_FILES['pic']['size']; $imgType = $_FILES['pic']['type']; $maxFileSize = 200000; if ($imgType == "image/jpeg" || $imgType == "image/gif" || $imgType == "application/rtf" || $imgType == "application/x-rtf" || $imgType == "text/richtext" || $imgType == "text/plain" ) { $error = ""; } else { $error = "type"; } if ($imgType == "image/jpeg" || $imgType == "image/gif" ) { $filetype = "image"; } if ($imgType == "application/rtf" || $imgType == "application/x-rtf" || $imgType == "text/richtext" || $imgType == "text/plain" ) { $filetype = "text"; } else { $filetype = "other"; } if ($imgSize > $maxFileSize) { $error = "size"; } if ($error == "" && $imgName != "" && $filetype == "image" ) { $filePath = "uploads/images/".$imgName; move_uploaded_file($imgTmp, $filePath); if ($error == "" && $imgName != "" && $filetype == "text" ) { $filePath = "uploads/text/".$imgName; move_uploaded_file($imgTmp, $filePath); //another securtiy measure sprintf $query = sprintf("INSERT INTO gallery(title,date,author,type,description,path) VALUES ('%s' , '%s' ,'%s' ,'%s' ,'%s' ,'%s' )", $title,$date,$author,$type,$description,$filePath); if (!mysql_query($query, $connect)) { die(); } else { header("Location: uploadsuccess.php"); } } } else { header("Location: uploadfail.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.