Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
Extracting data from Multi dimensional array
Psycho replied to williamZanelli's topic in PHP Coding Help
What is printed to the page when you run this? <?php $array = unserialize($array_field1); print_r($array); foreach ($array as $subarray){ echo ", <a href=\"{$subarray['category_name']}\">{$subarray['category_safe_name']}</a>"; } ?> -
Extracting data from Multi dimensional array
Psycho replied to williamZanelli's topic in PHP Coding Help
You are using a counter starting at 0 and incrementing by 1 to determine the key. But, from the serialized value it appears the array isn't using 0,1, 2, ... as the key values. You should be using foreach() instead. Also, you are using [category_safe_name] to extract one of the values. That text should be enclosed in quotes unless that is a constant. <?php foreach ($array as $subarray){ echo ", <a href=\"{$subarray['category_name']}\">{$subarray['category_safe_name']}</a>"; } ?> -
This: fuction verify_data(){ Should be this: function verify_data(){
-
Where is $subphone first set? The first time I see it used you are trying to set it based upon it's already set value (which would be nothing?): $subphone = stripslashes($subphone); Is that supposed to be this: $subphone = stripslashes($_POST['phone']); Can you give an example of a value that your code does not work with? If you are stating that a single zero is generating the error for not entered, then the problem is as thatsgreat2345 suggests. In that case you would want to use isset(): if(!isset($_POST['phone']))
-
Well, AttemptLogin() is going to be a JavaScript function. Did you look at the function to see what it does?
-
any other way to do this besides a bunch of ifs?
Psycho replied to nelsok's topic in PHP Coding Help
Yes you can use a ternary in a string and, yes, you must enclose it in parens like wildteen88 states. I was trying to post that code right as I was finishing up for the night whic his why I had the errant semi-colon and did not enclse it in parens. I also typically set a variable using the ternary operator before the string. But, I also try to refrain from creating variables on one line if they are only used once on the next line. But, readability is a valid concern. -
any other way to do this besides a bunch of ifs?
Psycho replied to nelsok's topic in PHP Coding Help
Create the links programatically and it will be much easier. <?php $uri = explode("/", $_SERVER['REQUEST_URI']); print_r($uri); print($uri[1]); $linksAry = array ( 'Home' => '', 'Services' => 'services', 'Solutions' => 'solutions', 'Technology' => 'technology', 'Quote' => 'quote', 'Company' => 'company', 'Contact Us' => 'contact', 'Work Profile' => 'profile' ); echo "<ul id=\"nav\">\n"; foreach ($linksAry as $name => $href) { echo "<li><a href=\"$href\" class=\"" . ($uri[1]==$href)?'current':''; . "\">Home</a></li>\n"; } echo "</ul>\n"; ?> [/ode] -
any other way to do this besides a bunch of ifs?
Psycho replied to nelsok's topic in PHP Coding Help
Can you explain that again? Because you just said that you want solution_class="current" for both (and presumably all) conditions, so why not just assign it that to begin with, no conditions at all? But I'm assuming that's not really what you meant. I had to reread it to see the logic as well. Look closely it is "services" class and "solutions" class. eval is a possibility, but I think eval is the lazy, unsecure method in most all scenarios. -
what do these image names have in common - they aren't displaying!
Psycho replied to kate_rose's topic in PHP Coding Help
I have a feeling this is your problem: Are you absolutely sure there are no leading or trailing spaces in the value you are pasting into the database??? Try this: <?php $imagepath = trim($_SESSION['image_path']); echo "<img src=\"$imagepath\"/>"; echo $imagepath; ?> Although you should really clean up the data in the database if that is the problem. -
As I suspected the values for the variables were never set! Base upon your Reply #4 you are posting a form to this particular page. I see where you are apparently including the YEAR in a hidden loastlogin field. How are you setting $lastlogin with that value? Are you assuming register globals is on? In any event I wouldn't use a hidden field, just let PHP set it when the query is run. You aren't using the right references to get the vlues from the form POST and you are not extracting the values from the 1st query. Try this: <?php $account_number = mysql_real_escape_string($_POST['account_number']); $account_key = mysql_real_escape_string($_POST['account_key']); $query = "SELECT * FROM register_account WHERE account_number='$account_number' AND account_key='$account_key' AND status='1' "; echo "Query 1: $query<br>"; $sqllog=mysql_query($query) or die (mysql_error()."<br>$query"); if (!mysql_num_rows($sqllog)) { echo "Error user does not exist!"; } else { $user = mysql_fetch_assoc($sqllog); //I am making an assumption that the column name is id $query = "UPDATE register_account SET lastlogin= '".date("Ymd")."' where id='".$user['id']."'"; echo "Query 2: $query<br>"; $sqllog=mysql_query($query) or die (mysql_error()."<br>$query"); } ?>
-
You never replied with a response from the code I provided in Reply#3. That code will echo to the page the exact content of your query. I am betting that either one or both of those variables are not set. But, I cannot magically deduce all of the included code that I cannot see to tell how those variables are set. Please post the output of the code I posted in Reply#3 with it inserted into the current page where the queries currently reside.
-
only during production. And get rid of them once everything is working correctly No, you should ALWAYS have error handling - period. How you implement that error handling can be different during development (e.g. echo'ing the error directly to the page) than in production where you should show a "friendly" error message to the user and save the actual error to a log file or some other back-end reporting repository. Not sure what your experience has been. But in my 10 years in software a product is in "production" when you release it to the end-user.
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <script type="text/JavaScript"> <!-- function ValidateForm(form){ var ErrorText; if ( form.elements['age'].selectedIndex == 0 ) { ErrorText = "Please select your Age."; } if (ErrorText) { alert(ErrorText); return false; } return true; } --> </script> </script> </head> <body> <form name="feedback" action="" method="post" onSubmit="return ValidateForm(this);"> Your Age: <select name="age"> <option value="">Please Select an Option:</option> <option value="0-18 years">0-18 years</option> <option value="18-30 years">18-30 years</option> <option value="60+ years">60+ years</option> </select> <input type="submit" name="SubmitButton" value="Submit"> <input type="reset" value="Reset"> </form> </body> </html>
-
Exactly! Well, I still don't see where $id is being set. Did you run that last block of code I posted? What was printed to the page?
-
Interesting. Are you putting the return true at the very end of the friendConfirmedSearchPage() function or at the end of the onreadystatechange function?
-
To hide/show the auto-suggestion box I would use an onfocus and onblur event for the search box which changes the display property of the auto-suggestion box. For up and down arrow functionality you will need to trap the keystrokes and identify when the up or down arrow is selected and manually change the selected value. Here is a sample script for capturing keystrokes: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html> <head> <title>test</title> <script language="javascript"> var altKey = false; function init() { var oinputs = document.getElementsByTagName('input'); for (var i = 0; i < oinputs.length; i++) { oinputs[i].onkeydown = function (e) { e = e || event; switch (e.keyCode) { case 9: // tab // enter whatever you want to happen if the user hits tab // while that input is in focus alert('you hit tab'); return false; //Prevents tabbing to next field break; case 13: // enter alert('you hit enter'); return false; //Prevents submitting a form break; case 18: // alt // same for the enter button altKey = true; break; case 81: // alt // same for the enter button if (altKey) { alert('Alt-q'); } break; default: // the rest of the keys break; } } oinputs[i].onkeyup = function (e) { e = e || event; switch (e.keyCode) { case 18: // alt // same for the enter button altKey = false; break; } } } } </script> </head> <body onload="init()"> <input type="text" name="1"/> <input type="text" name="2"/> <input type="text" name="3"/> </body> </html>
-
A warning is just that - a warning. It is good practice to always explicitly do a return in my opinion. But, if you have a function that does not need to return anything there is no reason you HAVE to have it return something. I think the warning is there in case you have a function that is supposed to return something there may be a specific branch of th elogic that doesn't - that would be a problem that needs to be fixed. I have not done any testing in FF3, but would be interested to see a specific function that does not work by adding a return statement.
-
A Goolge search for "textarea insert text" brought up this result: http://www.webmasterworld.com/forum91/4686.htm Here a working example with modified code from that page: <html> <head> <script type="text/javascript"> <!-- function insertAtCursor(fieldID, myValue) { fieldObj = document.getElementById(fieldID); if (document.selection) { //IE support fieldObj.focus(); sel = document.selection.createRange(); sel.text = myValue; } else if (fieldObj.selectionStart || fieldObj.selectionStart == '0') { //Mozilla/Firefox/Netscape 7+ support var startText = fieldObj.value.substring(0, fieldObj.selectionStart); var endText = fieldObj.value.substring(fieldObj.selectionEnd, fieldObj.value.length); fieldObj.value = startText + myValue + endText; } else { //Unable to insert at current position - add to end of current value fieldObj.value += myValue; } } //--> </script> </head> <body> <a href="#" onclick="insertAtCursor('usertext','[contact]')">[contact]</a> <a href="#" onclick="insertAtCursor('usertext','[date]')">[date]</a> <br> <textarea id="usertext"></textarea> </body> </html>
-
I never stated my code would fix the problem. What it would do is show you if there were any errors in the query. You didn't answer the previous questions though: 1. What is the purpose of the SELECT query since you don't use the results 2. (more importantly) Where are the values for $lastlogin and $id being set? When you included the code I posted did you get any errors? If so, what were they. Assuming you didn't get any errors I would echo the query to the page so you can verify the values of $lastlogin and $id. <?php $query = "SELECT * FROM register_account WHERE account_number='$account_number' AND account_key='$account_key' AND status='1' "; echo "Query 1: $query<br>"; $sqllog=mysql_query($query) or die (mysql_error()."<br>$query"); $query = "UPDATE register_account SET lastlogin= '$lastlogin' where id='$id'"; echo "Query 2: $query<br>"; $sqllog=mysql_query($query) or die (mysql_error()."<br>$query"); ?> This will NOT fix anything it will only help troubleshoot the problem. When having problems such as this you should always verify that variables have the values that you expect and that processes are not failing.
-
That code doesn' make sense to me. First you do a SELECT query and assign it to the variable $sqllog, then in the next line you do an INSERT queryand assign the results to the same variable. What's the point of the SELECT query? Since you immediately overwrite the pointer to the SELECT results you cannot use them. In the UPDATE query where are $lastlogin and $id being set? You should always add error handling to your queries: <?php $query = "SELECT * FROM register_account WHERE account_number='$account_number' AND account_key='$account_key' AND status='1' "; $sqllog=mysql_query($query) or die (mysql_error()."<br>$query"); $query = "UPDATE register_account SET lastlogin= '$lastlogin' where id='$id'"; $sqllog=mysql_query($query) or die (mysql_error()."<br>$query"); ?>
-
Typically I see an INSERT commands that first list the field names and then the values. Your query is missing the field names: INSERT INTO images (field1, field2, field3, field4) VALUES ('739-736-444736.jpg', '80232', '.jpeg', 'ÿØÿà\0JFIF\0\0\0d\0d\0\0ÿì\0Ducky\0\0\0\0\0<\0\0ÿî\0Adobe\0dÀ\0\0\0ÿÛ\0„\0
-
At the very least the parameters for mysqli_query() need to be switched, but you should also add some error handling as well. mysqli_query($sql, $mysqli) or die (mysql_error());
-
There are a few problems with that code. 1. The setTimeout function is called like this setTimeout(MyTimer, 1000); Note there are no brackets following the function name. 2. Your variables only have local scope. The min, sec & first variables are renewed each time the function runs. So, even if you fixed item #1 you would see 3 minutes constantly because each call to the function would have it thinking it was the first time run. 3. When reducing the seconds at the end of a minute you need to go to 59 seconds not 60. (Ex: if you have 2 minues and 0 seconds and take away one second you have 1 minute and 59 seconds, not 1 minute and 60 seconds)
-
@delickate, You posted JavaScript not PHP. Which are you wanting: a PHP validation or a JavaScript validation? There is no "checked" property on a POSTed value in PHP.
-
Well, a quick look at the js file and I saw one erro right off th ebat: xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4) { document.getElementById('testDIV'). innerHTML = xmlHttp.responseText; } } There is an errant space in the reference to the div object.