-
Posts
760 -
Joined
-
Last visited
Everything posted by joel24
-
the mysql IN statement works like so SELECT * FROM table WHERE id IN (12, 16, 13) in your case you need to organise the zip codes like so (zip1, zip2, zip3) so that MySQL can interpret it. you could use a foreach loop and write all the zips into a string like (zip1, zip2, zip3, zip4, etc etc). i.e. expanding on your code posted before <?php $zip = "-1"; if (isset($_GET['zip'])) { $zip = (get_magic_quotes_gpc()) ? $_GET['zip'] : addslashes($_GET['zip']); } mysql_select_db($database_connDB1, $connDB1) or die(mysql_error()); $z = new zipcode_class; $zips = $z->get_zips_in_range($zip, 10, _ZIPS_SORT_BY_DISTANCE_ASC, true); $sqlZips = ''; if ($zips === false) echo 'Error: '.$z->last_error; else { foreach ($zips as $key => $value) { //SQL STRING YOU CAN REMOVE single quote around $value if values are all numbers $sqlZips .= "'$value', "; } } //now SQL should work with IN command //this is from what you posted earlier //just modified (advertisers.zip_code IN ($sqlZips)) mysql_select_db($database_connDB2, $connDB2); $query_getCat = ("SELECT subcategories.subcategory, subcategories.cat_id, advertisers.adv_id, advertisers.zip_code, couponinfo.coupon_id FROM subcategories, advertisers, couponinfo WHERE (subcategories.subcat_id = advertisers.subcat_id OR subcategories.subcat_id = advertisers.subcat_id2) AND (advertisers.adv_id = couponinfo.adv_id) AND (advertisers.zip_code IN ($sqlZips)) ORDER BY subcategories.subcategory"); $getCat = mysql_query($query_getCat, $connDB2) or die(mysql_error()); //now do something with the query. ?>
-
they are the separate bits of code which definitely need changing, put this up the start of the script, somewhere before "if ($act==edit)" if (isset($_GET['act'])) { $act = $_GET['act']; } change if ($act==edit) { to if ($act=='edit') { and change } elseif ($act==teamlist) { to } elseif ($act=='teamlist') {
-
you have if ($act==edit) { and } elseif ($act==teamlist) { where is $act being set? You need to set $act. And you need to quote the strings i.e. 'edit' and 'teamlist' if (isset($_GET['act'])) { $act = $_GET['act']; } //code here //change ifs //i.e. if ($act=='edit') { //and } elseif ($act=='teamlist') { and then after that, you said after you click the edit button the url is "playerstats.php?act=editdo&PlayerID=1&stat=" You have no if if command to execute code if act = editdo.
-
the function sys_getloadavg() returns an array of the system load average 1 minute ago, 5minutes ago and 15minutes ago. You're code is not returning anything because it is not greater than 80, it returns the number of processes queued up for execution. You can do print_r(sys_getloadavg()); and it will return the array with those three values. You're code if if($load[0] > 80) will work, but only if the load avg 1 minute ago was > 80. You'll need to change 80 to a value which corresponds to a high system load on your server, and what that value is I don't know, you'll have to play around with it and find out.
-
you "don't know jack about PHP" and yet you have a site getting 6 or 7million hits per month? details for implementations and what values the function returns are here http://php.net/manual/en/function.sys-getloadavg.php
-
is get_zips_in_range() returning any values? try put in a print_r($zips) which will print all the values in the $zips array. i.e. <?php $zip = "-1"; if (isset($_GET['zip'])) { $zip = (get_magic_quotes_gpc()) ? $_GET['zip'] : addslashes($_GET['zip']); } mysql_select_db($database_connDB1, $connDB1) or die(mysql_error()); $z = new zipcode_class; $zips = $z->get_zips_in_range($zip, 10, _ZIPS_SORT_BY_DISTANCE_ASC, true); if ($zips === false) echo 'Error: '.$z->last_error; else { foreach ($zips as $key => $value) { echo "Zip code <b>$key</b> is <b>$value</b> miles away from <b>'$zip'</b>.<br />"; } } ?> and the zipcode class you're using requires a database table "zip_code" filled with zip codes. Have you got this database table setup?
-
there is a PHP function to check the system load sys_getloadavg(); as for a good host, I've always found dreamhost great. Reasonably priced, good uptime, easy to upgrade to a virtual private server and increase/decrease the power of that VPS.
-
... and as Thorpe said, your function returns $data, however, you're not passing a $data variable to the function. should be something like $data = "testing string"; //function code here echo in_this_instance($data);
-
are you getting any errors? is the script dying with your 'or die("ERROR MSG")' ?
-
you need to read the file with PHP (fopen, fread) then force its download googled a quick example here
-
I'd go for Azsen's solution. Try using ajax - jquery framework will be easiest form of ajax to use for this. This can load the html returned from a PHP file into a div on the page. You can script this to show a count down, then when it finishes load the PHP file to the div. The php can then check if the timeout has passed, through a session value showing the time when the download page was first clicked.
-
what are you trying to do?! have a look at the XML attribute foreach example here
-
try implement mysql_error() so you can see the error message if the query isn't functioning. Don't use or die() when the site is live for production, there are much nicer error reporting methods. i.e. <?php require_once ("dbconn.php"); ?> <?php $userID = $_SESSION['userID']; $insert_query = 'UPDATE users SET aim="' . $_POST['aim'] . '", msn="' . $_POST['msn'] . '", yim="' . $_POST['yim'] . '", psnID="' . $_POST['psnID'] . '", xblGamertag="' . $_POST['xblGamertag'] . '", otherContact="' . $_POST['otherContact'] . '", WHERE userID = $userID;' mysql_query($insert_query) or die(mysql_error()); ?> What does it say?
-
How can I test to see if a connection is closed?
joel24 replied to kjtocool's topic in PHP Coding Help
already answered on this thread -
you need to use an update query instead of insert.
-
Thorpe, just noticed your post count! Posts: 23,276
-
How to redirect CMS website ID extenstions to .HTML
joel24 replied to saash's topic in PHP Coding Help
you'll have to do some url rewriting. or another information source is here With url rewriting you can have www.domain.com/test.html point to www.domain.com/index.php?id=45 Although I'd recommend having a switch and having the id value in the url as a text string, i.e. id='home', or page='home' -
Need HELP! PHP code not working on a webserver
joel24 replied to oneplusdave's topic in PHP Coding Help
harristweed has pretty much summed it all up. You said "the script does generate an error", what's the error? #selects all data from table and displays it in textfields. If failed, it will display the error $sql = "SELECT * from tblquotes ORDER BY Rand() LIMIT 1"; $result = mysql_query($sql,$connection); if(mysql_num_rows($result) { $count =0; //while loop to cycle through results, not needed if you keep the limit to 1. //use a while loop instead of the while($count < $num) (with $count being a count of the results) loop you had before. while ($row = mysql_fetch_array($result)){ $q1 = $row['quote']; $q2 = $row['author']; } } else{ echo "ERROR: ".mysql_error(); } That is a more appropriate rendition of your code, however, I don't see what you're trying to do with the data pulled from the database table. In the code comment you say "and displays it in textfields", although you're not displaying any code in textfields? And if you were, it is cycling through all the rows of data and assigning the last row to the $q1 / $q2 variables. If you only want one row, you can just do $sql = "SELECT * from tblquotes ORDER BY Rand() LIMIT 1"; $query = mysql_query($sql); //don't have to loop result cause it's limited to one row. $result = mysql_fetch_array($query); //results are indexed into $result array. i.e. $quote = $result['quote']; $author = $result['author']; -
You're posting the form to the Test-Page html file and the include is not included by default, hence the PHP file is not being included and can't pick up any form posts. You need the form to post to url.com?page=contact, so the PHP file is included and can read the $_POSTs like so. action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>?page=contact"> or in full. <?php $your_email ='email@address';// <<=== update to your email address session_start(); $errors = ''; $name = ''; $visitor_email = ''; $visitor_website = ''; $user_message = ''; if(isset($_POST['submit'])) { $name = $_POST['name']; $visitor_email = $_POST['email']; $visitor_website = $_POST['website']; $user_message = $_POST['message']; ///------------Do Validations------------- if(empty($name)||empty($visitor_email)) { $errors .= "\n Name and Email are required fields. "; } if(IsInjected($visitor_email)) { $errors .= "\n Bad email value!"; } if(empty($_SESSION['6_letters_code'] ) || strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0) { //Note: the captcha code is compared case insensitively. //if you want case sensitive match, update the check above to // strcmp() $errors .= "\n The captcha code does not match!"; } if(empty($errors)) { //send the email $to = $your_email; $subject="New form submission"; $from = $your_email; $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; $body = "A user $name submitted the contact form:\n". "Name: $name\n". "Email: $visitor_email \n". "Website Update?: $visitor_website \n". "Message: \n ". "$user_message\n". "IP: $ip\n"; $headers = "From: $from \r\n"; $headers .= "Reply-To: $visitor_email \r\n"; mail($to, $subject, $body,$headers); // header('Location: thank-you.html'); } } // Function to validate against any email injection attempts function IsInjected($str) { $injections = array('(\n+)', '(\r+)', '(\t+)', '(%0A+)', '(%0D+)', '(%08+)', '(%09+)' ); $inject = join('|', $injections); $inject = "/$inject/i"; if(preg_match($inject,$str)) { return true; } else { return false; } } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Contact Us</title> <!-- define some style elements--> <style> label,a, body { font-family : Arial, Helvetica, sans-serif; font-size : 12px; } .err { font-family : Verdana, Helvetica, sans-serif; font-size : 12px; color: red; } </style> <!-- a helper script for vaidating the form--> <script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script> </head> <body> <?php if(!empty($errors)){ echo "<p class='err'>".nl2br($errors)."</p>"; } ?> <div id='contact_form_errorloc' class='err'></div> <form method="POST" name="contact_form" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>?page=contact"> <p> <label for='name'>Name: </label><br> <input type="text" name="name" value='<?php echo htmlentities($name) ?>'> </p> <p> <label for='email'>Email: </label><br> <input type="text" name="email" value='<?php echo htmlentities($visitor_email) ?>'> </p> <p> <label for='website'>Would you like to receive Website Update News? </label><br> <input type="radio" name="website" value='Yes <?php echo htmlentities($visitor_website) ?>' checked>YES <br> <input type="radio" name="website" value='No <?php echo htmlentities($visitor_website) ?>'>NO <br> </p> <p> <label for='message'>Message:</label> <br> <textarea name="message" rows=8 cols=30><?php echo htmlentities($user_message) ?></textarea> </p> <p> <img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' ><br> <label for='message'>Enter the code above here :</label><br> <input id="6_letters_code" name="6_letters_code" type="text"><br> <small>Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</small> </p> <input type="submit" value="Submit" name='submit'> </form> <script language="JavaScript"> var frmvalidator = new Validator("contact_form"); frmvalidator.EnableOnPageErrorDisplaySingleBox(); frmvalidator.EnableMsgsTogether(); frmvalidator.addValidation("name","req","Please provide your name"); frmvalidator.addValidation("email","req","Please provide your email"); frmvalidator.addValidation("email","email","Please enter a valid email address"); </script> <script language='JavaScript' type='text/javascript'> function refreshCaptcha() { var img = document.images['captchaimg']; img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000; } </script> </body> </html>
-
will need to see code
-
use the header() function. i.e. this line will redirect user to URL header('Location: ../includes/general/artdirector.php?position=top');
-
You'd be best off storing the values in a database, get a copy of this book if you're just starting out otherwise you'd have to use the fopen() function and the fwrite() function to edit a file... go with the database option
-
are you sure the code is not executing? the code you've posted is correct, are you setting the $item variable correctly? i.e this works $item = "i like steamboats"; if (strpos($item, 'boat') == true){ exit("'Boat' was found"); include("FoundInside.php"); } it will kill the script and echo 'Boat' was found when the string boat is found. Delete this line after you have that part of the code working then you can work on "FoundInside.php"
-
if ($time=$conf["hours_to_block_same_user_attacking"]*60*60; you don't close the bracket, and you shouldn't have a colon ending the if argument. i.e. if ($time=$conf["hours_to_block_same_user_attacking"]*60*60) { //code to execute if true }
-
.. why can't you?