Jump to content

pudge1

Members
  • Posts

    51
  • Joined

  • Last visited

    Never

Everything posted by pudge1

  1. pudge1

    Search System

    I just got tired of it and completely restarted it and now it works. Thanks to all who helped!
  2. <form id="form" action="add_note.php" method="post" enctype="multipart/form-data"> <b>Note Title:</b> <input type="text" name="title" /><br /> <b>Note Keywords:</b> <input type="text" name="keywords" /><br /> <b>Grade Level:</b> <select name="grade_level"><option value="kt5">K-5</option><option value="6">6th Grade</option><option value="7">7th Grade</option><option value="8">8th Grade</option><option value="9">9th Grade</option><option value="10">10th Grade</option><option value="11">11th Grade</option><option value="12">12th Grade</option><option value="College">College</option></select><br /> <b>Subject:</b> <select name="subject"><option>Biography</option><option>Biology</option><option>Chemistry</option><option>Computer Science</option><option>Drama</option><option>Economics</option><option>Film</option><option>Health</option><option>History</option><option>Math</option><option>Philosophy</option><option>Physics</option>Poetry</option><option>Psychology</option>Shakespseare</option><option>Stories</option>Science</option><option>Sociology</option><option>U.S. Government and Politics</option></select><br /><br /> <b>Note File:</b> <input type="file" name="file" id="file" /><br /><small style="color:gray;">(Supported: .txt, .rtf, .doc, .docx)</small><br /><br /> <input type="hidden" name="submitted" value="TRUE" /> <input type="submit" id="submit" value="Add Note!" /> </form> <?php if($_POST['submitted'] == 'TRUE') { } else { include_once('right.php'); exit; } if($account_level == '_GUEST_' || !$account_level || $account_level == '') { echo "<meta http-equiv='refresh' content='0;URL=no_perms.php' />"; exit; } else { } $file_type = $_FILE['file']['tmp_name']; $file_type = explode('.',$file_type); $count = count($file_type); $count = $count-1; $file_type = $file_type[$count]; $file_type = '.' . $file_type; if($file_type != '.doc' || $file_type != '.DOC' || $file_type != '.txt' || $file_type != '.TXT' || $file_type != '.rtf' || $file_type != '.RTF' || $file_type != '.docx' || $file_type != '.DOCX') { echo "<script>alert('Your file type is not supported');</script>"; echo "<meta http-equiv='refresh' content='0;url=index.php' />"; exit; } else { } $rand = rand(10,900); move_uploaded_file($_FILES["file"]["tmp_name"],'tmp/' . $rand . $file_type); $note_contents = file_get_contents('tmp/' . $rand . $file_type); ... I am just trying to do a simple upload script to upload a text file and then get the contents of it. This should be really easy but for some reason $note_contents comes back blank and I just can't figure it out at all. Its really confusing and kind of frustrating. I have no idea why this isn't working at all... The file is not being uploaded and /tmp exists
  3. pudge1

    Search System

    Yes that is correct
  4. pudge1

    Search System

    Fixed that problem. Echoed it (just like the sql query would appear) and copied and pasted into PHPMyAdmin and it worked fine.
  5. pudge1

    Search System

    Thanks I can't believe I didn't notice that. However for some reason I still get the same error.
  6. pudge1

    Search System

    Oops copied the wrong problem sorry. function Search($keyword,$subject,$grade,$search_by) { $user = SQL_User(); $pass = SQL_Pass(); $dbname = SQL_DB(); $connection = mysql_connect('localhost',$user,$pass); mysql_select_db($dbname , $connection); $search_term = mysql_real_escape_string($search_term); $sql = "SELECT * FROM Notes WHERE Keywords LIKE '%$search_term%'"; if($subject == 'NO') { } else { $sql .= " AND Subject='$subject'"; } if($grade == 'NO') { } else { $sql .= " AND Grade='$grade'"; } if($sort_by == 'NO') { } elseif($sort_by == 'RATING') { $sql .= " ORDER BY Rating DESC"; } elseif($sort_by == 'VIEWS') { $sql .= " ORDER BY Views DESC"; } else { } $query = mysql_query($sql , $connection); while($arr = mysql_fetch_array($query)) { $title = file_get_contents('notes/' . $arr['Note_ID'] . '.note'); $title = explode('||TITL_E=',$title); $title = $title[1]; $title2 = explode('=||',$title); $user = SQL_User(); $pass = SQL_Pass(); $dbname = SQL_DB(); $search_term = mysql_real_escape_string($search_term); $connection = mysql_connect('localhost',$user,$pass); mysql_select_db($dbname, $connection); $sql = "SELECT * FROM Notes WHERE Note_ID='$note_id'"; $query = mysql_query($sql , $connection); $query = mysql_fetch_array($query); $title = $query["Title"]; $contents = $title2[1]; $contents2 = wordwrap($contents, 80, ",", true); $contents2 = explode(',',$contents2); $contents2 = $contents2[0]; if($contents2 == $contents) { } else { $contents = $contents . '...'; } $results .= "<a id='search_title' href='view_note.php?id=" . $arr['Note_ID'] . "'>" . $title . "</a><br />"; $results .= "<span id='search_contents'>" . $contents . "</span><br />"; $results .= "<span id='search_author'>" . $arr['Author'] . "</span><br /><br /><br />|*|?|>|"; } return $results; } For some reason I get these errors Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/***/functions.php on line 713 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/***/functions.php on line 713 I've looked over this many times. I even took the SQL Statement ($sql) and put it through the SQL Command on PHPMyAdmin and replaced the variable with what I am using as a keyword and it works just fine. But I can't figure out quite what is wrong. Line 713 Begins with While($arr...
  7. $user = SQL_User(); $pass = SQL_Pass(); $dbname = SQL_DB(); $search_term = mysql_real_escape_string($search_term); $connection = mysql_connect('localhost',$user,$pass); mysql_select_db($dbname, $connection); $sql = "SELECT * FROM Notes WHERE Keywords LIKE '%$search_term%'"; if($subject == 'NO') { } else { $sql .= " AND Subject='$subject'"; } if($grade == 'NO') { } else { $sql .= " AND Grade='$grade'"; } if($sort_by == 'NO') { } elseif($sort_by == 'RATING') { $sql .= " ORDER BY Rating DESC"; } elseif($sort_by == 'VIEWS') { $sql .== " ORDER BY Views DESC"; } else { } $query = mysql_query($sql, $connection); $query = mysql_fetch_array($query); Will query output a multi-dimensional array? If not how does it separate each result?
  8. function Vote($note_id,$rating,$username) { $note_id = mysql_real_escape_string($note_id); $rating = mysql_real_escape_string($rating); $username = mysql_real_escape_string($username); $user_votes = file_get_contents('user/' . $username . '_votes.dat'); $user_votes = explode(',',$user_votes); foreach($user_votes as $user_vote) { if($note_id == $user_vote) { return "False_1"; } else { } } $user = '***'; $pass = '***'; $dbname = '***'; $connection = mysql_connect('localhost',$user,$pass); mysql_select_db($dbname, $connection); $sql = "SELECT Votes FROM Notes WHERE Note_ID='$note_id'"; $query = mysql_query($sql , $connection); $query2 = mysql_fetch_array($query); $query = $query2["Votes"]; $query++; $sql = "UPDATE Notes SET Votes='$query' WHERE Note_ID='$note_id'"; $query = mysql_query($sql , $connection); $sql = "SELECT * FROM Notes WHERE Note_ID='$note_id'"; $query = mysql_query($sql , $connection); $query2 = mysql_fetch_array($query); $query = $query2["Total Rating"]; $query = $query+$rating; $sql = "UPDATE Notes SET Total Rating='$query' WHERE Note_ID='$note_id'"; $query = mysql_query($sql , $connection); $file = fopen('user/' . $username . '_votes.dat','a'); fwrite($file,$note_id . ','); fclose($file); } With the username I am using (user/pudge_votes.dat) the file is completely empty but for some reason it keeps returning False_1. I have no idea why it is doing this. Here is the page that the function is being used on. Also the database isn't updating like it should. It should get Votes from the table Notes where Note_ID=$note_id and increase its value by one and then update the vote count. Then it should get Total Rating from Notes where Note_ID=$note_id and add $rating to that value and then update the new value but neither of those are working either. $vote = Vote($_POST['id'],$_POST['rating'],Get_Username()); if($vote == 'False_1') { echo '<script>alert("You have already voted on this note. You may only vote once.' . $vote . '");</script>'; echo '<meta http-equiv="refresh" content="0;URL=view_note.php?id=' . $_POST['id'] . '" />'; exit; } else { echo '<script>alert("You have successfully voted on this note! Thank you for your contribution!");</script>'; echo '<meta http-equiv="refresh" content="0;URL=view_note.php?id=' . $_POST['id'] . '" />'; exit; }
  9. Yeah I even compared the md5s of the data that was being put into LogIn() and they matched up exactly in the database.
  10. Password shows up what it should but $a_password is empty. Sorry I forgot to mention that.
  11. For some reason my LogIn script doesn't work. It connects to the database and everything alright but it doesn't work at all. I've checked the database multiple time and the information I am inputting IS in there. function Login($username,$password) { $user = '***'; $pass = '***'; $dbname = '***'; $connection = mysql_connect('localhost',$user,$pass); mysql_select_db($dbname, $connection); $sql = "SELECT Password FROM Users WHERE Username='$username'"; $query = mysql_query($sql , $connection); $arr = mysql_fetch_array($query); $a_password = $arr["Password"]; if($password == $a_password) { setcookie('LOGGED_IN','True_',time()+172800); setcookie('USERNAME',$username,time()+172800); } else { } } That is the function here it is in use: $username = mysql_real_escape_string( $_POST['username'] ); $password = mysql_real_escape_string( $_POST['password'] ); $username = strtolower($username); $password = strtolower($password); $username = md5($username); $password = md5($password); Login($username,$password);
  12. So I am creating a sign up script and part of the script has a function that checks if a username exists but everytime I try it, it shows that the username is already in use when it isn't... the database is empty. function Check_Username($username) { $user = 'nintendo_note'; $pass = 'zeno118'; $dbname = 'nintendo_note'; $connection = mysql_connect('localhost',$user,$pass); mysql_select_db($dbname, $connection); $query="select Username from Users"; $result=mysql_query($query); while($row=mysql_fetch_array($result)) { if($username == $row['Username']) { return False; } else { } } } and the actual use: if(!Check_Username(md5($_POST['username']))) { echo "Sorry username is already taken. Please choose another."; include_once('right.php'); exit; } I tried changing a lot of things and moving things around but nothing seems to work. I have also gone over the code many times. The e-mail section is coded the exact same way but for some reason it always thinks the e-mail is never taken.
  13. Thank you so much exactly what I wanted.
  14. That is what I meant to ask. How do I display them?
  15. function Search($search_term) { $user = '***'; $pass = '***'; $dbname = '***'; $search_term = mysql_real_escape_string($search_term); $connection = mysql_connect('localhost',$user,$pass); mysql_select_db($dbname, $connection); $sql = "SELECT Note_ID FROM Notes WHERE Keywords LIKE '%$keywords%'" $query = mysql_query($sql, $connection); } So I am kinda new to MySQL so I don't know it that well, how will the results of this search be displayed? Thank you so much if you help
  16. Try making a form with hidden inputs. Like: <form> <input type="hidden" name="var1" value="<? echo $_POST['var1']; ?>" /> ...etc. </form>
  17. <?php /* * File: SimpleImage.php * Author: Simon Jarvis * Copyright: 2006 Simon Jarvis * Date: 08/11/06 * Link: http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details: * http://www.gnu.org/licenses/gpl.html * */ class SimpleImage { var $image; var $image_type; function load($filename) { $image_info = getimagesize($filename); $this->image_type = $image_info[2]; if( $this->image_type == IMAGETYPE_JPEG ) { $this->image = imagecreatefromjpeg($filename); } elseif( $this->image_type == IMAGETYPE_GIF ) { $this->image = imagecreatefromgif($filename); } elseif( $this->image_type == IMAGETYPE_PNG ) { $this->image = imagecreatefrompng($filename); } } function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) { if( $image_type == IMAGETYPE_JPEG ) { imagejpeg($this->image,$filename,$compression); } elseif( $image_type == IMAGETYPE_GIF ) { imagegif($this->image,$filename); } elseif( $image_type == IMAGETYPE_PNG ) { imagepng($this->image,$filename); } if( $permissions != null) { chmod($filename,$permissions); } } function output($image_type=IMAGETYPE_JPEG) { if( $image_type == IMAGETYPE_JPEG ) { imagejpeg($this->image); } elseif( $image_type == IMAGETYPE_GIF ) { imagegif($this->image); } elseif( $image_type == IMAGETYPE_PNG ) { imagepng($this->image); } } function getWidth() { return imagesx($this->image); } function getHeight() { return imagesy($this->image); } function resizeToHeight($height) { $ratio = $height / $this->getHeight(); $width = $this->getWidth() * $ratio; $this->resize($width,$height); } function resizeToWidth($width) { $ratio = $width / $this->getWidth(); $height = $this->getheight() * $ratio; $this->resize($width,$height); } function scale($scale) { $width = $this->getWidth() * $scale/100; $height = $this->getheight() * $scale/100; $this->resize($width,$height); } function resize($width,$height) { $new_image = imagecreatetruecolor($width, $height); imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight()); $this->image = $new_image; } } ?> This is the code I used on my old image hosting site. I did not create it, found it online.
  18. $vault_id = $_POST['id']; $vault_combo = $_POST['c1'] . '-' . $_POST['c2'] . '-' . $_POST['c3']; $open_vault = open_vault($vault_id,$vault_combo); if($open_vault == 'FALSE') { echo '<font color="red">Invalid Vault ID/Combo</font>'; } else { echo $open_vault; } So I set that as a function and used it in the code above. However it doesn't ECHO anything. Which is weird because in all the ifelse statements either ECHOS FALSE or something else. So I am guessing there is some kind of script error somewhere. Thanks a lot though for writing that up for me.
  19. $connection = mysql_connect('localhost',$user,$pass); mysql_select_db($dbname, $connection); $vault_id = mysql_real_escape_string( $vault_id ); $combo = mysql_real_escape_string( $combo ); $var = "SELECT * FROM Vaults WHERE Vault_ID='". $vault_id . "'"; $result = mysql_query($var , $connection); while($row = mysql_fetch_array($result)) { if($row['Vault_ID'] == $vault_id && $row['Combo'] == $combo) { $var = "SELECT Contents FROM Vaults WHERE Vault_ID='". $vault_id . "'"; $return = mysql_query($var , $connection); return $return; } else { return 'FALSE'; } } What I am trying to do is find out if the variable $vault_id and $combo correspondingly match up with two columns Vault_ID and Combo both in the same row. If not it returns false. Otherwise it gets the value of the contents column in that same row. For example: Vault_ID | Combo | Contents ---------------------------------- 01234 01-01-01 Vault Contents 12345 02-02-02 More Contents If my $vault_id == '01234' and $combo == '01-01-01' then it would return "Vault Contents" or if $vault_id == '12345' and $combo == '02-02-02' it would return "More Contents" otherwise it returns false. However it doesn't do this at all. It doesn't return a MySQL error but my host is weird about PHP/MySQL errors so there may be one I am not sure. Do you guys see an error or a mistake I made in syntax. Thanks for at least reading this and attempting to help me.
  20. Thanks man, for fixing the code and for the tip. I'll use both.
  21. Warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@email.com,User)' at line 3 in That is the error I get. Thanks for whoever posted the new code, still broken though. I just don't see what is wrong I have looked it over a couple times and referred back to the manual.
  22. Thanks man, still doesn't work though
  23. $sql="INSERT INTO Users (userid, Username, Password, EMail, Account Type) VALUES (" . $count . "," . $username . "," . $password . "," . $_POST['email'] . "," . $at . ")"; $result = mysql_query($sql , $connection); The problem I am having with the script is that it is not inserting the data. I am 99.99% sure that is the fault of the way I wrote up the $sql= line. Does anyone see what I did wrong? EDIT: I forgot to mention. It IS connecting to the database just fine so that is NOT the problem.
×
×
  • 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.