overmonk Posted August 25, 2008 Share Posted August 25, 2008 Hi friends, I had a lot of help doing the initial design, and I don't do enough programming to feel confident jumping in without some guidance. The site allows authenticated users to log in, enter 100 names, and then it formats those names into an HTML file and also an excel file, attaches those to an email, and send it to me. When this process occurs, it marks their order_complete variable to 1; if they try to log in again, it bypasses the order process and takes them straight to a status page showing their order details. My boss has told our client that of course we can accomodate multiple orders per user, but that's not how I designed the site. My DB has two tables: tbl_users and tbl_recips - and ties the recips to the user by unique UserID. So if the user IS somehow permitted to log in again, right now it would overwrite the files created, and also the recips entry for that UserID. That would make accounting a huge PITA - I'd be tired to paper records to determine how many orders are placed. How can I set my site to add multiple recips records per user, and how can I code it so that the created files are not overwritten. I'm not good with arrays; I just haven't ever quite gotten them - just a heads up to let you know where my skills fall. Code that authenticates the user, if they exist, I check for and pull user data from tbl_users and set most of it as session variables, otherwise they enter it as part of the process: <?php session_start(); include("include/include_nc.php"); extract($_POST); $username = strtolower($username); $sql = "SELECT * FROM tbl_users WHERE username='$username' AND pwd='$pwd'"; $result = $mysql->query($sql); $rows = $mysql->rows($result); if ($rows == 0){ $page_title = "Log In Failed"; $content_title = $page_title; $content = "You have entered an incorrect username and/or password. Please <a href='javascript:history.back(1)'>go back</a> and try again."; $make = $template->make_page($page_title, $content_title, $content); exit(); } else { $i = $mysql->arrays($result); $_SESSION["first_name"] = $i["firstName"]; $_SESSION["last_name"] = $i["lastName"]; $_SESSION["id"] = $i["userID"]; $_SESSION["ordered"] = $i["order_complete"]; $_SESSION["order_id"] = $i["pwd"]; $_SESSION["addy_1"] = $i["address1"]; $_SESSION["addy_2"] = $i["address2"]; $_SESSION["userCity"] = $i["city"]; $_SESSION["userState"] = $i["state"]; $_SESSION["userZip"] = $i["zip_postal"]; $_SESSION["userTel"] = $i["telnum"]; $_SESSION["logged_in"] = "yes"; $_SESSION["emailaddy"] = $i["username"]; $_SESSION["ordDate"] = $i["orderDate"]; header("Location: foo_welcome.php"); } ?> This works fine. This is the code that creates the file after the user has entered their delivery and recipient info. I need to figure out how to set PHP to ADD a NEW record for each folder, then pull from that NEW record to create the files. It uses a homegrown mysql class, which is why it looks weird. The class works fine - you can tell what it's doing from the code: <? $orddate = date('F j, Y'); $id = $_SESSION['id']; $ordcomplete='1'; $sql_update = "UPDATE tbl_users SET orderDate='$orddate' WHERE userID='$id'"; $do_update = $mysql->query($sql_update); $sql_update = "UPDATE tbl_users SET order_complete='$ordcomplete' WHERE userID='$id'"; $do_update = $mysql->query($sql_update); ?> It then pulls out the recips and generates the files, as so: $file_open = fopen("./files/$ordnum" . "-100ct" . ".html", "w+"); $file_write = fwrite($file_open, $the_file); $file_close = fclose($file_open); The -100ct is because we have already expanded the program from 50 names to 100 - this is to keep the folks from overwriting their current 50 name order files - just the created files - it will still overwrite the DB at the moment. I think. And then this one too: $excel_open = fopen("./files/$ordnum" . "-100ct" . ".xls", "w+"); $excel_write = fwrite($excel_open, $data); $excel_close = fclose($excel_open); I'm thinking there's a way to simply set a new variable in the DB - one that says what order this is, and use that as a new key somehow? I can usually figure this stuff out given time, but my boss is hounding me, and I've got another project that's competing for the time. CAn anyone take a look and offer suggestions? I can post more code if need be. Thanks for any suggestions in advance. Monk Link to comment https://forums.phpfreaks.com/topic/121242-need-advice-on-modifying-exiting-phpmysql-site/ Share on other sites More sharing options...
DarkWater Posted August 25, 2008 Share Posted August 25, 2008 Check out the tutorial on joins on the main page of this site. It's pretty simple stuff to actually have more than one file per person in the database-maintenance sense, and the having multiple files is just a matter of associating unique filenames with each order record, which is tied to a person. Link to comment https://forums.phpfreaks.com/topic/121242-need-advice-on-modifying-exiting-phpmysql-site/#findComment-625034 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.