Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
Valid points kenrbnsn. In this case, the form is sending only a single value. As for spoofing, I believe too many inexperienced programmers rely upon the fact that users don't directly "see" the posted data as a form of security - leading to code that can be easily compromised. I'm in agreement with you, I just took exception to the previous statement "Its better to use method post in your form". It's simply not true as it stands. There are many times when using GET is appropriate over POST. It's a pet peeve of mine when people make such statements and don't provide credible reasons for it.
-
Identify the checkbox that is checked, in a group of checkboxes
Psycho replied to help_lucky's topic in Javascript Help
I read your post a couple of times and really don't understand what your problem is. Escpecially since some of it just doesn't make sense. You say that you are working with JavaScript and PHP but your client doesn't support AJAX. - ??? If you can use both of those technologies you can use AJAX. In any event, I *think* you are making this more complicated than it needs to be (at least based upon what I think you are needing to do). First off, if you want to hide/display certain fields (and populate defaults) based upon a checkbox selection there isn't any need to do a subsequent PHP call to reload the page. Just put all the logic into your JavaScript. By the way, it sounds as if you should really be using two radio buttons - unless the user is allowed to select both checkboxes. Here is a very rough example: <html> <head> <script type="text/javascript"> function setServiceType(typeStr) { document.getElementById('return_info').style.display = (typeStr=='return') ? 'inline' : 'none'; document.getElementById('audit_info').style.display = (typeStr=='audit') ? 'inline' : 'none'; } </script> </head> <body> <b>Type of service:</b><br /> <input type="radio" name="service" value="return" onclick="setServiceType(this.value);" /> Tax return <input type="radio" name="service" value="audit" onclick="setServiceType(this.value);" /> Audit <br /><br /> <b>Contact Info</b><br /> Name: <input type="text" name="name" /><br /> Phone: <input type="text" name="phone" /><br /> Email: <input type="text" name="email" /><br /> <br /> <div id="return_info" style="display:none;"> <b>Please provide the following info for the return service requested:</b><br /> Tax Year: <input type="text" name="year" value="2009" /><br /> State: <input type="text" name="state" /><br /> <input type="checkbox" name="newhome" /> Check here if you are a new home buyer. </div> <div id="audit_info" style="display:none;"> <b>Please provide the following info for the audit service requested:</b><br /> Fiscal Year end date (mm/dd): <input type="text" name="year" value="12/31" /><br /> Type of business: <input type="text" name="state" /><br /> </div> </body> </html> -
OK, but you still haven't supplied a valid reason for stating "Its better to use method post in your form". That fact that someone assumed he used POST doesn't mean he should have used POST. Based upon the code posted, the form consists of a single value: "name_id". So, the address will look something like "selectday.php?name_id=xxx". Although the user would be selecting the value in a form, it makes perfect sense to use GET. That way the processing page can be repurposed to use direct links if needed/wanted.
-
And what do you base that on? There's nothing inherently wrong with using GET. Although I do prefer to use POST most of the time so the address doesn't get messy.
-
Assuming you see values in the drop-down the query is apparently not failing. Have you verified that the options actually have values? Do a view source on the HTML page to see if the $year_id is getting set correctly. [edit]OK: on looking at the code again you have TWO select fields. The first one at the top has no name and is not closed until after the second select list. Also, your first option has no closing tag. The problem is incorrectly formatted HTML <?php //connect to MySQL $connect = mysql_connect("localhost","root","") or die ("Could not connect to database."); //choose the database mysql_select_db("lakeside"); //Query from database $sql = "SELECT year_id, year FROM years"; $result = mysql_query($sql); $options="<option value=\"0\">Choose Year Group</option>\n"; while ($row=mysql_fetch_array($result)) { $options .= "<option value=\"{$row['year_id']}\">{$row['year']}</option>\n"; } ?> <form action="selectday.php" method="get"> <select name="year_id"> <?=$options?> </select> <input type="submit" /> </form>
-
It is not AJAX specific. You just have to be careful about your naming in JS. I run into the same problem every so often when I accidentally give a function the same name as an object ID.
-
If I am understanding you correctly the post data will have the old client ID and a (possibly) new client ID. And you are wanting to update the client ID if there was a new one submitted. You would just need a single query to the effect UPDATE table SET client_id = '$newID' WHERE client_id = '$oldID' If you need to ensure there are no duplicates, just do a query before that to see if the new ID already exists or not.
-
I think what you are after is more of a CSS/Style issue than a JavaScript issue. The JavaScript is very simple. Here's a working example: <html> <head> <style> #imgControl { width:350px; height:300px; } #imgDisplay { width: 350px; height: 225px; text-align: center; border: 1px solid #000000; } #imgList { width: 350px; height: 75px; overflow: auto; white-space: nowrap; border: 1px solid #000000; } .thumb { height: 45px; width:45px; } </style> <script type="text/javascript"> function showImage(imageName) { var path = 'images/'; //path to images folder var imgObj = document.getElementById('displayedImg'); imgObj.src = path + imageName; return; } </script> </head> <body> <div id="imgControl"> <div id="imgDisplay"> <img src="blank.jpg" id="displayedImg" /> </div> <div id="imgList"> <a href="#" onclick="showImage('image1.jpg');"><img src="images\thumbs\thumb1.jpg" class="thumb" /></a> <a href="#" onclick="showImage('image2.jpg');"><img src="images\thumbs\thumb2.jpg" class="thumb" /></a> <a href="#" onclick="showImage('image3.jpg');"><img src="images\thumbs\thumb3.jpg" class="thumb" /></a> <a href="#" onclick="showImage('image4.jpg');"><img src="images\thumbs\thumb4.jpg" class="thumb" /></a> <a href="#" onclick="showImage('image5.jpg');"><img src="images\thumbs\thumb5.jpg" class="thumb" /></a> <a href="#" onclick="showImage('image6.jpg');"><img src="images\thumbs\thumb6.jpg" class="thumb" /></a> <a href="#" onclick="showImage('image7.jpg');"><img src="images\thumbs\thumb7.jpg" class="thumb" /></a> <a href="#" onclick="showImage('image8.jpg');"><img src="images\thumbs\thumb8.jpg" class="thumb" /></a> <a href="#" onclick="showImage('image9.jpg');"><img src="images\thumbs\thumb9.jpg" class="thumb" /></a> </div> </div> </body> </html>
-
@dbk, That process doesn't make sense. Why would you want to get all the clinet_id's not equal to a ccertain value and then do a search for a specific client_id? Why not just do a query for the client_id you are looking for?
-
It sounds like you are tying to derermine the page based upon the starting index. That's sbackwards. You should use the page number and records per page to determine the starting index: $startingIndex = ($page-1) * $recordsPerPage ); Although, If you have a current index and the records per page changes, you can determine the new page to display (based upon the previously viewed index) as follows: $page = floor(($oldIndex+1) / $recordsPerPage); $startingIndex = ($page-1) * $recordsPerPage );
-
OK, that is something different than what I thought you were saying originally. So, according to what you just said, the images are the same for all users at a specific time of day? I think that is actually an easier implemetation as you wouldn't need to store a session variable and do that calculation.
-
Not 100% sure what you are asking. If you want the image to change while the user is viewign the page, then you will need to use javascript (possibly AJAX). However, if you only want to dynamically detemine what image to display when the page loads, then you would only need PHP. Having said that I will interpret what I think you are asking. I think you are wanting the images to rotate through a fixed list (change every 30 seconds while the user is viewing the page). But, when the user refreshes the page the images should start at the position it left off and not start at the beginning again. Personally, I think that is just overcomplicating things. I'd just hae it display the images randomly and not worry about which ones were viewed previously. But, what you are asking is possible. I think the easiest solution is to simply set a session variable when the suer first accesses the site and set the time of that access as the value. You can then determine which image to display at any point in time using the following calculation: $imgIndex = floor((time() - $_SESSION['acess_time'])/30); You can use that on each page load to detemine the correct image and you can also have a javascript function that will get the next image. But, you wouldn't need to utilize a full-fledged AJAX routine. All you need to do is set the image src to a php page that will determine the correct image to display and then have a javascript function to recall that page as the source of the iamge every 30 seconds. Example PHP page: <?php session_start(); if(!isset($_SESSION['acess_time'])) { $_SESSION['acess_time'] = time(); } $images = array( "aaaa.jpg", "bbbb.jpg", "cccc.jpg" ); $time = time(); $imgIndex = floor(($time-$_SESSION['acess_time'])/30) % count($images); $image = $images[$imgIndex]; header("Location: {$image}"); ?> Usage in the HTML page: <html> <head> <script type="text/javascript"> function imgRotate() { var imgObj = document.getElementById('rotate'); imgObj.src = "http://localhost/test/test.php?"+Math.random(); } window.onload = function() { setInterval ( "imgRotate()", 30000 ); } </script> </head> <body> <img id="rotate" src="http://localhost/test/test.php" /> </body> </html> Note: the random number appended to the src is needed so the browser sees it as a different request than the previous one. Otherwise it "thinks" you are requesting the same image and it will use the one in the cache.
-
Perfect Canonical Link | Need Help Altering Syntax
Psycho replied to Bryan Hadaway's topic in PHP Coding Help
function canlink() { $request_uri = parse_url($_SERVER['REQUEST_URI'],PHP_URL_PATH); echo "<link rel=\"canonical\" href=\"http://{$_SERVER['HTTP_HOST']}{$request_uri}\" />"; } -
Seems logical to me. There are a lot more calcualtions/assignements going on in option A. Option A: - The for loop must do a check of var $a on each iteration - The fread operator is used - An assignment is made to the var $b - a concatenation is made on the var $r - A ternary operator is used to make an assignement to the var $a Option B: - a check is made on each iteration to see if the end of file is reached - fgets() is run - a concatenation is made on the var $r By the way, running a ternary operator on each iteration in option A is less efficient than doing a single IF statement because an assignment must be made on each iteration. I aslo don't know whay you would use 0 and 1 for the values instead of a boolean true/false. Then you could have done this: $a=empty($b); A more efficient approach would be to assign $a before the loop and jsut use a single IF statement. Then if the condition is false that code is never run. Additionally, for heaven's sake, give your variables descriptive names. Using $a, $b, $r just makes maintenance and debugging much harder.
-
Guidance sought - Clear form field when user begins entering data
Psycho replied to Chezshire's topic in Javascript Help
You are putting a condition on an else statement. An "else", by itself, means if all else fails do this. You need change that to an "else if". Also the error on that line is the same as the one before it. So what is different ebtween empty() and isOK()? -
is there a way to create a jpg of an entire web page?
Psycho replied to aebstract's topic in PHP Coding Help
I'm in total agreement with igance. Almost no one uses CSS to its true potential. By specifying different style properties for the "print" media type in the CSS you can build the page in such a way that is looks how you want it when displayed in the browser and has a different structure when printed so it fits on the page as needed. Whenever I travel for work, I always print out the confirmation page at the end of the booking process. But important data is always cut off on the right side of the printed page because the left hand menu on the HTML page is being printed too. There is no reason to include menu's in a printed page and it is VERY easily avoided. There have been several related posts on these forums in the past where I have responded with sample code. If you want to go this route you can do a search of those posts to get an idea on how it can be done. -
build a checkbox list based on selection of drop down form field
Psycho replied to svgmx5's topic in Javascript Help
I would just build all of the checkbox lists and then use style properties to show/hide the appropriate lists. Example: <html> <head> <script type="text/javascript"> function showList(selectObj) { var lists = new Array('cars', 'computers', 'sports'); var selectedListID = selectObj.options[selectObj.selectedIndex].value; var divObj; for(i=0; i<lists.length; i++) { divObj = document.getElementById(lists[i]); divObj.style.display = (selectedListID==lists[i]) ? '' : 'none'; } return; } window.onload = function() { showList(document.getElementById('listType')); return; } </script> </head> <body> <select name="listType" id="listType" onchange="showList(this);"> <option value="cars">Cars</option> <option value="computers">Computers</option> <option value="sports">Sports</option> </select> <br /> <div id="cars"> <input type="checkbox" name="cars[]" value="Honda"> Honda<br /> <input type="checkbox" name="cars[]" value="Ford"> Ford<br /> <input type="checkbox" name="cars[]" value="Toyota"> Toyota<br /> </div> <div id="computers"> <input type="checkbox" name="computers[]" value="Dell"> Dell<br /> <input type="checkbox" name="computers[]" value="HP"> HP<br /> <input type="checkbox" name="computers[]" value="Alienware"> Alienware<br /> </div> <div id="sports"> <input type="checkbox" name="sports[]" value="Football"> Football<br /> <input type="checkbox" name="sports[]" value="Basketball"> Basketball<br /> <input type="checkbox" name="sports[]" value="Baseball"> Baseball<br /> </div> </body> </html> -
When you do a header() to redirct to another page it is considered a new request from the server - POST values are not sent. Instead, you should simply do an include. Here is the page with that correction and a little more rewrite as well. <?php header("Cache-Control: no-cache, must-revalidate"); header("Expires: Fri, 31 Dec 1999 00:00:00 GMT"); include('/inc/db.php'); $email_msg = ''; if (!empty($_POST)) { $email = trim($_POST['email']); $sql_email = mysql_real_escape_string($email); $query = "SELECT email FROM table WHERE email = '{$sql_email}'"; $result = mysql_query($query); $check = mysql_num_rows($result); if ($check > 0) { $email_msg = "<label for='email' class='error'>This email address is already in use</label>"; //The following lines should NOT use mysql_real_escape_string() as they //will change the values if any characters are escaped. Instead, you //should use trim $forename = trim($_POST['forename']); $surname = trim($_POST['surname']); $username = trim($_POST['username']); $password = trim($_POST['password']); $password2 = trim($_POST['password2']); $email = trim($_POST['email']); $dob = trim($_POST['dob']); } else { // register_db.php doesn't receive a value for $_POST['forename'] or any of the other fields include('/inc/register_db.php'); exit(); } } ?> <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <script type="text/javascript" src="/js/jquery-1.3.2.min.js"></script> <script type="text/javascript" src="/js/jquery.validate.pack.js"></script> <link rel="stylesheet" type="text/css" media="projection, screen" href="/css/ui-lightness/jquery-ui-1.7.2.custom.css" /> </head> <body id="register-body"> <div id="page-header"> <div id="logo"> <h1><a accesskey="1" href="index.php">HOMEPAGE</a></h1> </div> </div> <div id="register-page"> <form id="register-details" method="post" action="/inc/register_db.php"> <div id="column1"> <h3><label for="forename">FORENAME</label></h3> <input type="text" id="forename" name="forename" class="required" tabindex="1000" value="<?php $forename; ?>" /> <br /><br /> <h3><label for="surname">SURNAME</label></h3> <input type="text" id="surname" name="surname" class="required" tabindex="1010" value="<?php $surname; ?>" /> <br /><br /> <h3><label for="username">USERNAME</label></h3> <input type="text" id="username" name="username" class="required" tabindex="1020" value="<?php $username; ?>" /> <br /><br /> <h3><label for="password">PASSWORD</label></h3> <input type="password" id="password" name="password" class="required" tabindex="1030" value="<?php $password; ?>" /> <br /><br /> <h3><label for="password2">RETYPE PASSWORD</label></h3> <input type="password" id="password2" name="password2" class="required" tabindex="1040" value="<?php $password2; ?>" /> <br /> </div> <div id="column2"> <h3><label for="email">EMAIL ADDRESS</label></h3> <input type="text" id="email" name="email" class="required email" tabindex="1050" value="<?php $email; ?>" /> <?php $email_msg; ?> <br /> </div> <div id="column3"> <h3><label for="country">LOCATION</label></h3> <select id="country" name="country" class="required" tabindex="1060"> <option value="">Please select</option> <option value="1">United Kingdom</option> <option value="2">United States</option> <option value="3">Canada</option> </select><br /> </div> <div id="column4"> <h3><label for="dob">DATE OF BIRTH</label></h3> <input type="text" id="dob" name="dob" class="required date" tabindex="1070" value="<?php $dob; ?>" /> <br /> <input type="submit" id="register-button" name="register-button" value="register!" /> </div> </form> </div> </body> </html>
-
By the way, you have some poorly written javascript on your site. When I hover over a forum listing my CPU usage for IE jumps up to almost 50% for a half second - then the forum listing gets highlighted. That main page is VERY sluggish because of this.
-
You should create the query as a string variable and then execute the query. This allows you to echo the query to the page when needed for debugging purposes. You also have no error handling on your query. So, it is likely failing, but you have no way of knowing. I see at least two definit problems and a few possible problems. In the defined fields list there are two fields listed that should be one: ...,receiver,email,... Based upon the values you are using I think that should be a single field called "receiver_email". Also, in the values to populate in the database you have more values defined than you have fields. The last for values are not in the defined list. I found it pretty easy when I was reformmatting the code into a more logic format. If you follow some sort of standard these types of problems are easily avoided. <?php if($p->ipn_data['receiver_email']=='donations@nmdgaming.com') { //Prepare values $tax_id = esc($p->ipn_data['txn_id']); $item_number = esc($p->ipn_data['item_number']); $first_name = esc($p->ipn_data['first_name']); $last_name = esc($p->ipn_data['last_name']); $payer_email = esc($p->ipn_data['payer_email']); $amount = (float) ($p->ipn_data['mc_gross']-$p->ipn_data['mc_fee']); $mc_gross = esc($p->ipn_data['mc_gross']); $mc_fee = esc($p->ipn_data['mc_fee']; $receiver_email = esc($p->ipn_data['receiver_email']); $payment_type = esc($p->ipn_data['payment_type']); $payment_status = esc($p->ipn_data['payment_status']); $payment_date = esc($p->ipn_data['payment_date']); $payer_business_name = esc($p->ipn_data['payer_business_name']); $payer_status = esc($p->ipn_data['payer_status']); $residence_country = esc($p->ipn_data['residence_country']); $mc_currency = esc($p->ipn_data['mc_currency']); $payer_id = esc($p->ipn_data['payer_id']); $receiver_id = esc($p->ipn_data['receiver_id']); //Create query $query = "INSERT INTO donations (`txn_id`, `item_number`, `first_name`, `last_name`, `payer_email`, `amount`, `mc_gross`, `mc_fee`, `receiver_email`, `payment_type`, `payment_status`, `payment_date`, `payer_business_name`, `payer_status`, `residence_country`, `mc_currency`, `payer_id`, `receiver_id`) VALUES ('{$tax_id}', '{$item_number}', '{$first_name}', '{$last_name}', '{$payer_email}', '{$amount}', '{$mc_gross}', '{$mc_fee}', '{$receiver_email}', '{$payment_type}', '{$payment_status}', '{$payment_date}', '{$payer_business_name}', '{$payer_status}', '{$residence_country}', '{$mc_currency}', '{$payer_id}', '{$receiver_id}')"; //Execute query $result = mysql_query($query) or die("Error:<br />".mysql_error()."<br />Query:<br />$query");; } ?>
-
What's better, a lot of JS files or one large file?
Psycho replied to Flames's topic in Javascript Help
My take: Have separate files for "categories" of JavaScript functions. For example, I will have function for form processing in one file and only load that file on the pages with forms. -
is there a way to create a jpg of an entire web page?
Psycho replied to aebstract's topic in PHP Coding Help
Are you wanting to do this as a PHP process for the user to get an image of the page they are viewing? If so, then there are 3rd party application for this. but,they cost money and you would have to have it installed on the server. If you are wantng this so YOU can print a page you are viewing, then there are utilities for that as well - but this is the wrong forum for such a question. -
I see the problem - it was a typo. I used $row when getting the record data, but used $rows when processing it. Change the while loop to this: while($row = mysql_fetch_assoc($result)) { $images .= createImageHTML($row['Title'], $row['Picture'], $idx); $idx++; }
-
No need to do two queries. Just do one query to get the records and check the number of records returned. Also, you are giving multiple divs the exact same ID, you can't do that. Here is a more logical approach <?php include("Config.php"); function createImageHTML($title, $src=false, $idx=false) { $divID = ($idx!==false) ? "carousel_images_{$idx}" : 'carousel_images'; if(!$src) { $src = '../Gallery_Images/Default.jpg'; } $html = "<li>\n"; $html .= " <div id=\"{$divID}\">\n"; $html .= " <a href=\"#\"><img src=\"{$src}\" alt=\"{$title}\" /></a>\n"; $html .= " </div>\n"; $html .= "</li>\n"; return $html; } $User_id = mysql_real_escape_string(trim($_GET['id'])); $query = "SELECT * FROM biggartfp9_gallery_itemst WHERE User_id='$User_id' ORDER BY Date_added DESC LIMIT 10"; $result = mysql_query($query); $images = ''; if(mysql_num_rows($result)<1) { //There were no results, show 'coming soon image' $images = createImageHTML("Artwork Coming Soon"); } else { //There were results, create image links $idx = 0; while($row = mysql_fetch_assoc($result)) { $images .= createImageHTML($rows['Title'], $rows['Picture'], $idx); $idx++; } } mysql_close(); ?> <br /> <div class="content_box"> <div class="content_box_h">Latest Artwork</div> <div class="content_box_carousel"> <div id="slider"> <ul> <?php echo $images; ?> </ul> </div> </div> </div>
-
Yes, you can use ANY kind of comparison in a CASE statement - you just have to be creative. Remember the case value must match the switch value. So, just use the boolean true for the switch value and the comparisons as the case value Example switch(true) { case ($num>50 && $num<150): //action goes here break; case ($num>=150 && $num<300): //action goes here break; }