
siamsam
Members-
Posts
21 -
Joined
-
Last visited
Never
Everything posted by siamsam
-
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.
-
I downloaded a zip code radius search script and I actually got it to work, somewhat. I attached the include class script and the demo. This works... <?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 />"; } } ?> It returns all the zips within the range of the url variable within 10 miles. The problem I am having is, I need to use those values and compare it to matching advertisers' zips in the db. I have searched on how to do this and I just end up with a ton of errors. Here is my sql (which obviously doesn't work): 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 ('$zips')) ORDER BY subcategories.subcategory"); $getCat = mysql_query($query_getCat, $connDB2) or die(mysql_error()); I have tested the sql query with a constant zip code and it returns what I want it to return, but I cannot seem to get the result of the first into the second. I have a feeling it is because I am not pulling the right array from the include class script? And of course that I am new to all this... Would really appreciate the help! Thanks. [attachment deleted by admin]
-
I need to write a script for a project that I am working on that selects fields from two tables in one database and inserts them into a table in another database via a form. All three tables have a common 'id' field. Both databases are on the same server. I just can't seem to get it right! Any ideas? It would be much appreciated!
-
Thank you both for your responses! I am going to try it out, I am still building the form so when I am done I will see if it works. Two more questions... Will I run into a problem with concurrent users if the script is trying to copying those files at the same time for two different customers? Since the rep will be the one initiating the script, this most likely won't happen but I figured I would ask. I suppose I am just not sure how PHP goes about copying a file - whether it just reads and copies or actually causes the file to be "busy" (if you will). Hope this makes sense. Also, what I am trying to do with one of the image templates that will be copied, is to have users fill in a form to add text and upload a logo. It then will insert it into the image as a new image. The problem I am having is that I need to also include links specific to the customer. To get an idea of what I am talking about check out this site: http://www.mingamo.com/mingamo/search.php?category_id=34 The links I am referring to are the ones at the bottom of the coupon. I looked at their code to get an idea and it looks like each coupon is returned within a table. Do we think that the tables were created within the html or directly from the PHP? That is the only way I could think of doing this. But again - I am a big PHP newbie! Thanks for your help!
-
Hello all. I need a little help in a project I am working on. I am not sure if it is even possible to do what I am hoping for, or if it is a secure way to accomplish it. Here is what I would like to achieve: 1. sales rep enters info about order into a form & info goes into database (I have this part) 2. once the new record is created, I want the magic of PHP to create a new directory for the customer (i.e. named 'customer_name') 3. in the directory I want it to automatically include a copy of /forms/bizpagetemplate.php and two copies of /forms/coupontemp.jpeg - all three writable only with that customer's permissions (username and pass is set when rep enters in form) 4. then I want to have an email sent to the customer with the link to the file Is this possible? I am new to PHP and would appreciate any comments on how to achieve this. And if possible, tips on security measures when doing something like this. Thanks!
-
Thanks for replying. My lack of experience with PHP is definitely an issue here! No doubt. My reference to Dreamweaver is that it allows you to build recordsets based on your database and you can insert them into an HTML table when the query is executed. DW helps the less experienced PHP people with this feature, pretty much writing the code for you - as long as you insert the proper query. I am just not sure how to incorporate selecting the items and having them sent to a "cart" type of thing, to just be printed in another form of an HTML table. Since I don't know PHP very well, is that just a script that takes the selected items and sends them to an HTML table for display? Users would have to login in order to select items and print, but not to just browse. There would be no limit as to how many they could select. The images themselves are not exactly images - really just a pdf with product information (text) and possible a company logo. Sorry if I sound completely PHP ignorant...but I am!
-
I think...I know I need a little help here... Background info: using MySQL (pretty comfortable with), PHP(new to this), Dreamweaver CS4 (have been using for about 6 months now for static websites) What I am attempting to do is create an app that users can do a search by putting in their zip code and getting results within the radius (in miles) of several business in their area. Here is the part I am having most trouble with - the results should be displayed as images (which will be small in file size and stored in the database) and preferrably in a table with 10 results per page. They can then select (via a checkbox or something similar) which images they would like to add to their "cart". The images will not be purchased, but I want them to be able to print them as a watermarked pdf once they are done searching and selecting the images they want. When printed, I want to fit as many images on a page as possible (to save paper) - another table I suppose. Maybe even later add the ability to email or send images as a sms to their phone. With that in mind, I really could use some suggestions on how to achieve this effectively. Do I need to set up a full blown shopping cart to achieve this, since no monetary transaction is taking place? Is their a simplier way to do this in DW that I am just not getting? Also - how do I find a script for the zip code search and are there any suggestions for the db table layout of zip codes? I have not written any code for this project yet, I am still in the "how the heck do I do this" phase. Thanks in advance to anyone who attempts to help me with this mess!