Jump to content

Smudly

Members
  • Posts

    148
  • Joined

  • Last visited

    Never

Everything posted by Smudly

  1. I have a search engine that searches through my sql table called `sheets`. Inside this table are the following columns: id int(11) No artist varchar(100) No title varchar(100) No url varchar(2083) No timesdownloaded int(11) No lastdownloaded date No todaydownloads int(11) No date date No active varchar(3) No duplicate int(1) My search script searches for matches inside the Artist or Title columns. However there is one problem. Let's say I have 5 records (I will show the first three columns): ID .. Artist .. Title 1 .. ABBA .. Super Trouper 2 .. Super Castlevania .. First Stage 3 .. Super Mario Brothers .. Underwater 4 .. Mario .. Theme 5 .. Super Junior .. Sorry, Sorry So if I search for "Super Mario", right now it is displaying the following results (So right now it is searching phrases, rather than single words): 3 .. Super Mario Brothers .. Underwater However, I need to modify my code so it will display the following results: 1 .. ABBA .. Super Trouper 2 .. Super Castlevania .. First Stage 3 .. Super Mario Brothers .. Underwater 4 .. Mario .. Theme 5 .. Super Junior .. Sorry, Sorry Here is my full code, and any suggestions appreciated. I'll be working on it. <?php session_start(); include_once('inc/connect.php'); if (isset($_SESSION['username'])){ $loginstatus = "logout"; } else{ $loginstatus = "login"; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta name="description" content="Free Piano Sheet Music - Sheet Music Haven"> <meta name="keywords" content="free,piano,sheet,music,download,keyboard,haven,lyrics,notes,chords,score,top,modern,popular,jazz,classical,sheetmusichaven"> <meta name="author" content="Sheet Music Haven - Free Piano Sheet Music. Download all types of piano sheet music for free. Popular sheets are added often"> <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"> <title>Search - Sheet Music Haven</title> <link rel="stylesheet" type="text/css" href="styles/style.css"> <script type="text/javascript"> function make_blank() { if(document.login.username.value =="Username"){ document.login.username.value =""; document.login.username.style.color ="#000000"; } } function make_blank1() { if(document.login.password.value =="Password"){ document.login.password.value =""; document.login.password.type ="password"; document.login.password.style.color ="#000000"; } } function undoBlank() { if(document.login.username.value == ""){ document.login.username.value ="Username"; document.login.username.style.color="#ccc"; } } function undoBlankpass() { if(document.login.password.value == ""){ document.login.password.value ="Username"; document.login.password.style.color="#dddddd"; } } </script> </head> <body bgcolor="#343331" OnLoad="document.form.q.focus();"> <?php include('inc/reporterrors.php'); ?> <!-- Header --> <div id="header"> <div id="headerleft"> <div style="position: relative; top: 30px; width: 165px; margin-left: auto; margin-right: auto; text-align: center;"> <form name="form1" action="search.php" method="get"> <div style="float: left;" class="searchboxdiv"><input type="text" name="q" class="searchbox" /></div> <div style="float: right;"><input type="image" src="img/search.png" alt="Search" name="Submit" value="Search" /></div> </form> </div> </div> <div id="headermiddle"><a href="index.php"><img src="img/logo.png"></a></div> <div id="headerright"> <?php echo "<form name='login' action='inc/$loginstatus.php' method='POST'>";?> <div class="loginboxdiv" id="username"> <input type="text" class="loginbox" name="username" value="Username" onFocus="make_blank();" onBlur="undoBlank();"> </div> <div class="loginboxdiv" id="password"> <input class="loginbox" type="text" name="password" type="text" value="Password" onFocus="make_blank1();" onBlur="undoBlankpass();"> </div> <div id="login"> <?php echo "<input type='image' src='img/$loginstatus.png' alt='".ucfirst($loginstatus)."'>";?> </div> </form> <div id="register"> <a href="register.php"><img src="img/register.png"></a> </div> <div id="forgotpassword"> <a href="resetpassword.php" class="forgot">Forgot Password?</a> </div> </div> </div> <!-- Content Top --> <div id="contenttop"> <div id="links"> <table cols="7"> <tr> <td align="center" valign="middle" width="100px" height="48px"><a href="index.php"><img src="img/home.png"></a></td> <td align="center" valign="middle" width="100px" height="48px"><a href="member.php"><img src="img/member.png"></a></td> <td align="center" valign="middle" width="100px" height="48px"><a href="addsheet.php"><img src="img/addsheet.png"></a></td> <td align="center" valign="middle" width="100px" height="48px"><a href="advertise.php"><img src="img/advertise1.png"></a></td> <td align="center" valign="middle" width="100px" height="48px"><a href="faq.php"><img src="img/faq.png"></a></td> <td align="center" valign="middle" width="100px" height="48px"><a href="terms.php"><img src="img/terms.png"></a></td> <td align="center" valign="middle" width="100px" height="48px"><a href="contact.php"><img src="img/contact.png"></a></td> </tr> </table> <!-- 92x30 --> </div> </div> <!-- Content Middle --> <div id="contentmiddle"> <div id="content"> <?php include_once('inc/functions.php'); // Get the search variable from URL $var = @mysql_safe($_GET['q']) ; $trimmed = trim($var); //trim whitespace from the stored variable // rows to return $limit=10000; $date = date("Y-m-d"); $ip = $_SERVER['REMOTE_ADDR']; // check for an empty string and display a message. if ($trimmed == "") { $error = "<tr><td colspan='2' style='text-align: center; border-style: solid; border-color: #f43636; background-color: #fe6a6a;'><strong>Type In A Sheet To Search For</strong></td></tr>"; } // check for a search parameter if (!isset($var)) { $error = "<tr><td colspan='2' style='text-align: center; border-style: solid; border-color: #f43636; background-color: #fe6a6a;'><strong>Type In A Sheet To Search For</strong></td></tr>"; } // Build SQL Query $query = "select * from `sheets` where `active`='yes' AND (artist like \"%$trimmed%\" OR title like \"%$trimmed%\") ORDER BY `artist`"; $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); if ($numrows == 0 || $var=="delete" || $var=="DELETE") { // If search was not found $error = "<tr><td colspan='2' style='text-align: center; border-style: solid; border-color: #f43636; background-color: #fe6a6a;'><strong>Unfortunately that sheet was not found. Please request it by clicking below:</strong></td></tr><tr><td colspan='2' style='text-align: center; border-left-style: solid; border-bottom-style: solid; border-right-style: solid; border-color: #f43636; background-color: #fe6a6a;'>Tip: Keep your search phrase short and simple for best results!</td></tr><tr><td colspan='2' style='text-align: center; border-left-style: solid; border-bottom-style: solid; border-right-style: solid; border-color: #f43636; background-color: #f5f5f5;'><a href='request.php'>Request A Sheet Here</a></td></tr>"; // Insert search phrase ($var) into 'Search' table. id, phrase, date, resultsfound $word = explode(" ", $var); $num = 0; foreach($word as $key=>$value){ $wordexist = mysql_query("SELECT word FROM searchedwords WHERE word='$word[$num]'"); $wordcount = mysql_num_rows($wordexist); if($wordcount!=0){ //UPDATE $wordget = mysql_query("SELECT * FROM searchedwords WHERE word='$word[$num]'"); $wordrow = mysql_fetch_assoc($wordget); $todayword = $wordrow['today']; $totalword = $wordrow['total']; $newtoday = $todayword+1; $newtotal = $totalword+1; $updateword = "UPDATE `searchedwords` SET `today`='$newtoday', `total`='$newtotal' WHERE `word`='$word[$num]'"; mysql_query($updateword); $num++; } else{ $addone = 1; $wordinsert = mysql_query("INSERT INTO searchedwords VALUES ('','$word[$num]','$addone','$addone')"); $num++; } } $searchphrase = mysql_query("INSERT INTO search VALUES ('','$var','$date','no','$ip')"); if($var!=""){ $search = "Search:"; $break = ""; } } else{ // next determine if s has been passed to script, if not use 0 if (empty($s)) { $s=0; } // get results $query .= " limit $s, $limit"; $result = mysql_query($query) or die("Couldn't execute query"); $search = " "; $break = "<br>"; if($var!=""){ $search = "Search:"; $break = ""; // Insert search phrase ($var) into 'Search' table. id, phrase, date, resultsfound $word = explode(" ", $var); $num = 0; foreach($word as $key=>$value){ $wordexist = mysql_query("SELECT word FROM searchedwords WHERE word='$word[$num]'"); $wordcount = mysql_num_rows($wordexist); if($wordcount!=0){ //UPDATE $wordget = mysql_query("SELECT * FROM searchedwords WHERE word='$word[$num]'"); $wordrow = mysql_fetch_assoc($wordget); $todayword = $wordrow['today']; $totalword = $wordrow['total']; $newtoday = $todayword+1; $newtotal = $totalword+1; $updateword = "UPDATE `searchedwords` SET `today`='$newtoday', `total`='$newtotal' WHERE `word`='$word[$num]'"; mysql_query($updateword); $num++; } else{ $addone = 1; $wordinsert = mysql_query("INSERT INTO searchedwords VALUES ('','$word[$num]','$addone','$addone')"); $num++; } } $searchphrase = mysql_query("INSERT INTO search VALUES ('','$var','$date','yes','$ip')"); } } ?> <br><div id='headsearch'></div> <div style='position: relative; float: left; left: 540px;'><?php if($error==""){echo $numrows." Results";} ?></div> <div style="width: 220px; margin-left: auto; margin-right: auto; text-align: center;"> <form name="form" action="search.php" method="get"> <div style="float: left;"><input type="text" name="q" /></div> <div style="float: right;"><input type="image" src="img/search.png" alt="Search" name="Submit" value="Search" /></div> </form> </div> <?php // display what the person searched for echo "<center><div style='min-width: 210px; margin-left: auto; margin-right: auto; text-align: center;'>$search <span style='color: #6aa504; margin-left; auto; margin-right: auto;'>" . stripslashes($var) . "</span></div></center>"; ?> <?php // begin to show results set $count = 1 + $s ; $greenboxleft = "greenboxleft"; $greenboxright = "greenboxright"; $grayboxleft = "grayboxleft"; $grayboxright = "grayboxright"; $colorvalue = 0; echo "$break<table width='700px' align='center' style='border-collapse:separate; border-spacing:0px;'><th style='background-color: #93DB70; border-bottom-style: solid; border-color: #6aa504;'>Artist</th><th style='background-color: #93DB70; border-bottom-style: solid; border-color: #6aa504;'>Title</th>"; if($error==""){ // now you can display the results returned while ($row= mysql_fetch_array($result)) { $artist = $row["artist"]; $title = $row["title"]; if($artist!="DELETE"){ if(($colorvalue%2)==0){ $styleleft = $greenboxleft; $styleright = $greenboxright; } else{ $styleleft = $grayboxleft; $styleright = $grayboxright; } echo "<tr>"; echo "<td align='center' width='350px' id='$styleleft'><div id='songsboxleft'><strong>". ucwords($row['artist']). "</strong></div></td>"; echo "<td align='center' width='350px' id='$styleright'><div id='songsboxright'><a target='_blank' name='downloadclick' href='download.php?sheet=".$row['url']."&artist=".$row['artist']."&title=".$row['title']."'>" .ucwords($row['title']). "</a></div></td>"; echo "</tr>"; $colorvalue++; } } } else{ echo $error; } echo "</table>"; ?> </div> </div> </div> <!-- Content Bottom --> <div id="contentbottom"> </div> </body> </html> Full Code:
  2. Thanks for the tip. I forgot to mention the uploader also allows .doc or .docx files When echoing the type of file this is, it displays: application/vnd.openxmlformats-officedocument.wordprocessingml.document Does this sound right? If so, I'll just include this as well in the code you provided: ($type == "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
  3. My uploader allows the following file formats: jpg pdf gif png I tested that if someone was to name a file configure.php.jpg, my uploader allows it to upload I want to do a check to see if the user has 2 extensions, and if so it will not allow them to upload. I was thinking of just checking if the file name has two "." (dots) in the name. What function could I use to do this? Or .. is there a better way?
  4. Hey It turns out the locations that I had typed for my css files and images were not absolute. They were: styles/style.css And they should have been www.mysite.com/styles/style.css All fixed Thanks!
  5. Hi, I have created a missing.php file which the user is redirected to if the page they are trying to access does not exist. I use GoDaddy as a host and I set up the 404 error section so it redirects correctly. It works if the user tries to go to www.mysite.com/fakefile.html This would redirect the user to missing.php However, if they go down a directory, things start to get funky. Example: www.mysite.com/directory/fakefile.html This redirects to the missing.php, but any styling it had before is nowhere to be seen. Test for yourself at my site if you want to see exactly what is happening. www.sheetmusichaven.com My missing.php is in my Root Directory. I tried making a duplicate and placing it in the sub folders and places ../ on any images, css files, etc.
  6. How can I call a PHP Function inside a Javascript Function? This is what I have so far, but I don't think I'm doing it the right way. Any suggestions? <?php function phpQuery(){ $query = mysql_query("INSERT INTO mytable VALUES('','name','email')"); } ?> <script type="text/javascript"> function delayQueries() { timeoutID = window.setTimeout(doQueries, 2000); } function doQueries() { var runQuery = "<?php phpQuery(); ?>"; } </script>
  7. Hi, I have some queries that update some statistics in a table I have. I need these queries to run only after 15 seconds have passed however. This way if the user leaves before the 15 seconds, the queries won't run. I've tried using Sleep, however it seems to just stop all the code all together for the allotted time. There must be a way to do this.
  8. Alright thanks for the tips guys. I fixed all the errors by using w3 validator. Still having the same issues. Will see what I can do with the code you provided. Any more feedback appreciated
  9. Hi, I am having some major issues. My site provides sheet music available for downloading for free. When a user clicks on a sheet to download, a new window opens up. This user views our sponsor's website for 30 seconds. Once the time is up, they can download the free sheet. Now for the issues: I found a download script that I'm putting to the test. When clicking download, it asks where you want to save the file and downloads the file just fine. After some testing, i found that if the user tries to download the sheet again, my entire php/html code displays on the page, as well as a bunch of nonreadable characters (I'm guessing this is from the .pdf file that is supposed to be downloaded). I need to modify my code to stop this from happening. I've tried to exit() the code or die() after the sheet downloads, but I must be doing it wrong because nothing seems to work. I also tried a redirect to send them to a different page once they download the file. That doesn't work either. The next issue is the bottom page is supposed to display our sponsor's website, which it does. However, the frame that contains the website is not 100% in height as it is specified to be. Something in my code is causing it to stop extending all the way. If you would like to see exactly what is happening for yourself, you can go here: http://www.sheetmusichaven.com/download.php?sheet=98%20Degrees-I%20Do%20Cherish%20You-SheetMusicHaven.pdf&artist=98%20Degrees&title=I%20Do%20Cherish%20You I'm using the latest version of Firefox, PHP 5. And for the code. I warn you it is ugly >< <?php session_start(); include_once('inc/connect.php'); $sheet = $_GET['sheet']; $artist = stripslashes($_GET['artist']); $title = stripslashes($_GET['title']); $hyphen = " - "; $url = "http://www.youtube.com"; $timetodownload = $_POST['timetodownload']; $todayquery = mysql_query("SELECT `todayviews` FROM `websites` WHERE `active`='yes'"); $todayresult = mysql_fetch_assoc($todayquery); $todayviews = $todayresult['todayviews']; $result = mysql_query("SELECT `url` FROM `websites` WHERE `active`='yes' && `dailyviews`>'$todayviews' && `credits`>0"); $i = 0; while($row = mysql_fetch_array($result)) { while($i<1){ $url = $row['url']; $i++; } } if(strlen($artist)+strlen($title)>80){ $artist = ""; $hyphen = ""; } $ip = $_SERVER['REMOTE_ADDR']; // Time Goes Here // $ipcheck = mysql_query("SELECT ip FROM downloading WHERE ip='$ip'"); // $ipcount = mysql_num_rows($ipcheck); // if ($ipcount!=0) // { // $error1 = "<div id='regerror'>Username already taken!</div>"; // } // $ipquery = "INSERT INTO downloading VALUES ('','$ip','$time')"; // mysql_query($ipquery); $timesdownloaded = 0; if(isset($timetodownload)&&$timesdownloaded<1){ ############################################################### # File Download 1.31 ############################################################### # Visit http://www.zubrag.com/scripts/ for updates ############################################################### # Sample call: # download.php?f=phptutorial.zip # # Sample call (browser will try to save with new file name): # download.php?f=phptutorial.zip&fc=php123tutorial.zip ############################################################### // Allow direct file download (hotlinking)? // Empty - allow hotlinking // If set to nonempty value (Example: example.com) will only allow downloads when referrer contains this text define('ALLOWED_REFERRER', ''); // Download folder, i.e. folder where you keep all files for download. // MUST end with slash (i.e. "/" ) define('BASE_DIR','admin/uploads/'); // log downloads? true/false define('LOG_DOWNLOADS',true); // log file name define('LOG_FILE','downloads.log'); // Allowed extensions list in format 'extension' => 'mime type' // If myme type is set to empty string then script will try to detect mime type // itself, which would only work if you have Mimetype or Fileinfo extensions // installed on server. $allowed_ext = array ( // archives 'zip' => 'application/zip', // documents 'pdf' => 'application/pdf', 'doc' => 'application/msword', // images 'gif' => 'image/gif', 'png' => 'image/png', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', ); #################################################################### ### DO NOT CHANGE BELOW #################################################################### // If hotlinking not allowed then make hackers think there are some server problems if (ALLOWED_REFERRER !== '' && (!isset($_SERVER['HTTP_REFERER']) || strpos(strtoupper($_SERVER['HTTP_REFERER']),strtoupper(ALLOWED_REFERRER)) === false) ) { die("Internal server error. Please contact system administrator."); } // Make sure program execution doesn't time out // Set maximum script execution time in seconds (0 means no limit) set_time_limit(0); if (!isset($sheet) || empty($sheet)) { die("Please specify file name for download."); } // Nullbyte hack fix if (strpos($sheet, "\0") !== FALSE) die(''); // Get real file name. // Remove any path info to avoid hacking by adding relative path, etc. $fname = basename($sheet); // Check if the file exists // Check in subfolders too function find_file ($dirname, $fname, &$file_path) { $dir = opendir($dirname); while ($file = readdir($dir)) { if (empty($file_path) && $file != '.' && $file != '..') { if (is_dir($dirname.'/'.$file)) { find_file($dirname.'/'.$file, $fname, $file_path); } else { if (file_exists($dirname.'/'.$fname)) { $file_path = $dirname.'/'.$fname; return; } } } } } // find_file // get full file path (including subfolders) $file_path = ''; find_file(BASE_DIR, $fname, $file_path); if (!is_file($file_path)) { die("File does not exist. Make sure you specified correct file name."); } // file size in bytes $fsize = filesize($file_path); // file extension $fext = strtolower(substr(strrchr($fname,"."),1)); // check if allowed extension if (!array_key_exists($fext, $allowed_ext)) { die("Not allowed file type."); } // get mime type if ($allowed_ext[$fext] == '') { $mtype = ''; // mime type is not set, get from server settings if (function_exists('mime_content_type')) { $mtype = mime_content_type($file_path); } else if (function_exists('finfo_file')) { $finfo = finfo_open(FILEINFO_MIME); // return mime type $mtype = finfo_file($finfo, $file_path); finfo_close($finfo); } if ($mtype == '') { $mtype = "application/force-download"; } } else { // get mime type defined by admin $mtype = $allowed_ext[$fext]; } // Browser will try to save file with this filename, regardless original filename. // You can override it if needed. if (!isset($_GET['fc']) || empty($_GET['fc'])) { $asfname = $fname; } else { // remove some bad chars $asfname = str_replace(array('"',"'",'\\','/'), '', $_GET['fc']); if ($asfname === '') $asfname = 'NoName'; } // set headers header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Type: $mtype"); header("Content-Disposition: attachment; filename=\"$asfname\""); header("Content-Transfer-Encoding: binary"); header("Content-Length: " . $fsize); // download // @readfile($file_path); $file = @fopen($file_path,"rb"); if ($file) { while(!feof($file)) { print(fread($file, 1024*); flush(); if (connection_status()!=0) { @fclose($file); die(); } } @fclose($file); } // log downloads if (!LOG_DOWNLOADS) die(); $f = @fopen(LOG_FILE, 'a+'); if ($f) { @fputs($f, date("m.d.Y g:ia")." ".$_SERVER['REMOTE_ADDR']." ".$fname."\n"); @fclose($f); } $timesdownloaded++; if(isset($timetodownload)==($_POST['timetodownload'])){ $timetodownload = ""; echo "<meta http-equiv=\"refresh\" content=\"0;url=index.php?letter=0\">"; } if($timesdownloaded>0){ header("Location: index.php"); } } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="description" content="Free Piano Sheet Music - Sheet Music Haven" /> <meta name="keywords" content="free,piano,sheet,music,download,keyboard,haven,lyrics,notes,chords,score,top,modern,popular,jazz,classical,sheetmusichaven" /> <meta name="author" content="Sheet Music Haven - Free Piano Sheet Music. Download all types of piano sheet music for free. Popular sheets are added often" /> <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1" /> <title>Downloading <?php echo $sheet; ?> - Sheet Music Haven</title> <link rel="stylesheet" type="text/css" href="styles/style.css" /> <style> iframe { padding: 0px; spacing: 0px; } body{ margin: 0px; color: #000000; } #bggreen{ width: 99%; height: 88%; background-color: #6aa504; margin-left: auto; margin-right: auto; text-align: center; } #countdown{ color: #4296ce; font-size: 18px; } .sheetbar a{color: #000000; font-family: "Arial", Helvetica, sans-serif; } #logo{ position: relative; width: 320px; height: 65px; text-align: center; float: left; top: 19px; } #timer{ position: relative; width: 65%; height: 59px; float: left; text-align: center; top: 3px; background-color: #ececec; border-style: solid; border-color: #93DB70; } </style> <script type="text/javascript"> var time = 2; function startCountdown(){ var t = setTimeout("countdown()", 1000); } function countdown(){ var sHeet = "<?php echo $sheet;?>"; var artist = "<?php echo $artist;?>"; var tItle = "<?php echo $title;?>"; --time; if(time == 0){ document.getElementById("countdown").innerHTML = "<form action='download.php?sheet=<?php echo $sheet; ?>' method='POST'><input type='image' src='img/download.png' alt='Download' name='timetodownload' value='Download'><\/form>"; }else{ document.getElementById("countdown").innerHTML = time; var t = setTimeout('countdown()', 1000); } } </script> </head> <body onload="startCountdown();" bgcolor="#343331"> <table width="100%" height="100%" cellspacing="0" cellpadding="0" border="0"> <?php echo "<tr><td style='background:#343331;height:80px;border-bottom:#aaaaaa solid 2px;'>"; echo "<div id='bggreen' class='sheetbar'> <div id='logo'><a href='index.php'><img src='img/logosmall.png'></a><br /> <a href='suggestions.php' style='color: #ececec; font-size: 14px;'>Report Errors</a></div> <div id='timer'> It is our sponsor's that keep this website running. Please view their website while you wait for:<br /> <span style='color: #6aa504;'>".ucwords($artist).$hyphen.ucwords($title)."</span> <br /> <div id='countdown'>2</div> </div> </div>".$error; echo "</td></tr>"; ?> <tr><td> <iframe src="<?php echo $url;?>" width="100%" height="100%" frameborder="0" marginwidth="0" marginheight="0"> <p>Your browser does not support iframes.</p> </iframe> </td></tr> </table> </body> </html>
  10. Thanks for all the ideas guys. I ended up creating an additional table which captures all words separately. I can then increment each one of these rows when the word comes up in the search. This seems to be the best way for me. If anyone is interested, here is the code I used. Maybe it could help you in the future: $word = explode(" ", $var); $num = 0; foreach($word as $key=>$value){ $wordexist = mysql_query("SELECT word FROM searchedwords WHERE word='$word[$num]'"); $wordcount = mysql_num_rows($wordexist); if($wordcount!=0){ //UPDATE $wordget = mysql_query("SELECT * FROM searchedwords WHERE word='$word[$num]'"); $wordrow = mysql_fetch_assoc($wordget); $todayword = $wordrow['today']; $totalword = $wordrow['total']; $newtoday = $todayword+1; $newtotal = $totalword+1; $updateword = "UPDATE `searchedwords` SET `today`='$newtoday', `total`='$newtotal' WHERE `word`='$word[$num]'"; mysql_query($updateword); $num++; } else{ $addone = 1; $wordinsert = mysql_query("INSERT INTO searchedwords VALUES ('','$word[$num]','$addone','$addone')"); $num++; } } So when somebody types in "Php Freaks Is Cool", it checks if the word is in the searchedwords table. If it is, it just increments the `today` field as well as the `total` field. Then I have a cron job that resets the today fields every day at midnight. Capturing this information on an admin page is also very simple. You just use something like: // This query ignores the words in the parenthesis (the, and, or, a) etc. $result1 = mysql_query("SELECT * FROM searchedwords WHERE word NOT IN ('the', 'and', 'or', 'a', 'in', 'of', 'to', 'for', 'is', 'we', 'are', 'that', 'have', 'been') ORDER BY today DESC"); while($row1 = mysql_fetch_array($result1)){ if(($i%2)==0){ $bgcolor = "#f5f5f5"; } else{ $bgcolor = "#ccddff"; } echo "<tr>"; echo "<td align='center' valign='top' width='50px' bgcolor='$bgcolor'>" .$row1['id']. "</td>"; echo "<td align='center' valign='top' width='250px' bgcolor='$bgcolor'>" .$row1['word']. "</td>"; echo "<td align='center' width='100px' bgcolor='$bgcolor'>".$row1['today']."</td>"; echo "<td align='center' width='100px' bgcolor='$bgcolor'><span style='color: $rescolor;'>".$row1['total']."</span></td>"; echo "</tr>"; $i++; }
  11. Hey, I have a search feature that searches for words in my database. I am currently storing all searches that users make in a table called `search`. I need to list the top 10 words that are searched for the most, excluding common words like "the, and, or, etc". Because the searches users make are stored into a table, it should be fairly easy. Could anyone give an example of how to do this? Here's how my sql table looks: table name: search columns: id (autoincrement) phrase date resultsfound ip
  12. Alright, that may contradict with the queries I already have going. How would I modify this? $result = mysql_query("SELECT * FROM sheets WHERE artist REGEXP '^[$mysortletter]' && active='yes' && title!='' ORDER BY artist $sortcount");
  13. Hey, I am grabbing a date from a row in my table which is currently formatted as: date("Y-m-d") 2010-09-29 So in my code I have something like this: $row['date']; How do I use this to rearrange the date to look like: 09-29-2010 I looked at the formatting tutorials, but they explain how to format it for the date you are currently setting into a variable.
  14. I am displaying rows from a database onto a page using: while($row=mysql_fetch_array($query)){ echo $row['name']; } I need to figure out how to limit the rows shown to the page to 100. And if there are 100 rows on the page, a link will be displayed at the bottom, that says "Next 100". Then this will display the next 100 rows. Can you give an example how to do this please? Thanks
  15. I guess it really doesn't have to. I just need the message "Uploading", to display on the page once the button is clicked.
  16. I have a form, that when the user click Submit, I need a php variable to be echoed to the page. This is for an upload page. So when they are waiting for the file to upload, it will say "Uploading..." until the upload is complete. All I know so far is I need to create a javascript function and include it in the submit button. This is all I have so far in the submit button tag: onClick="Transferring();" Now I need to figure out the code to include in this function. Any ideas?
  17. Hi, I'm having two issues with my Search engine for my website. It is created to search through my database (it doesn't crawl through pages). The first problem I'm having is when I type in for example: Super Mario Bros and there is a row in my table with a field called Super Mario Brothers this row is not included as a successful result to the search. I need to somehow modify my code to search every word in every table cell in the database. So another example. I have 5 rows, each with one cell, named as follows: One Two Three Four Five If I was to type in the search box: One Two Three Four Five it should display all rows (it obviously doesn't do that right now lol) The second issue has to do with my sql query. It looks like this: $query = "select * from sheets where artist like \"%$trimmed%\" OR title like \"%$trimmed%\" order by artist"; $numresults=mysql_query($query); I need this query to search in the columns artist and title (like it is doing above) AS WELL as search only those rows that have an active status set to 'yes'. I tried to type something like: $query = "select * from sheets where active='yes' && artist like \"%$trimmed%\" OR title like \"%$trimmed%\" order by artist"; but this obviously causes problems. How do i require the query to include rows that are active, but have it look through artist OR title as well? Here is my code below. Any insight appreciated. Will be working on it til someone is available. Thanks <?php include_once('inc/functions.php'); // Get the search variable from URL $var = @mysql_safe($_GET['q']) ; $trimmed = trim($var); //trim whitespace from the stored variable // rows to return $limit=10000; // check for an empty string and display a message. if ($trimmed == "") { $error = "<tr><td colspan='2' style='text-align: center; border-style: solid; border-color: #f43636; background-color: #fe6a6a;'><strong>Type In A Sheet To Search For</strong></td></tr>"; } // check for a search parameter if (!isset($var)) { $error = "<tr><td colspan='2' style='text-align: center; border-style: solid; border-color: #f43636; background-color: #fe6a6a;'><strong>Type In A Sheet To Search For</strong></td></tr>"; } // Build SQL Query $query = "select * from sheets where artist like \"%$trimmed%\" OR title like \"%$trimmed%\" order by artist"; $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); // If we have no results if ($numrows == 0) { // If search was not found $error = "<tr><td colspan='2' style='text-align: center; border-style: solid; border-color: #f43636; background-color: #fe6a6a;'><strong>Unfortunately that sheet was not found, however, please request it by clicking below</strong></td></tr><tr><td colspan='2' style='text-align: center; border-left-style: solid; border-bottom-style: solid; border-right-style: solid; border-color: #f43636; background-color: #f5f5f5;'><a href='request.php'>Request A Sheet Here</a></td></tr>"; } // next determine if s has been passed to script, if not use 0 if (empty($s)) { $s=0; } // get results $query .= " limit $s, $limit"; $result = mysql_query($query) or die("Couldn't execute query"); $search = " "; $break = "<br />"; if($var!=""){ $search = "Search:"; $break = ""; } ?> <br /><div id='headsearch'></div> <div style="width: 210px; margin-left: auto; margin-right: auto; text-align: center;"> <form name="form" action="search.php" method="get"> <div style="float: left;"><input type="text" name="q" /></div> <div style="float: right;"><input type="image" src="img/search.png" alt="Search" name="Submit" value="Search" /></div> </form> </div> <?php // display what the person searched for echo "<center><div style='width: 210px; margin-left: auto; margin-right: auto; text-align: center;'>$search <span style='color: #6aa504; margin-left; auto; margin-right: auto;'>" . stripslashes($var) . "</span></div></center>"; ?> <?php // begin to show results set $count = 1 + $s ; $greenboxleft = "greenboxleft"; $greenboxright = "greenboxright"; $grayboxleft = "grayboxleft"; $grayboxright = "grayboxright"; $colorvalue = 0; echo "$break<table width='700px' align='center' style='border-collapse:separate; border-spacing:0px;'><th style='background-color: #93DB70; border-bottom-style: solid; border-color: #6aa504;'>Artist</th><th style='background-color: #93DB70; border-bottom-style: solid; border-color: #6aa504;'>Title</th>"; if($error==""){ // now you can display the results returned while ($row= mysql_fetch_array($result)) { $artist = $row["artist"]; $title = $row["title"]; if(($colorvalue%2)==0){ $styleleft = $greenboxleft; $styleright = $greenboxright; } else{ $styleleft = $grayboxleft; $styleright = $grayboxright; } echo "<tr>"; echo "<td align='center' width='350px' id='$styleleft'><div id='songsboxleft'><strong>". ucwords($row['artist']). "</strong></div></td>"; echo "<td align='center' width='350px' id='$styleright'><div id='songsboxright'><a target='_blank' name='downloadclick' href='download.php?sheet=".$row['url']."&artist=".$row['artist']."&title=".$row['title']."'>" .ucwords($row['title']). "</a></div></td>"; echo "</tr>"; $colorvalue++; } } else{ echo $error; } echo "</table>"; ?>
  18. Thanks for all the suggestions everyone. Here is where I am at. The char-set is utf8-unicode. Once i type in the title: I Don't Care Inside the database it displays exactly how I typed it. Displaying it is the issue now. I tried stripslashes around $title, but it displays as: I Don Here is my code that displays each row from my database. while($row = mysql_fetch_array($result)) { if(($ibg%2)==0){ $bgcolor = "#f5f5f5"; } else{ $bgcolor = "#ccddff"; } $hasdownloads = $row['timesdownloaded']; $dcolor = "#ffffff"; $tcolor = "#ffffff"; $inputbg = "#ffffff"; $dlsbg = "#ffffff"; $lastdownloaded = $row['lastdownloaded']; if ($hasdownloads>0){ $dcolor = "#00cc00"; $dlsbg = "#93db70"; } else{ $dlsbg = $bgcolor; } if ($lastdownloaded==$today){ $tcolor = "#72a4d2"; $inputbg = "#ccddff"; } else{ $tcolor = $bgcolor; $inputbg = $bgcolor; } if($row['artist']=="DELETE"||$row['title']=="DELETE"){ $bgcolor = "#FE6A6A"; $bgcolor = "#FE6A6A"; } echo "<tr>"; echo "<td align='center' width='40' bgcolor='$bgcolor'><input type='hidden' name='user[".$row['id']."]' value='".$row['id']."' />" .$row['id']. "</td>"; echo "<td align='center' width='200' bgcolor='$bgcolor'><input type='text' name='artist[".$row['id']."]' value='" .ucwords($row['artist']). "' size='30' style='border: none; background-color: $bgcolor;'></td>"; echo "<td align='center' width='130' bgcolor='$bgcolor'><input type='text' name='title[".$row['id']."]' value='" .ucwords($row['title']). "' style='border: none; background-color: $bgcolor;'></td>"; echo "<td align='center' width='10' bgcolor='$bgcolor'><input type='text' name='timesdownloaded[".$row['id']."]' value='" .$row['timesdownloaded']. "' size='10' class='adminform' style='background-color: $dlsbg; border: none'></td>"; echo "<td align='center' width='80' bgcolor='$bgcolor'><input type='text' name='url[".$row['id']."]' value='" .$row['url']. "' size='15' style='border: none; background-color: $bgcolor;'></td>"; echo "<td align='center' width='10' bgcolor='$tcolor'><input type='text' name='todaydownloads[".$row['id']."]' value='" .$row['todaydownloads']. "' size='10' class='adminform' style='background-color: $inputbg; border: none'></td>"; echo "<td align='center' width='20' bgcolor='$tcolor'><input type='text' name='lastdownloaded[".$row['id']."]' value='" .$row['lastdownloaded']. "' size='8' style='background-color: $inputbg; border: none'></td>"; echo "<td align='center' width='10' bgcolor='$bgcolor'><a href='editsheets.php?delete=true&id=" .$row['id']. "' onclick='return show_delete()'>Delete</a></td>"; echo "<td align='center' width='10' bgcolor='$bgcolor'><input type='checkbox' name='check[".$row['id']."]' style='background-color: $bgcolor;'></td>"; echo "</tr>"; $ibg++; }
  19. Hey, i tried echoing the title out, and after trying to type in: I Don't Care It echoed out: I Don\'t Care So this part seems to work correctly, however it doesn't show all of this once it updates the database. It only shows: I Don I know the query updates the rows successfully, however it just doesn't display the single quote or anything after it. Any other ideas?
  20. Hi, I'm trying to type in a name of a song into an input field, for example: I'll Be Missing you This field is captured through $_POST and set to a variable $title I then update the table with this new title. Once it is updated, all that is shown in the data is: I The single quote, and anything after it is gone completely. Here is my query. How can I change this so it includes the single quote and everything after it? $sql = "UPDATE sheets SET artist = '$artist', title = '$title', active = '$activestatus' WHERE id = $value"; $result = mysql_query($sql) or die(mysql_error().'<br>'.$sql); If more code is required to understand what I'm talking about, let me know.
  21. Alright, I tried this: $result = mysql_query("SELECT title, COUNT(title) AS n FROM sheets GROUP BY title HAVING n > 1"); I have a while loop later on in my code that looks like this: while($row = mysql_fetch_array($result))[ } This is a page that I've been using for weeks and the while loop works great. There must be a problem with this query. I am not getting any errors, nor anything displaying to the screen.
  22. I have a mysql table that looks like this: id int(11) autoincrement artist varchar(50) title varchar(50) I need to check for any rows that have the same titles. So for example, if I had the following rows: 1 - Bob - Hello World 2 - Charlie Brown - Theme Song 3 - Joe - Hello World 4 - Joe - Is Cool 5 - Bob - Magic Dude The query would display Row 1, and Row 3 as duplicates. Any idea how I can do something like this?
  23. @schilly The variable just doesn't echo, but other than that it looks fine @PFMaBiSmAd The page is called editsites.php Upon testing: printf("<pre>%s</pre>", print_r($GLOBALS, true)); Here is what I got Array ( [GLOBALS] => Array *RECURSION* [_POST] => Array ( ) [_GET] => Array ( [siteid] => 95 ) [_COOKIE] => Array ( [__utma] => 85803532.1539801326.1264289557.1266012530.1272424868.20 [phpSESSID] => 4rpecnl0ct9horguflqgji9gt4 ) [_FILES] => Array ( ) [_SESSION] => Array ( [sort_counter] => 2 [username] => treeguy [views] => 0 ) [loginstatus] => logout [username] => treeguy [connect] => Resource id #3 [siteid] => 95 [message] => [success] => [error] => [useridquery] => SELECT id FROM users WHERE username='treeguy' [useridresult] => Resource id #4 [useridrow] => Array ( [id] => 2 ) [userid] => 2 [result1] => Resource id #5 [siterow1] => Array ( [id] => 95 [userid] => 2 [url] => http://www.55newgrounds.com [credits] => 8105 [dailyviews] => 5555555 [todayviews] => 56 [totalviews] => 9756 [active] => no [title] => 55new grounds1254242 [confirmed] => no ) [titledb] => 55new grounds1254242 [urldb] => http://www.55newgrounds.com [maxviewsdb] => 5555555 [statusdb] => no [titlenew] => [urlnew] => [maxviewsnew] => [statusnew] => no [editnewsite] => )
  24. Hi, I'm working on a page that GETs a value that is passed in the URL. This variable echos correctly up until I try echoing it inside an if statment where it needs to be. The variable is called $siteid. Inside my if statement I have a query that runs WHERE id='$siteid' Inside this if statement it won't echo out. It is the weirdest thing. I tried to hardcode the siteid as 95, to test it, and the query updated my database as it should. However, leaving it as the variable it will not work. Any help solving this mystery that I've been banging my head over for hours would be greatly appreciated! My variable echos correctly up until the line that says: // $siteid will Echo up until here. After this point it stops working. The query I am having issues with is after the line that says: // Problem lies in this query. My SQL Table: id int(11) No userid int(11) No url varchar(2083) No credits int(11) No 0 dailyviews int(11) No 0 todayviews int(11) No 0 totalviews int(11) No active tinytext No title varchar(50) No confirmed tinytext No And my code: <?php session_start(); if (isset($_SESSION['username'])){ $loginstatus = "logout"; $username = $_SESSION['username']; include_once('inc/connect.php'); $siteid = $_GET['siteid']; $message = "messagebox"; $success = " "; $error = " "; $useridquery = "SELECT id FROM users WHERE username='$username'"; $useridresult = mysql_query($useridquery); $useridrow = mysql_fetch_assoc($useridresult); $userid = $useridrow['id']; $result1 = mysql_query("SELECT * FROM websites WHERE `id`='$siteid' && userid='$userid'"); $siterow1 = mysql_fetch_assoc($result1); $titledb = $siterow1['title']; $urldb = $siterow1['url']; $maxviewsdb = $siterow1['dailyviews']; $statusdb = $siterow1['active']; $titlenew = $_POST['title']; $urlnew = $_POST['url']; $maxviewsnew = $_POST['maxviews']; $statusnew = $_POST['status']; if($statusnew=="Active"){ $statusnew = "yes"; } else{ $statusnew = "no"; } $editnewsite = $_POST['editnewsite']; if($success!=""){ $message = ""; } else{ $message = "messagesuccess"; } // $siteid will Echo up until here. After this point it stops working. if($editnewsite){ if($titlenew){ if($urlnew){ if($maxviewsnew){ function valid_url($urlnew) { return ( ! preg_match('/^(http|https|ftp):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i', $urlnew)) ? FALSE : TRUE; } if(valid_url($urlnew)){ //Check if URL is a Duplicate for current user $results = mysql_query("SELECT * FROM `websites` WHERE `userid`='$userid' AND `url`='$url'"); $rows = mysql_num_rows($results); if ($rows<=0) { $siteidnew = $siteid; // Problem lies in this query. $update = "UPDATE `websites` SET `title`='$titlenew', `url`='$urlnew', `dailyviews`='$maxviewsnew', `active`='$statusnew' WHERE `id`='$siteid' && `userid`='$userid'"; mysql_query($update); $titledb = $titlenew; $urldb = $urlnew; $maxviewsdb = $maxviewsnew; $statusdb = $statusnew; echo $titledb; echo $urldb.$maxviewsdb.$statusdb."<br>".$siteid; // PROBLEM HERE exit(); } else{ $error = "You have already submitted that site"; $message = "messageerror"; } } // here else { $error = "Invalid URL"; $message = "messageerror"; } } else{ $error = "Type in the Maximum Views you<br />want your site to get daily!"; $message = "messageerror"; } } else{ $error = "Type in the Url of your website!"; $message = "messageerror"; } } else{ $error = "Type in a Title for your site!"; $message = "messageerror"; } } } else{ $loginstatus = "login"; header("Location: index.php"); } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="description" content="Free Piano Sheet Music - Sheet Music Haven" /> <meta name="keywords" content="Piano,Sheet,Music,Haven,Score,Piece,Top,Trade" /> <meta name="author" content="Sheet Music Haven" /> <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1" /> <title>Edit Sites - Sheet Music Haven</title> <link rel="stylesheet" type="text/css" href="styles/style.css" /> <link rel="stylesheet" type="text/css" href="styles/editsites.css" /> <script type="text/javascript"> function make_blank() { if(document.login.username.value =="Username"){ document.login.username.value =""; document.login.username.style.color ="#000000"; } } function make_blank1() { if(document.login.password.value =="Password"){ document.login.password.value =""; document.login.password.type ="password"; document.login.password.style.color ="#000000"; } } function undoBlank() { if(document.login.username.value == ""){ document.login.username.value ="Username"; document.login.username.style.color="#ccc"; } } function undoBlankpass() { if(document.login.password.value == ""){ document.login.password.value ="Username"; document.login.password.style.color="#cccccc"; } } function inputLimiter(e,allow) { var AllowableCharacters = ''; if (allow == 'NumbersOnly'){AllowableCharacters='1234567890';} var k; k=document.all?parseInt(e.keyCode): parseInt(e.which); if (k!=13 && k!=8 && k!=0){ if ((e.ctrlKey==false) && (e.altKey==false)) { return (AllowableCharacters.indexOf(String.fromCharCode(k))!=-1); } else { return true; } } else { return true; } } </script> </head> <body bgcolor="#343331"> <!-- Header --> <div id="header"> <div id="headerleft"></div> <div id="headermiddle"><a href="index.php"><img src="img/logo.png"></a></div> <div id="headerright"> <?php echo "<form name='login' action='inc/$loginstatus.php' method='POST'>";?> <div class="loginboxdiv" id="username"> <input type="text" class="loginbox" name="username" value="Username" onFocus="make_blank();" onBlur="undoBlank();"> </div> <div class="loginboxdiv" id="password"> <input class="loginbox" type="text" name="password" type="text" value="Password" onFocus="make_blank1();" onBlur="undoBlankpass();"> </div> <div id="login"> <?php echo "<input type='image' src='img/$loginstatus.png' alt='".ucfirst($loginstatus)."'>";?> </div> </form> <div id="register"> <a href="register.php"><img src="img/register.png"></a> </div> <div id="forgotpassword"> <a href="resetpassword.php" class="forgot">Forgot Password?</a> </div> </div> </div> <!-- Content Top --> <div id="contenttop"> <div id="links"> <table cols="7"> <tr> <td align="center" valign="middle" width="100px" height="48px"><a href="index.php"><img src="img/home.png"></a></td> <td align="center" valign="middle" width="100px" height="48px"><a href="member.php"><img src="img/member.png"></a></td> <td align="center" valign="middle" width="100px" height="48px"><a href="addsheet.php"><img src="img/addsheet.png"></a></td> <td align="center" valign="middle" width="100px" height="48px"><a href="advertise.php"><img src="img/advertise1.png"></a></td> <td align="center" valign="middle" width="100px" height="48px"><a href="faq.php"><img src="img/faq.png"></a></td> <td align="center" valign="middle" width="100px" height="48px"><a href="terms.php"><img src="img/terms.png"></a></td> <td align="center" valign="middle" width="100px" height="48px"><a href="contact.php"><img src="img/contact.png"></a></td> </tr> </table> <!-- 92x30 --> </div> </div> <!-- Content Middle --> <div id="contentmiddle"> <div id="content"> <div id="headeditsites"></div> <br /> <div id="editsite"> <form action="editsites.php" method="post" name="newsite"> Title: <input type="text" name="title" value="<?php echo $titledb; ?>"><br /> Url: <input type="text" name="url" value="<?php echo $urldb; ?>"><br /> Max Views: <input type="text" maxlength="11" id="NumbersOnly" onkeypress="return inputLimiter(event,'NumbersOnly')" name="maxviews" value="<?php echo $maxviewsdb; ?>"><br /> <select name="status"><option value='Active' name='active'>Active</option><option value='Passive' name='passive'>Passive</option></select><br /><br /> <center><input type="submit" name="editnewsite" value="Edit Site"></center> </form> </div> </div> </div> <!-- Content Bottom --> <div id="contentbottom"> </div> </body> </html>
×
×
  • 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.