PHP - Major Issues ...
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 he 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*8)); 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> Similar TutorialsHere is my code so far... I can't login using this php, i am new to php and am trying my hardest to figure this out... i have been on this for 4 days and am about to pull all of my hair out... can anyone please help me... //******** start of login.php ******** <?php require_once('connectvars.php'); // Start the session session_start(); // Clear the error message // $error_msg = ""; // If the user isn't logged in, try to log them in if (!isset($_SESSION['user_id'])) { if (isset($_POST['submit'])) { // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); if (!$dbc) { die('Could not connect: ' . mysqli_error()); } echo 'Connected successfully'; // Grab the user-entered log-in data $user_email = mysqli_real_escape_string($dbc, trim($_POST['email'])); $user_pass = mysqli_real_escape_string($dbc, trim($_POST['password'])); if (!empty($user_email) && !empty($user_password)) { // Look up the username and password in the database $query = "SELECT tb_user_id, tb_user_email FROM tb_users WHERE tb_user_email = '$user_email' AND tb_user_password = SHA('$user_pass')"; $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 1) { // The log-in is OK so set the user ID and username session vars (and cookies), and redirect to the home page $row = mysqli_fetch_array($data); $_SESSION['user_id'] = $row['tb_user_id']; $_SESSION['email'] = $row['tb_user_email']; setcookie('user_id', $row['tb_user_id'], time() + (60 * 60 * 24 * 30)); // expires in 30 days setcookie('email', $row['tb_user_email'], time() + (60 * 60 * 24 * 30)); // expires in 30 days $home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/index.php'; header('Location: ' . $home_url); } else { // The username/password are incorrect so set an error message $error_msg = 'Sorry, you must enter a valid username and password to log in1.'; } } else { //*********** This is the error i keep getting // The username/password weren't entered so set an error message $error_msg = 'Sorry, you must enter your username and password to log in2.'; } } } // Insert the page header $page_title = 'Log In'; require_once('header.php'); // If the session var is empty, show any error message and the log-in form; otherwise confirm the log-in if (empty($_SESSION['user_id'])) { echo '<p class="error">' . $error_msg . '</p>'; ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <fieldset> <legend>Log In</legend> <label for="email">Email Address:</label> <input type="text" name="email" value="<?php if (!empty($user_email)) echo $user_email; ?>" /><br /> <label for="password">Password:</label> <input type="password" name="password"/> </fieldset> <input type="submit" value="Log In" name="submit" /> </form> <?php } else { // Confirm the successful log-in echo('<p class="login">You are logged in as ' . $_SESSION['email'] . '.</p>'); } ?> <?php // Insert the page footer require_once('footer.php'); ?> Ok. So I have an HTML website with 14 pages and an external CSS. This website is for a movie rental place like BlockBuster, but local and much smaller. I have to update it everyday , http://brucegregory.net/westmorelandvt , and as you can see I will have to move every block down 1 to put a new movie up. What I think would help: 1. Change all my pages to PHP with an admin panel. 2.I need help with the admin panel and a code that makes my movies on the index page move to the right once or move down to the left once every time I add a new movie. Can someone please help? I am in the middle of creating an E-Commerce website in PHP (using EasyPHP) and I have run into some problems I have a file called Logout.php which is designed to log registered database users out of a session. However when I go to view the page, I get this ASP.NET IIS7 message: HTTP Error 500.24 - Internal Server Error An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode. This is obviously a php file I have developed, but I do not understand why it is doing this. I have attached the entire project to the message (once unzipped, look for "logout.php") to demonstrate what I am doing, help would be very appreciated please. I have a script that I've given the user some additional options to either get a random proxy from a URL or list that they have supplied. While getting from the URL is no problem. I banging my head against the wall trying to figure out why the program won't get a random proxy from the list. After submitting their query their proxy list gets written to a temporary file. Everything writes fine and the URL where they are written is the exact format that I need. This works: //Where the user submits a URL <?PHP $proxypage = file('theirproxyurl.php'); ?> Although the page exists in the exact same format as the above link when I write their proxies to a file within the server - it does not work. For example: //Where the user submits a list of proxies - they get written to a file <?PHP $proxypage = file('proxieswrittentofile.php'); ?> Even if I paste the LINK (Note: the page exists with the exact same format) directly in the program where the users proxies were written to it still doesn't work. <?PHP //This doesn't work: $proxypage = file('pasted-working-link-in-exact-same-format.php'); ?> <?PHP //I tried the full URL - it doesn't work either $proxypage = file('http://SUBDOMAIN.fullURLtowrittenproxypage.php'); ?> The only thing that's different is that the file where the proxies are being written is on a sub-domains. Aside from that the pages are absolutely identical down to the <br /> tags. Would sub-domains be an issue for the file function? I make my share of programming design blunders, as many of you know from helping me debug a few, so I am hesitant to point fingers, but I just had an experience so horrible, with so many errors on a website owned by Snapfish (which should have some programming resources) that I had to write it up.
Hello everyone, it's my first post here. I was recommend this community for it's professionalism and "friendlyness". During my stay here, please excuse my english. I know it can be unpleasant for you to read a thread with terrible grammar, I hate it in my native language, I'll do my best. Okay, so I'm having two major issues for my website to operate like I'd like it to, I've done everything I knew about, and I can't think about anything else Google didn't help me much either this time. First one is that I seem to have a cookies/sessions problem. Well, I use Liberty Reserve to allow my members to top up their account. So I send my form to their SCI and when I either cancel or complete a transaction, I return to my website but I'm not logged in anymore! So the auto-add to balance system can't work. Alright, when I saw this I was only using sessions, so I added cookies so I could rely on them too. And there again, same thing. Doubled, tripled checked all the LR settings and everything, I know they are right. But what's really, really, weird to me and what's really doing my head in is that I'm not actually logged out, because if I use another tab/window I'm still logged in. In other words, it's only the window coming back from Liberty Reserve that won't log in. The cookies are still here and so is the session so... Another terrible thing is that it used to work when I was on my previous host (just moved to a dedicated server, which may be causing the problems, it's the first time I administrate a dedi). This is blocking my entire website from working. And my second problem is with the function mail() -there again 'caused' by new server-. I don't get any error message, or anything. The e-mails with cPanel/WHM work great. Though, I have done several tests and it never reaches my Gmail, Hotmail or Yahoo account. It did work with a Yopmail inbox though. So, I was focusing on 'why isn't it sending it' but since I just noticed it worked with Yopmail, I'm sure it is sending it and have no ideas why wouldn't it work with other e-mail service providers. I hope you understood what I meant and that, hopefully, you guys can help me out with those totally handicapping issues. Thank you, Regards. -Ben. Issue # 1 How can i send the values come from $_POST['name'],$_POST['number'] to an email address xyz@radiations3.com??? Issue # 2 I am trying to display data from four different tables with the following sql query: (The problem is that the data is getting displayed fine but i don't know why some of the (same )data gets repeated two or three times where as i checked in all four tables and all the data exists one time not twice) If anything wrong with my query kindly help SELECT distinct * FROM applicant,applicant_info_nic,room,student WHERE applicant_info_nic.status='Available' and applicant.appNIC=applicant_info_nic.appNIC and applicant.roomID=room.roomID and applicant.appNIC=student.appNIC ORDER BY applicant.roomID i am trying to sort out a session now, i normally use the folllowing code to check if someone is logged in and if they are not to forward them to the login page, but i am getting this message: Notice: Undefined index: username in code: Code: [Select] if ($_SESSION['username']) { }else{ include 'login.php'; die(""); } can someone help please. Hey all, I can not get utf-8 working properly. I'm having issues with special characters, such as bullets, e with an accent over it, etc. The data is being stored in my mssql database properly, and I can see everything there fine. It's when I grab it from the database and display it on my php page. The page it set up to utf-8, if I go to Tools>Page Info, it says encoding is utf-8. I have it in my headers, I just can not figure out why it will not display on the page. Any thoughts? Hello, I'm having troubles parsing text properly. Whenever I submit data into a mysql db, and then call that specific data, in the text, I get this symbol, �. Does anybody know what it is or how to remove it? I believe it's with utf-8 and me using a function that corrupts the string but I'm not sure. Anybody have any clues? Thanks in advance. Hello, Well let me explain my problem to you guys. I am using a printf function with an array, a custom function which i got off php.net Anyways, Everytime I use it, It seems to leave random numbers at the end of the string for no reason at all. Here is the result in source: Code: [Select] <td><a href="?page=download&name=DarkRP">DarkRP</a></td> <td>08:10:17 AM 07/08/2010</td> <td>Updated DarkRP from revision: 670 to revision: 67150</td> Array ( [Name] => DarkRP [TimeStamp] => 1281186617 [Revision1] => 670 [Revision2] => 671 ) </tr>It is mean't to show Code: [Select] Updated DarkRP from revision: 670 to revision 671but instead it has the random number 50 at the end for no reason... Anyways heres the echoing code: <?php foreach($Logs as $Log){ $Time = TimeToDate($Log['TimeStamp']); if($Log['Revision1']&$Log['Revision2']){ $Message = 'Updated %1$s from revision: %3$s to revision: %4$d'; }else{ $Message = 'Freshly downloaded: %1$s revision: %3$d'; } ?> <tr> <td><?php echo '<a href="?page=download&name='. $Log['Name'] .'">'. $Log['Name'] .'</a>'; ?></td> <td><?php echo $Time['Time'] .' '. $Time['Date']; ?></td> <td><?php echo printf_array($Message, $Log); ?></td> <?php print_r($Log); ?> </tr> <?php } ?> </table> <br /> Functions: function MySQLGetLogs(){ global $Connection; if($Connection){ $Query = sprintf('SELECT name, timestamp, revision1, revision2 FROM update_logs ORDER BY timestamp DESC;'); if($Result = mysql_query($Query)){ $Array = array(); while($Row = mysql_fetch_array($Result)){ $Array2 = array(array( 'Name' => $Row['name'], 'TimeStamp' => $Row['timestamp'], 'Revision1' => $Row['revision1'], 'Revision2' => $Row['revision2'] ) ); $Array = array_merge($Array, $Array2); } mysql_free_result($Result); return $Array; } } } function printf_array($Format, $Array) { return call_user_func_array('printf', array_merge((array)$Format, $Array)); } Also, I got the same issue with printf alone instead of the custom array function above. Hey guys, I wrote a function called isServer() so I can quickly move files from my local machine to my server without modifying too much. The function is as follows: function isServer() { if ($_SERVER['SERVER_NAME'] == 'myservername') { return(true); } else { return(false); } } // isServer() I have placed this function in a system.php file I created that is used to simply to keep things in order. That files contents a <?php session_start(); function isServer() { if ($_SERVER['SERVER_NAME'] == 'myservername') { return(true); } else { return(false); } } // isServer() include "configuration.php"; include "functions.php"; include "functions_sql.php"; include "functions_soap.php"; include "functions_mail.php"; if (isProductionServer()) { $dbhost = 'db'; $dbuser = 'db_user'; $dbpass = 'pass123'; } else { $dbhost = 'localhost'; $dbuser = 'user'; $dbpass = 'pass'; } $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'my_database'; mysql_select_db($dbname) or die ('Selected database does not exist'); ?> The problem I am having is for some reason none of the include files are recognizing the function. For example, the functions_mail.php file references the function to determine which emails to send (because the different environments have different modules and such installed). I know this is something easy, but I can't seem to figure it out. Thanks for any help! Hello, I have the following code Code: [Select] class Uploads extends Controller { public function __construct() { parent::__construct(); if (empty($_FILES)) { log_message('error', 'Uploads - files empty'); exit('No files uploaded'); } ini_set('memory_limit', '128M'); $this->load->helper('file'); $this->load->helper('helpers'); $this->load->model('uploads_model'); } public function font_handler() { $this->uploads_model->font_handler(); } } class Uploads_model extends Model { public function font_handler() { $config = array( 'max_size' => '8388', 'allowed_types' => 'ttf', 'upload_path' => 'assets/fonts/' ); $this->load->library('upload', $config); if ($this->upload->do_upload('Filedata')) { $file = $this->upload->data(); $jsFile = $file['raw_name'].'.js'; $query = $this->db->where('location', 'menuFont')->get('fonts')->row(); if ($query->customFile != '' && file_exists('assets/fonts/'.$query->customFile)) { unlink('assets/fonts/'.$query->customFile); } $path = getcwd() . '/assets/fonts/cufon/convert.php'; $command = 'php ' . $path . ' -u "U+??" ' . $file['full_path'] . ' 1> ' . getcwd() . '/assets/fonts/' . $jsFile; system($command); } } } Ok so, the ttf file is uploaded correctly and I can run $command from the command promt in putty and it works perfect, but when I try to run the same command from system() the js file just contains (from the controller) "No files uploaded" I have no idea why this is happening? Anyone have any ideas? Also one thing i'm not sure about is if it should be 1> or > when creating the js file?!? Thanks guys! Hey guys im having a real problem trying to make this string happend the problem is passing parameters on the javascript function "onmouseover" $map_array .= "<a href='map.php?planet=$address' onmouseover='ajax_popup ($picture,$detail_name,$stargate_address,$detail_owner,$time_conquered,$time_offset,$detail_siege, $alliance)'> <img src='images/star.jpg' style='position:absolute; left:".$b_x."px; top:".$b_y."px; border-style:solid; border-color: yellow;'></a>"; if I try this it works onmouseover='ajax_popup(1,2,3,4,5,6,7,8)'> So the problem is when the variables equal words. Cause of the quote issue. Is there like a way i should be using JSON to do what im trying to do? I have to keep this as a php string too. Or end as a php string Hi, I'm trying to convert a charting app to OOP. So here I've simplified it down to just the bare bones issue of drawing a line to a png image and displaying it. Code: [Select] <?php class chart { var $im; var $backgroundColor; var $textColor; function chart() { $this->im= @ImageCreate (100, 200) or die ("Cannot Initialize new GD image stream"); $this->backgroundColor = ImageColorAllocate ($this->im, 224, 234, 234); $this->textColor = ImageColorAllocate($this->im, 233, 14, 91); } function display() { imageline ($this->im,0,0,100,200,$this->backgroundColor); imageline ($this->im,100,0,0,200,$this->textColor); ImagePng ($this->im); } } ?> Here is the code which instantiates the class. Code: [Select] <?php include "simple_draw.php"; $mychart = new chart(); $mychart->chart(); $mychart->display(); ?> Basically depending on how I rework it, one of two things happens: a)it generates a bunch of little boxes which say fffd, or b) I get a message saying the resource is invalid or nonexistent (this error isn't coming up right now so I can't be precise.) If this is run outside the OOP environment it works fine. No sure. I'm really trying to work with classes but this kind of problem is frustrating and admittedly makes it tempting to just go back to regular functions. Any ideas?? Thanks, Jeff Hi Guys, Beginner needs help with accommodation search feature...i have two drop downs(area and type), each one has an 'any' option. I cant evalute the 'any' options directly against the database so have written this: Code: [Select] <?php //query database if ($_SESSION['type']== 'any' && $_SESSION['area']== 'any'){ $query = mysql_query("SELECT * FROM hotels Order by RAND() "); } elseif ($_SESSION['area'] == 'any' && $_SESSION['type'] != 'any'){ $query = mysql_query("SELECT * FROM hotels WHERE type = $_SESSION[type] Order by RAND()"); } elseif ($_SESSION['type'] == 'any' && $_SESSION['area'] != 'any'){ $query = mysql_query("SELECT * FROM hotels WHERE location =$_SESSION[area] Order by RAND()"); } else{ $query = mysql_query("SELECT * FROM hotels WHERE location ='$_SESSION[area]' AND type ='$_SESSION[type]' Order by RAND()"); } //show results while ($search_result = mysql_fetch_assoc($query)) { echo '<b>'.$search_result[name] . '</b><br>'; echo '<p><img src="'.$search_result['photo1'].'" /></p>'; echo '<p><img src="'.$search_result['award'].'" /></p>'; echo $search_result[description] . '<br><br>'; }?> The first if and last else return the correct info from database but the middle two elseif's throw this error: Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given.... I have commented out the queries and replaced them with simple echoes and they all seem to evaluate correctly!. So im lost why $query isnt assigned in the middle two elseif's ?? Any ideas what im doing wrong and is there a better way. Cheers!! Hi all, I am desperately in need of some help here. I have been troubleshooting these codes for days, and I have posted this similar question quite a couple of times, and there is no answer from anyone... I am really in a bad shape now. Could someone please enlighten me to my problem? I have created 2 while loops...apparently the 2nd while loop overwrites the 1st while loop record. Meaning to say...1st while loop generates values of 'Math' 'Eng' 'Chi' 'Sci' AND store it in $subject_data, createLevelCheckboxes($subject_data, $level_data, 5); Apparently, the 2nd while loop takes only the last record 'Sci' from $subject_data and continues the looping. Which gives me results like Level 1 Sci Level2 Sci Level3 Sci I would like to attain something like.... Level 1 Math Level2 Eng Level3 Chi Level4 Sci Is there any reset which I need to do? while($data = mysqli_fetch_array($sql)) { if($current_level_id != $data['level_id']) { $checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); $current_level_id = $data['level_id']; $subject_data = array(); } //Add the current record to the $level_data array $subject_data[] = $data; } while($data1 = mysqli_fetch_array($sql1)) //Iterate throug the DB results { $checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); $level_data = array(); $level_data[] = $data1; } $checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); I have no idea what the problem is with preg_replace and strings smaller than 3 characters. I'm writing to do a pattern search of abreviations(array) and replacements (array)... tried word boundries, which seems not to work at all. (it is VITAL that im able to match the whole word) here is a quick example which I cannot understand maybe someone could explain to me: 1. why repitions of certain abrevs do not get replaced. 2. why '/\bs.\b/' wont get matched (where there is a space before the b. - hense the word boundry) here is a snippet of code could someone please explain why this happens: Code: [Select] <?php $string='de d. s. pres. div. de de d. s.'; //DEFINE PATTERN $patterns = array(); $patterns[0] = '/ s. /'; $patterns[1] = '/ b. /'; $patterns[2] = '/ pres./'; $patterns[3] = '/ Ind./'; $patterns[4] = '/ Mar./'; $patterns[5] = '/ Agt./'; $patterns[6] = '/ Agy./'; $patterns[7] = '/ Indpls./'; $patterns[8] = '/ Chgo./'; $patterns[9] = '/ Corp./'; $patterns[10] = '/ U./'; $patterns[11] = '/ Fin./'; $patterns[12] = '/ ls./'; $patterns[13] = '/ Pres. /'; $patterns[14] = '/ Internat. /'; $patterns[15] = '/ m. /'; $patterns[16] = '/ N.Y.C./'; $patterns[17] = '/ div. /'; $patterns[18] = '/ de /'; $patterns[19] = '/ d. /'; //DEFINE PATTERN REPLACE $replacements = array(); $replacements[0] = ' son of '; $replacements[1] = ' born in '; $replacements[2] = ' president'; $replacements[3] = ' Indiana '; $replacements[4] = ' March '; $replacements[5] = ' Agent '; $replacements[6] = ' Agency '; $replacements[7] = ' Indianapolis '; $replacements[8] = ' Chicago'; $replacements[9] = ' Corporation '; $replacements[10] = ' U '; $replacements[11] = ' Financial '; $replacements[12] = ' Island'; $replacements[13] = ' President '; $replacements[14] = ' International '; $replacements[15] = ' married to '; $replacements[16] = ' New York City '; $replacements[17] = ' divorced'; $replacements[18] = ' de '; $replacements[19] = ' daughter of '; echo '------ Original ---------<br>'.$string.'<br>'; $data = preg_replace($patterns, $replacements, $string); echo '<br>------ Abbreviation Replace ---------<br>'.$data.'<br>'; ?> OUTPUT: ------ Original --------- de d. s. pres. div. de de d. s. ------ Abbreviation Replace --------- de daughter of son of president divorcedde daughter of d. s. any help is appriciated thanks. I'm going to post two scripts my login.php and my register.php problem is i'm always getting usernamepassword don't match i think something to do with md5 but can't figure out where... or why? <?php session_start(); $login = $_POST['login']; $password = $_POST['password']; if ($login&&$password) { $connect = mysql_connect("localhost","heaven","jefF0614") or die ("could not connect to server"); mysql_select_db("heaven_users") or die ("could not find database"); $query = mysql_query("SELECT * FROM members WHERE username='$login'"); $numrows = mysql_num_rows($query); if($numrows!=0) { while ($row = mysql_fetch_assoc($query)) { $dbusername = $row['username']; $dbpassword = $row['password']; } // check to see if they match if($login==$dbusername&&$password==$dbpassword) { echo "Your In <a href='member.php'>click here to go to the member page</a>"; //start session $_SESSION['username']=$login; } else echo "Incorrect Password/Username Combination"; } else die("That username dose not exist"); } else die ("Please enter a username and password"); ?> and register.php <?php //check for submit $submit =$_POST['submit']; //gather POST variable $fullname =strip_tags($_POST['fullname']); $email =strip_tags($_POST['email']); $username =strip_tags($_POST['username']); $password =strip_tags($_POST['password']); $password2 =strip_tags($_POST['password2']); if ($submit) { //check that fields were filled in if ($fullname&&$email&&$username&&$password&&$password2) { //check to see if our two password fields match if ($password==$password2) { $password = md5($password); // register the user //open database $connect = mysql_connect("localhost", "heaven", "jefF0614"); mysql_select_db("heaven_users"); //begine insert $queryreg = mysql_query("INSERT INTO members VALUES ('','$fullname','$email','$username','$password')"); if ($queryreg) { echo "Thanks, For Registering! Click <a href=\"index.php\">HERE</a>To Login!"; } } //otherwise if passwords don't match else { echo "<font color='red'>The passwords you entered do not match</font>"; //end of checking password } } else { echo "<font color='red'>Please enter all fields!</font>"; } } //end check for submit ?> I'm trying to run this: Code: [Select] <?php ini_set('max_execution_time','3600'); ini_set('memory_limit','512M'); ini_set('upload_max_filesize','100M'); ini_set('post_max_size','100M'); phpinfo(); ?> Max execution time and memory_limit works but upload_max_filesize and post_max_size don't work. Are you allowed to set those at run time? |