HuggieBear
Members-
Posts
1,899 -
Joined
-
Last visited
Everything posted by HuggieBear
-
autologin to .htaccess protected directory through php - how?
HuggieBear replied to scotch33's topic in PHP Coding Help
I think that the short answer is no. It can be done the other way around, you can log into an .htaccess protected directory and automatically be authenticated with php, but not the other way around. Regards Huggie -
OK, it's always good to start with a plan, so how about this. On all your product pages you allow people to add the product to the order form by selecting a link. We have this in place already. They can't decrease the quantity from these pages, they have to go to the order form for that, is that a fair assumption? I think despite this being an order form, it should be treated like a shopping cart, with the same principles. Then from the order form page, they can remove specific items, remove all items, or change the quantity for individual items? Regards Huggie
-
Yes, they aren't problems, I just hadn't written those bits yet. If you think you understand some of the code, then why not have a go at those bits yourself and see how you get on. Regards Huggie
-
Oh dear, what have I started. I'm glad to see the method's been passed as acceptable... lol Huggie
-
It is indeed a Bud, and you're more than welcome. Glad to have been able to help. Regards Rich 8)
-
My bad, made a major typo! I had [code=php:0]$body =. "value";[/code] I should have had [code=php:0]$body .= "value";[/code] I had the period and the equals the wrong waya around, I wasn't actually concatenating anything... Idiot :-[ Try again with this code: [code]<?php // start the session session_start(); // put the array of id's into a string for use in the sql query $sqlitems = implode(",", array_keys($_SESSION['items'])); // connect to the database include_once('database.php'); // get the results from the database (the same query as earlier) $sql = "SELECT id, name, FROM products WHERE id IN ($sqlitems) ORDER BY id"; $result = mysql_query($sql) or die ("<b>Unable to run :</b> $sql<br>\n<br>\n<b>Because:</b> " . mysql_error()); include "mime_mail.inc"; # create object instance $mail = new mime_mail; # set all data slots $mail->from = "$email"; $mail->to = "MY EMAIL ADDRESS HERE"; $mail->subject = "Order from the website"; $body = "The following is an order from the website. The order details are as follows: NAME: $contact_name COMPANY: $company_name ADDRESS: $address TOWN: $town COUNTY: $county POST CODE: $post_code TELEPHONE: $telephone MOBILE: $mobile COMMENTS: $comments"; $body .= "\n\nItem\t\tQuantity\n"; // put a row for each order line into the body of the email while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){ $body .= "{$row['name']}\t\t{$_SESSION['items'][$row['id']]}\n"; } $mail->body = $body; # send email $mail->send(); print("<meta http-equiv=\"refresh\" content=\"1;URL=order_form_thank_you.php\"> "); ?>[/code] Regards Huggie
-
In that case, why not use timestamps. I'm not going to provide you with the code, just an idea. 1. A new user logs into your site the first day they register, you credit them with 100 points and store in the database the time of login. 2. The next time they login, you take the current timestamp and subtract the one stored in the datbase and round it down to the nearest day to work out the number of elapsed days. 3. You credit them with that number of elapsed day times 100 (up to the limit you've set) and then log the new timestamp for next time they log in. Now for someone who's worked a lot with timestamps, dates, time functions etc. This shouldn't bee too difficult, unfortunately that person isn't me. :( Regards Huggie
-
Better idea, based on what you've said... [code] <?php // start the session session_start(); // put the array of id's into a string for use in the sql query $sqlitems = implode(",", array_keys($_SESSION['items'])); // connect to the database include_once('database.php'); // get the results from the database (the same query as earlier) $sql = "SELECT id, name, FROM products WHERE id IN ($sqlitems) ORDER BY id"; $result = mysql_query($sql) or die ("<b>Unable to run :</b> $sql<br>\n<br>\n<b>Because:</b> " . mysql_error()); include "mime_mail.inc"; # create object instance $mail = new mime_mail; # set all data slots $mail->from = "$email"; $mail->to = "MY EMAIL ADDRESS HERE"; $mail->subject = "Order from the website"; $body = "The following is an order from the website. The order details are as follows: NAME: $contact_name COMPANY: $company_name ADDRESS: $address TOWN: $town COUNTY: $county POST CODE: $post_code TELEPHONE: $telephone MOBILE: $mobile COMMENTS: $comments"; $body =. "\n\nItem\t\tQuantity\n"; // put a row for each order line into the body of the email while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){ $body =. "{$row['name']}\t\t{$_SESSION['items'][$row['id']]}\n"; } $mail->body = $body; # send email $mail->send(); print("<meta http-equiv=\"refresh\" content=\"1;URL=order_form_thank_you.php\"> "); ?> [/code] Regards Huggie
-
Do they always get 100 added every night? If I register and don't log in for two weeks, when I log in next time, will I have 1400 points? Regards Huggie
-
[quote]any ideas?[/quote] I'd imagine that you don't have a very good understanding of HTML tables if you're not sure why this won't display properly. They're very rigid structures, so attempting to add another column just 'willy nilly' in the middle of a table isn't just going to work. Take a look at this [url=http://www.w3schools.com/html/html_tables.asp]tutorial[/url]. Regards Huggie
-
ok, I'm not 100% certain how that's going to work, as I've not used classes before, but you could try adding more than one item to the body of the email and see how it goes, for example: [code] <?php // start the session session_start(); // put the array of id's into a string for use in the sql query $sqlitems = implode(",", array_keys($_SESSION['items'])); // connect to the database include_once('database.php'); // get the results from the database (the same query as earlier) $sql = "SELECT id, name, FROM products WHERE id IN ($sqlitems) ORDER BY id"; $result = mysql_query($sql) or die ("<b>Unable to run :</b> $sql<br>\n<br>\n<b>Because:</b> " . mysql_error()); include "mime_mail.inc"; # create object instance $mail = new mime_mail; # set all data slots $mail->from = "$email"; $mail->to = "MY EMAIL ADDRESS HERE"; $mail->subject = "Order from the website"; $mail->body = "The following is an order from the website. The order details are as follows: NAME: $contact_name COMPANY: $company_name ADDRESS: $address TOWN: $town COUNTY: $county POST CODE: $post_code TELEPHONE: $telephone MOBILE: $mobile COMMENTS: $comments"; $mail->body = . "\n\nItem\t\tQuantity\n"; // put a row for each order line into the body of the email while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){ $mail->body =. "{$row['name']}\t\t{$_SESSION['items'][$row['id']]}\n"; } # send email $mail->send(); print("<meta http-equiv=\"refresh\" content=\"1;URL=order_form_thank_you.php\"> "); ?> [/code] Regards Huggie
-
Can I see the actual code. Regards Huggie
-
There's no need for input boxes or a form at all. Your order page is dynamically generated from the database, based on what existed in the array, so generate the email dynamically too. Once you have your order ready, hit 'purchase' or whatever you want on there and process it like follows (Most of the code is similar to the page we've already seen): [code] <?php // start the session session_start(); // put the array of id's into a string for use in the sql query $sqlitems = implode(",", array_keys($_SESSION['items'])); // connect to the database include_once('database.php'); // get the results from the database (the same query as earlier) $sql = "SELECT id, name, FROM products WHERE id IN ($sqlitems) ORDER BY id"; $result = mysql_query($sql) or die ("<b>Unable to run :</b> $sql<br>\n<br>\n<b>Because:</b> " . mysql_error()); // start the email $to = "me@mydomain.com"; // may need to escape the @ $subject = "Order from your domain"; // generate the main message body of the email $body = "Item\t\tQuantity\n"; // put a row for each order line into the body of the email while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){ $body =. "{$row['name']}\t\t{$_SESSION['items'][$row['id']]}\n"; } // send the mail mail($to, $subject, $body); ?> [/code] Regards Huggie
-
Yes, you should use the unique, auto-incrementing id for the link. That would solve all the issues. You can still display the product name on the page, but just have the link use the unique id to add to the array. Regards Huggie
-
ok, I assumed that the products all had a unique id that was an integer. In that case we need to re-think. Regards Huggie
-
Move [code=php:0]$post = emoticon($updates[uptext]);[/code] inside the where loop first. Then change this: [code] <td bgcolor=#101010>emoticon($updates[uptext])</td> [/code] To this: [code] <td bgcolor=#101010>$post</td> [/code] Regards Huggie
-
OK, did you call your $_SESSION variable 'items' like I did in my example of not? If not, then you need to change the references to it. The errors you're getting are because $_SESSION['items'] does not appear to be a array. Regards Huggie
-
Oh I see what you mean, my bad... Change this: [code]<?php $database="database"; mysql_connect ("localhost", "user", "pass"); @mysql_select_db($database) or die( "Unable to select database"); $num_rows = mysql_num_rows($sql); echo "<p class='footer'>"; echo $num_rows; echo " emulators found</p>"; ?>[/code] To this: [code]<?php $database="database"; mysql_connect ("localhost", "user", "pass"); @mysql_select_db($database) or die( "Unable to select database"); $sql = "select emulator, version, os, platform, details from windows_atari2600 where emulator LIKE '%".mysql_real_escape_string($_POST["emusearch"])."%' OR platform LIKE '%".mysql_real_escape_string($_POST["emusearch"])."%' order by platform asc, emulator asc"; $result = mysql_query($sql); $num_rows = mysql_num_rows($result); echo "<p class='footer'>"; echo $num_rows; echo " emulators found</p>"; ?>[/code] Regards Huggie
-
OK, MySQL can do all of that for you, change your sql to something like this... [code]SELECT model_number, count(model_number) as quantity, sum(cost * quantity) as total_cost FROM parts GROUP BY model_number [/code] Obviously you'll need your column names and table name in here. Regards Huggie
-
What bar? Huggie
-
Sorry, typo on my part. I corrected it now, can you copy and paste and try again. Regards Huggie
-
ok, you didn't quite provide what I asked for, but that's ok, I'll make an assumption to help you. I'm assuming from what you've said that a single row in your database will look like this: [table] [tr][td]Model Number[/td][td]Quantity[/td][td]Cost[/td][/tr] [tr][td]WT1200LE[/td][td]20[/td][td]7.50[/td][/tr] [/table] Is that correct, I just want to establish what it looks like in your database, before I get my wellies on. Regards Huggie [size=8pt][color=red][b]Edit:[/b][/color] I'm off to bed now, but this is easy to resolve, I'll pick it up in the morning :)[/size]
-
ok, modified from your code above, give this a try: [code]<?php if (isset($_POST['emusearch']) && strlen(trim($_POST['emusearch'])) > 0){ $database="database"; mysql_connect ("localhost", "user", "pass"); @mysql_select_db($database) or die( "Unable to select database"); $sql = "select emulator, version, os, platform, details from windows_atari2600 where emulator LIKE '%".mysql_real_escape_string($_POST["emusearch"])."%' OR platform LIKE '%".mysql_real_escape_string($_POST["emusearch"])."%' order by platform asc, emulator asc"; if(!$rs = mysql_query($sql)){ echo "Error<br>".mysql_error()."<br>".$sql; exit(); } if(!mysql_num_rows($rs)){ echo "<tr>"; echo "<meta http-equiv='refresh' content='0; URL=http://www.google.com/foundnorecordspage'>"; echo "</tr>\n"; } else{ $num_rows = mysql_num_rows($rs); echo "$num_rows results found<br>\n<br>\n"; while ($get_info = mysql_fetch_row($rs)) { echo "<tr>"; foreach ($get_info as $field){ echo "<td>$field</td>\n"; } echo "</tr>\n"; } } } else{ echo "<meta http-equiv='refresh' content='0; URL=http://www.google.com/searchcriteriarequired'>"; } ?>[/code] Regards Huggie
-
I'm not sure what you're asking here, can you provide a sample row from your database and then give us an example of the figures, so we can work out what you're after. Regards Huggie
-
You still need a query... Do you want it to show the total in emulators, or just the total found once searched? Regards Huggie