Ricky55
Members-
Posts
100 -
Joined
-
Last visited
-
Days Won
1
Everything posted by Ricky55
-
Looking at the code I provided is there anything else you can think of that I could get my dev to check for me?
-
Sorry Fenway! I'm totally new to mySQL I don't know how to get this information. Would I be better using a persistent connection? or do you need this info first?
-
Thanks for replying. the scripts/func.php is just included at the top of every page of the website. Does this answer your question? Does this mean that this connection will be made every time a new page is loaded? Could this be done in a more efficient manner?
-
Hi I'm wondering if any of you guys would be kind enough to help me with this. A developer that I use is away on holiday and I'm having a few connection issues. From time to time I get the two following errors 1. Lost connection to MySQL server at 'reading initial communication packet', system error: 111 2. Too many connections We are currently using this code: <?php $conn = conn(); function conn($host='79.170.**.**', $user='web140-ffc', $pwd='XXX', $db='web140-ffc') { $conn = mysql_connect($host, $user, $pwd) or die ("<h1>mysql_connect Error</h1>\n <ul>\n <li>Error in: " . $_SERVER['PHP_SELF'] . "</li>\n <li>Selecting database : $db</li>\n <li>With username: $user</li>\n <li>And Password: $pass</li>\n <li>mysql_error: " . mysql_error() . "</li>\n </ul>\n"); mysql_select_db($db, $conn) or die("<h1>mysql_select_db Error</h1>\n <ul>\n <li>Error in: " . $_SERVER['PHP_SELF'] . "</li>\n <li>Selecting database : $db</li>\n <li>With username: $user</li>\n <li>And Password: $pass</li>\n <li>mysql_error: " . mysql_error() . "</li>\n </ul>\n"); return $conn; } function qry($sql) { $result = mysql_query($sql) or die("<h1>Error Querying Database</h1>\n<ul><li>SQL: $sql</li>\n<li>Error: " . mysql_error() . "</li>\n</ul>"); return $result; } ?> Then on every page I have an include to this connection file <?php include 'scripts/func.php'; ?> I was wondering if you could take a look and tell me A. How this code looks, can you see anything that might be causing the issue? B. Is there anyway to prevent the Too Many connections error? perhaps increase the number of connections or have a check in place? Thanks in advance
-
Just used the first example working like charm both locally and online. Thanks for your lads much appreciated.
-
Hi Still a new comer when it comes to PHP. I have a situation where I want to use an include within an include and I am having trouble with my file paths. My main header include, includes everything for each page of my site, beyond the opening of the body to incorporate my navigation etc conditionally loading in css, and loading in titles and meta data etc depending on the page in question. This header needs to reference another include called the-pod.php which is required for every page, the only trouble is I want to use / to reference the root of the server and this is breaking my code. I can't use ../../ etc as its a different path depending on where the master file is located. So my question is how do I get around this? Can the root of the server or path to the root be stored in a variable? and if so how would I write this. Any tips / advice will be greatly appreciated.
-
IE not processing form with input type of image
Ricky55 replied to Ricky55's topic in PHP Coding Help
Cheers I used the _x method and it worked for me. -
IE not processing form with input type of image
Ricky55 replied to Ricky55's topic in PHP Coding Help
If you know the answer please help me. -
Hi I have a simple form that uses an image for the submit button <input type="image" src="images/contactSendBtn.jpg" alt="Submit Form" name="submit" value="submit" /> This submit button works in all browsers but not in IE. I've read that its something to do with IE not sending the submit variable correctly and instead sending submit_x. Could anyone look at my script and tell me how I need to change this to get it to work with this input type of image. Thanks My script <?php $after = "/contact-success.php"; $oops = "/contact-failed.php"; if (!isset($_POST['submit']) || $_SERVER['REQUEST_METHOD'] != "POST") { exit("<p>You did not press the submit button; this page should not be accessed directly.</p>"); } else { $exploits = "/(content-type|bcc:|cc:|document.cookie|onclick|onload|javascript|alert)/i"; $profanity = "/(beastial|bestial|blowjob|clit|cock|cum|cunilingus|cunillingus|cunnilingus|cunt|ejaculate|fag|felatio|fellatio|fuk|fuks|fuck|fuck off|gangbang|gangbanged|gangbangs|hotsex|jism|jiz|kock|kondum|kum|kunilingus|orgasim|orgasims|orgasm|orgasms|phonesex|phuk|phuq|porn|pussies|pussy|spunk|xxx)/i"; $spamwords = "/(viagra|phentermine|tramadol|adipex|advai|alprazolam|ambien|ambian|amoxicillin|antivert|blackjack|backgammon|texas|holdem|poker|carisoprodol|ciara|ciprofloxacin|debt|dating|porn)/i"; $bots = "/(Indy|Blaiz|Java|libwww-perl|Python|OutfoxBot|User-Agent|PycURL|AlphaServer)/i"; if (preg_match($bots, $_SERVER['HTTP_USER_AGENT'])) { exit("<p>Known spam bots are not allowed.</p>"); } foreach ($_POST as $key => $value) { $value = trim($value); if (empty($value)) { if (($key != "company" && $key != "telNo")) { exit("<p>Please go back and complete the required fields.</p>"); } } elseif (preg_match($exploits, $value)) { exit("<p>Exploits/malicious scripting attributes aren't allowed.</p>"); } elseif (preg_match($profanity, $value) || preg_match($spamwords, $value)) { exit("<p>Please keep things clean, no naughty words!</p>"); } $_POST[$key] = stripslashes(strip_tags($value)); } if (!ereg("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,6})$",strtolower($_POST['email']))) { exit("<p>How can we reply if you don't provide us with a valid email address?</p>"); } $recipient = "[email protected]"; $subject = "Web Site Enquiry"; $message .= "Name: {$_POST['name']} \n"; $message .= "Company: {$_POST['company']} \n"; $message .= "Email: {$_POST['email']} \n"; $message .= "Tel: {$_POST['telNo']} \n"; $message .= "Message: {$_POST['message']} \n"; $headers .= "From: {$_POST['email']}"; if (mail($recipient,$subject,$message,$headers)) { echo "<meta HTTP-EQUIV=\"REFRESH\" content=\"0; url=$after\">"; } else { echo "<meta HTTP-EQUIV=\"REFRESH\" content=\"0; url=$oops\">"; } } ?>
-
Hi I've been using jQuery to validate my forms but one of my clients is starting to receive blank emails as some idiots are just turning off JS to bypass the validation. I have therefore found a PHP script to act as a back up which is working exactly as I want. The only problem is that it forces all fields to be completed and I like to add certain fields that don't necessarily need to be completed such as a Company field. So my question is how could I modify this script to allow the company field or any other that I decide to be left blank? The basic page can be viewed here http://www.qwerty-demos.co.uk/contact/ And this is the script <?php $after = "../thanks.html"; $oops = "../oops.html"; if (!isset($_POST['submit']) || $_SERVER['REQUEST_METHOD'] != "POST") { exit("<p>You did not press the submit button; this page should not be accessed directly.</p>"); } else { $exploits = "/(content-type|bcc:|cc:|document.cookie|onclick|onload|javascript|alert)/i"; $profanity = "/(beastial|bestial|blowjob|clit|cock|cum|cunilingus|cunillingus|cunnilingus|cunt|ejaculate|fag|felatio|fellatio|fuk|fuks|gangbang|gangbanged|gangbangs|hotsex|jism|jiz|kock|kondum|kum|kunilingus|orgasim|orgasims|orgasm|orgasms|phonesex|phuk|phuq|porn|pussies|pussy|spunk|xxx)/i"; $spamwords = "/(viagra|phentermine|tramadol|adipex|advai|alprazolam|ambien|ambian|amoxicillin|antivert|blackjack|backgammon|texas|holdem|poker|carisoprodol|ciara|ciprofloxacin|debt|dating|porn)/i"; $bots = "/(Indy|Blaiz|Java|libwww-perl|Python|OutfoxBot|User-Agent|PycURL|AlphaServer)/i"; if (preg_match($bots, $_SERVER['HTTP_USER_AGENT'])) { exit("<p>Known spam bots are not allowed.</p>"); } foreach ($_POST as $key => $value) { $value = trim($value); if (empty($value)) { if ($key != "email") { exit("<p>Please go back and complete the required fields.</p>"); } } elseif (preg_match($exploits, $value)) { exit("<p>Exploits/malicious scripting attributes aren't allowed.</p>"); } elseif (preg_match($profanity, $value) || preg_match($spamwords, $value)) { exit("<p>Please keep things clean, no naughty words!</p>"); } $_POST[$key] = stripslashes(strip_tags($value)); } if (!ereg("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,6})$",strtolower($_POST['email']))) { exit("<p>How can we reply if you don't provide us with a valid email address?</p>"); } $recipient = "my email address"; $subject = "Web Site Enquiry"; $message .= "Name: {$_POST['name']} \n"; $message .= "Email: {$_POST['email']} \n"; $message .= "Tel: {$_POST['telNo']} \n"; $message .= "Company: {$_POST['company']} \n"; $message .= "Message: {$_POST['message']} \n"; $headers .= "From: {$_POST['email']}"; if (mail($recipient,$subject,$message,$headers)) { echo "<meta HTTP-EQUIV=\"REFRESH\" content=\"0; url=$after\">"; } else { echo "<meta HTTP-EQUIV=\"REFRESH\" content=\"0; url=$oops\">"; } } ?>
-
Issue with giving anchor tags a class based on its file name
Ricky55 replied to Ricky55's topic in PHP Coding Help
Cheers lads, just used the pageID, as I had a few I've created an array to hold these. Working a treat. I know what I need to do in plain in english I just can't always turn that into PHP without some prompting. Cheers -
Hi Still very new to PHP but getting some good use out of it with includes. I'm currently using this code to check the file name of the page and then give the corresponding anchor tag a class of active in order to style my main menu. This is all working for most of my pages but my problem is that I now have multiple files called index.php one in the root of my site and some are in folders. Is there any way around this issue? Can PHP check to see if its the index file in the root of the site or is there a better way. I suppose I could create a second variable in the index file in my root ie my home page and then check to say if the current page is called index and has the variable of home but how would I write this? My code $currentPage = basename($_SERVER['SCRIPT_NAME'], '.php'); <li><a href="/" <?php if ($currentPage == 'index') {echo 'class="active"';} ?>>Home</a></li>
-
Hi I found this code on a blog that removes the .php extension from URL's. RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/$ $1.php RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$ RewriteRule (.*)$ /$1/ [R=301,L] I have changed my links to just point to <a href="/about-us">About Us</a> and the code does work for all files at the root level of the site but as soon as I link to any file thats in a folder the links no longer work. Any ideas as to why? I have the .htaccess file in my root folder btw. Thanks in advance. Richard
-
Can anyone tell me why I am getting this strange flicker on the two orange buttons below the main image? A developer wrote the js for me and he is telling me that he can't see the flicker but yet I am seeing it on all three of my macs. Can anyone else here see it? Only seems to happen in Safari on the Mac not tested in PC version, should I just put this down to a browser oddity or is it something that can be fixed? Any thoughts / suggestions will be greatly appreciated. Its only a small issue but its really annoying me. http://www.qwerty-demos.co.uk/products/knightsbridge/knightsbridge-range.php
-
is it best to do it with javascript?
-
Hi I have two pages that link to the same php file. This php file has a back button, how can I code the button so when the user clicks it takes them back to the page they were just viewing? Just like the browsers back button does. I already have a variable set up called $title that creates the page title from the file name is that helps. I want to say if previous page == page a then take the user back to page a and the same for page b I just don't know how to write the link. Sorry for asking for so much. Thanks
-
Yeah that's exactly what I wanted. I was just writing the code wrong. Still learning. Thanks very much!
-
Sorry I meant to say is there any way to say if in array 1 or in array2 then do something.
-
Hi I have two quite lengthly arrays made up of strings but quite a few bits of each array are repeated. I'm using one of the arrays to control the downstate of my navigation and the other to conditionally load a CSS file. Is there are way in a if statement to say if array 1 or array 2 then do something? I am currently checking one array by using this code <?php if (in_array($title, $rangePages)) { ?> <link rel="stylesheet" href="/css/range-viewer.css" media="screen"> <?php } ?> By the way my other array is called $forProdDownState
-
Check if in array but not include some values in the array
Ricky55 replied to Ricky55's topic in PHP Coding Help
That's exactly what I meant thanks very much. Its only a small CSS anyway but not point in loading it if it doesn't need to be loaded. Didn't know you could do nested statements like this (obviously) Thanks very much! -
Check if in array but not include some values in the array
Ricky55 posted a topic in PHP Coding Help
I have an array created to control the down states of the my buttons in my navigation. Which is working well. This array will have quite a few strings in it before I'm done. I then want to conditionally load a CSS file for all the files in that array with the exception of two, is this possible? In plain in english I want to say If in array apart from these values then load my css file. My array (will have more values when complete) $otherTitles = array('Product Selector', 'Avon Range', 'Knightsbridge Range', 'Kingston Range' ); My code to load a css file <?php if (in_array($title, $otherTitles)) { ?> <link rel="stylesheet" type="text/css" href="homepage.css"/> <?php } ?> I want all titles in the otherTitles array to get this CSS file apart from two Product Selector and Avon Range. Thanks Richard -
Best way to handle unique META Descriptions when using Includes
Ricky55 replied to Ricky55's topic in PHP Coding Help
Thanks guys I can feel better about using this method now. -
Best way to handle unique META Descriptions when using Includes
Ricky55 replied to Ricky55's topic in PHP Coding Help
Nothing really I'm just new to PHP and I always like to make sure I'm doing things the best way I can. I was asking more from a learning perspective. Thanks for replying. -
Hi I've been using includes for a while now but I'm just starting to do more with them. I'm currently working on a site where my header include brings in code from the doctype, includes my nav and then to the start of my opening wrapper div. I'm generating the page titles from the file names and I'm also using these to create my menu downstates. All is well but I was just wondering what the best practice was for creating unique meta data for each or at least some of the pages? Would I be best just creating a variable in each page and then echo out the meta data or is there a slicker way? Thanks in advance.
-
Just a short note to say thanks this worked great.