
siamsam
Members-
Posts
21 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
siamsam's Achievements

Newbie (1/5)
0
Reputation
-
login script with redirect to previous url help
siamsam replied to siamsam's topic in PHP Coding Help
Thanks for the quick replies, but I think maybe I was not clear in my original post. The restricted pages redirect to the login.php page via a header if not already logged in. The problem I am having is that once they get to the login.php page, I want them to be sent back to the restricted page that sent them after they log in successfully. Since login.php processes itself, if they enter in the wrong username and pass, login.php is displayed again with a message saying they entered the wrong username and password. At that point, the referring url is login.php (from login attempt #1) - so if the second attempt to login is successful and I use javascript to go back 1 page...they will be sent to login.php (from login attempt #1 - which is actually the referring page...just not the initial referrer being the restricted page. It would have to go back 2 pages in order to get back to the restricted page, or 3 pages if they have 2 failure attempts at logging in. I am thinking I need to hold the value of the original url (the restricted page) in a session or something so it will refer back to that page no matter how many log in attempts they make. Does this make more sense...or did I confuse everyone more? lol. -
Hey freaks! I have run into a bit of a snag and need a little guidance from the wise ones. I have a login script that users are redirected to if they land on restricted pages of my site. Initially, I used javascript (go back (-1) to get the user back to the page they were previously on after logging in - which worked fine...but only if they got their login credentials right the first time (which will probably never happen that often). The login form processes itself, so if they get it wrong, it comes back to login.php. I noticed that when I test logging in and purposely enter the wrong information, when I do enter the right info the login page comes back up because it was the previous url. I am not a big fan of JS and I am still fairly new to PHP, so I am not sure how to do this. I tried setting a session for the previous url using http referer (if the url did not equal login.php), but it did not like that at all! Undefined index, headers already sent, you name it...I got the error... I can post my code if need be, but it is just a basic login script (with a lot of Dreamweaver mumbo jumbo) that checks the username and pass in mysql. Any suggestions? Should I use a session for this? Or is it probably one of those switch statements that I am not remotely close in knowledge to writing myself...lol. Or even scarier...a custom function? Any help would be appreciated. Thanks!
-
Great thanks! That worked!
-
I am somewhat new to php, but I also use godaddy for hosting. I noticed that when I try and send an email that has a variable or $POST data in the subject line, it does not send - and doesn't give an error message. Not sure if this is your problem, but I would try hardcoding the subject line in your mail script and see if it sends. Just to rule it out. It seems odd that they would not let you do this, but I haven't been able to get it to work for some reason. Hope it helps.
-
Hello, freaks. I need a little help with the best way to go about this. I have a field in mysql that contains a comma separated string of values. What I need to do is get those values out of the db and list them into editable text fields so the user can update the values in a html form. So far this is my code, I left out all the in betweens - validation, results, etc - for this post...but its there . SELECT servs FROM services WHERE id = $a_id $services = $row['servs']; $srvs = explode(',', $services); Then for the form: <?php foreach ($srvs as $service) { ?> <input type="text" name="servs[]" value="<?php echo $service ?>" /> <?php } ?> This gives me a text field for each value of servs, great! But the problem is, the user can enter up to 15 servs. Some currently have less than that saved in the db. I want to give them the ability to 1. edit any of the current servs value and 2. add more values if they have less than 15. My question is, how do I echo out 15 editable text fields for servs[] no matter the number of values they currently have? And when I go to implode the values, will blank text fields screw everything up? I can't find anything in the forums that relate to this. I believe it probably will involve $i, but I am not too familiar with counting in php yet, so I could really use some help. Thanks! Oh - and I am not stuck on using text fields, but I couldn't figure how to make this work using a select list or checkboxes. Any suggestions either way would help.
-
Thanks so much, that worked! I really appreciate the help.
-
I am having trouble with passing the results of this first query into the next. I first query the db to get the sub id's that belong to the cat id coming through the url. This query gives me the correct results. //query for subcat id $var1_getCAT = "-1"; if (isset($_GET['cat'])) { $var1_getCAT = (get_magic_quotes_gpc()) ? $_GET['cat'] : addslashes($_GET['cat']); } mysql_select_db($database_conntest, $conntest); $query_getCAT = sprintf("SELECT subs.subcat_id, subs.subcategory FROM subs WHERE subs.cat_id = %s ORDER BY subcat_id", GetSQLValueString($var1_getCAT, "int")); $getCAT = mysql_query($query_getCAT, $conntest) or die(mysql_error()); $row_getCAT = mysql_fetch_assoc($getCAT); $totalRows_getCAT = mysql_num_rows($getCAT); Then, I use the array $subCATS in the next query to search the results that are in that array: //set var for subs $subCATS = array(); while ($row = mysql_fetch_assoc($getCAT)) { $subCATS[] = $row['subcat_id']; } $subCATS = implode( ', ', $subCATS); $query_rsSearch = "SELECT advs.adv_id, cinfo.c_id, FROM cinfo LEFT JOIN advs USING (adv_id) WHERE (cinfo.subcat_id IN ($subCATS) OR cinfo.subcat_id2 IN ($subCATS)) ORDER BY RAND()"; If I put exit in front of the second query, I see that the array is dropping the first result. For example, if the first query returns (2, 3, 4, 6, 9, 52), the value of the $subCATS array in the second query is only searching in (3, 4, 6, 9, 52). I hope this makes sense. I am not sure why it would only drop the first result. I figured it would either work or not work, not just partially work - it has thrown my brain into a do while loop that is making me dizzy! What am I doing wrong?
-
Taking the distance out of the return is just sorting the result ascending by zip code. When I run the sql statement, I get the results of all the advs in those zip codes, but the result set is displayed in random order and not by distance of the zip code. I have two databases that I am querying - the zip code field in the zip db is zip_code VARCHAR(5) and the field in the adv db table is zip_code VARCHAR(5). It seems like $return needs to keep the distances in the array in order to have the zips sorted. Funny tidbit...I tried to find the guy who wrote this script and eventually tracked him down. Apparently he is now way beyond this programming stuff in life, but appreciates all that are still using the classes he wrote when he was living in his Toyota and had a lot of time on his hands to write and post scripts. lol! Won't see much help from him any time soon.
-
This is what I got (keeping the zip.class as the original): Array ( [19067] => 0 [08625] => 1.18 [08677] => 1.25 [08611] => 1.48 [08645] => 1.75 [08646] => 1.83 [08647] => 1.85 [08605] => 1.91 [08666] => 1.91 [08604] => 1.94 [08601] => 1.97 [08603] => 2 [08608] => 2.01 [08695] => 2.03 [08607] => 2.08 [08609] => 2.6 [08629] => 2.76 [08610] => 3.08 [08618] => 3.1 [19054] => 3.2 [08638] => 4.14 [19030] => 4.33 [19055] => 4.79 [08505] => 4.8 [19058] => 5.09 [08619] => 5.09 [08554] => 5.38 [08518] => 5.75 [08620] => 5.87 [19057] => 5.96 [08628] => 5.96 [19059] => 6.14 [08690] => 6.17 [08648] => 6.28 [08515] => 6.83 [19056] => 6.86 [19007] => 7.36 [19049] => 7.99 [08691] => 8.19 [19048] => 8.24 [08650] => 8.37 [08560] => 8.53 [08022] => 8.93 [18977] => 9.17 [08016] => 9.2 [19047] => 9.29 [08534] => 9.74 [19021] => 9.75 [18940] => 9.83 ) 0, 1.18, 1.25, 1.48, 1.75, 1.83, 1.85, 1.91, 1.91, 1.94, 1.97, 2, 2.01, 2.03, 2.08, 2.6, 2.76, 3.08, 3.1, 3.2, 4.14, 4.33, 4.79, 4.8, 5.09, 5.09, 5.38, 5.75, 5.87, 5.96, 5.96, 6.14, 6.17, 6.28, 6.83, 6.86, 7.36, 7.99, 8.19, 8.24, 8.37, 8.53, 8.93, 9.17, 9.2, 9.29, 9.74, 9.75, 9.83 This is what I get when I change the result to $return[] = $row[0]: Array ( [0] => 08016 [1] => 08022 [2] => 08505 [3] => 08515 [4] => 08518 [5] => 08534 [6] => 08554 [7] => 08560 [8] => 08601 [9] => 08603 [10] => 08604 [11] => 08605 [12] => 08607 [13] => 08608 [14] => 08609 [15] => 08610 [16] => 08611 [17] => 08618 [18] => 08619 [19] => 08620 [20] => 08625 [21] => 08628 [22] => 08629 [23] => 08638 [24] => 08645 [25] => 08646 [26] => 08647 [27] => 08648 [28] => 08650 [29] => 08666 [30] => 08677 [31] => 08690 [32] => 08691 [33] => 08695 [34] => 18940 [35] => 18977 [36] => 19007 [37] => 19021 [38] => 19030 [39] => 19047 [40] => 19048 [41] => 19049 [42] => 19054 [43] => 19055 [44] => 19056 [45] => 19057 [46] => 19058 [47] => 19059 [48] => 19067 ) 08016, 08022, 08505, 08515, 08518, 08534, 08554, 08560, 08601, 08603, 08604, 08605, 08607, 08608, 08609, 08610, 08611, 08618, 08619, 08620, 08625, 08628, 08629, 08638, 08645, 08646, 08647, 08648, 08650, 08666, 08677, 08690, 08691, 08695, 18940, 18977, 19007, 19021, 19030, 19047, 19048, 19049, 19054, 19055, 19056, 19057, 19058, 19059, 19067
-
Unfortunately that didn't work either, the problem is we took it out of the array with $return[] = $row[0]. It is only returning one value, the zip. Is there a way to take out the resulting zips from the first query, then use them in the next query and then associate them back with the corresponding distance after the results of the 2nd query? Or do I have to query it all over again since it is a calculated result? My head hurts...lol...and I am sure you are sick of helping me by now! I really do appreciate it! Especially since you are the only one in this forum who has attempted to tackled this problem.
-
It didn't like that one! - this is what I got. Warning: sort() expects parameter 1 to be array, boolean given in C:\vhosts\mysite\home.php on line 44 Warning: implode() [function.implode]: Invalid arguments passed in C:\vhosts\mysite\home.php on line 46 Error: This is getting so frustrating. Do I have to do something like break apart the array, query the zip_code IN ($sqlZIPS) and then put it back into an array with the distance to sort?
-
Ok - that worked. joel24 rocks! Thanks so much for your help. The only problem is...I don't want to display the distance, but I wanted to sort the results by distance - showing the results for the data in the closest zips first. If I take distance out, I can't sort it that way? Definitely getting closer though. I am starting to really not like zip codes...
-
I did, I am having it echoing out in a do while loop in a table on the page. If I put an actual zip code in the WHERE IN clause I get all the results I am looking for, so I know my query is ok. I just can't get it to pass the values of the zips_in_range query to a variable that I can use in the IN clause. This is driving me nuts, I am sure it is just some simple 2-3 lines of code needed to get those values...I just can't figure out where to get them. Where you able to look at the zips.class script? I know it is in there somewhere, but since it is filled with other functions, I can't tell what to use! Is the result of the zips_in_range query $r, $return, $details or something I am completely missing? Uggghhh...
-
I tried adding in what you posted, but now the page fails to display completely - no error message or anything, just a blank page. Odd. Any other ideas?
-
yep, the database is set up and the get_zips_in_range returns all the values without a problem. I echoed them out to the top of the page to make sure that part was working. It returns all the zips and the distance from the zip variable in the url. I just can't figure out how to search within those results in my query. It may be that I am trying to compare too much in the WHERE statement, but even still - it doesn't recognize $zips as holding any values. I am lost - but it seems like I just need a bridge between the two that I am completely missing.