PHP - Mysql/php: Redirected When Already Visited
Hello,
I'm currently programming a site for my school as final work. Some stuff works, other doesn't yet anyway, here is my question: People have to register on the site. Once they done it, and they revisit it, they shouldn't be able to visit it anymore. I want to check this with a control sign, in my database it is named 'controle'. When 'controle' is set to 1, it means they have registered them self already and they should be redirected to another page. I wrote something but it is not correct at all. Any ideas? Code: [Select] <?php $query ="SELECT naam FROM Leerlingenkeuzes"; // Selecteren it leerlingenkeuzes $result = mysql_query($query) or die (mysql_error());// $query .= " WHERE naam='".$naam."' AND controle='1' AND klas='".$klas."'"; $res=mysql_fetch_row($result); while($res = mysql_fetch_array($result)) { if($res['controle']='1') { header ("Location: /ingeschreven.php"); echo $res['naam']; } else { echo $res['klas']; } } ?> Similar TutorialsHello, I have domain "A" coming with a wehosting and a domain "B" , it's DNS is redirected to domain "A". Now I'm solving how to catch the url (domain name) of "B", that is redirecting to me. Is it possible throught PHP ? Thak you Hi phpfreaks members, I got a little social network website, http://www.tranceprofile.com I got a php script for members to log in to my website. When they are logged in they can view there own profile and edit it. I got my login script on two places, http:www.tranceprofile.com/login.php and my index.php page. Well here is my problem: When they log in they are send to my index.php page as a logged in user. I want them to be redirected to the http://www.tranceprofile.com/profile.php page. I hope you guys can help me out! Best regards, Mitch Oosterhuis. Login script: <table width="400" align="center" cellpadding="6" style="background-color:#FFF; border:#666 1px solid;"> <form action="login.php" method="post" enctype="multipart/form-data" name="signinform" id="signinform"> <tr> <td width="23%"><font size="+2">Log In</font></td> <td width="77%"><font color="#FF0000"><?php print "$errorMsg"; ?></font></td> </tr> <tr> <td><strong>Email:</strong></td> <td><input name="email" type="text" id="email" style="width:60%;" /></td> </tr> <tr> <td><strong>Password:</strong></td> <td><input name="pass" type="password" id="pass" maxlength="24" style="width:60%;"/></td> </tr> <tr> <td align="right"> </td> <td><input name="remember" type="checkbox" id="remember" value="yes" checked="checked" /> Remember Me</td> </tr> <tr> <td> </td> <td><input name="myButton" type="submit" id="myButton" value="Sign In" /></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td colspan="2">Forgot your password? <a href="forgot_pass.php">Click Here</a> <br /></td> </tr> <tr> <td colspan="2">Need an Account? <a href="register.php">Click Here</a><br /> <br /></td> </tr> </form> </table> Hi, I'm working on a web application that will interact with an existing website from another company. On the other company's site, there will be a form (using POST) that has my web application as the action element. The user who clicked the submit button will be redirected to my site, where I need to receive the $_POST data from this form to process before redirecting into the web application. I have done work on the other side, using standard form posts to send data to another site, but I've never had to write the code for the receiving end. How do I receive the form data posted from the other website? Can I access the $_POST[''] array as I would with any normal same-site POST transaction? Please let me know if you need additional detail or if my question wasn't clear! I'm fast approaching deadlines and really appreciate your help! Thanks! I have some thousands of photos about nature I ll let visitors/members to see them one by one, but I dont want to show them the same photo again after they visit 1 week later How can I do this ? What I think as a solution is; For members; I can store the ids (like "everest01") of the photos that member has visited , and show user the most visited photos that he/she has not see for next visit. But what I m wondering is, how will I take the photos from DB ? select * from photos WHERE id not in ( $thousandsofvisitedphotoids ) ?? I m stuck here ? For visitors ( not members ) ; I can set a cookie that keeps the ids of visited photos.. when visitor visits the website again, I take the cookie and sent to $thousandsofvisitedphotoids and make a query again ? I m stuck here, How you guys do this ? what's the logic of this ? Hello I use this code to display popup login when user to clicked on a "proceed to checkout" button in the cart page (woocomerce) <?php function woocommerce_button_proceed_to_checkout() { $checkout_url = WC()->cart->get_checkout_url(); ?> <div <?php echo mf_get_option( 'login_reg_popup' ) ? 'data-toggle="modal" data-target="#login-modal"' : null; ?>> <a class="checkout-button button alt wc-forward" href="<?php echo ! mf_get_option( 'login_reg_popup' ) ? wc_get_page_permalink( 'myaccount' ) : '#'; ?>" class="checkout-button button alt wc-forward"><?php _e( 'اقدام به پرداخت', 'woocommerce' ); ?></a> <?php }
But after login, I want the user to be redirected to the "checkout" page if it is on the cart page
I found the following code but I couldn't put it in the code above <?php //redirect to your "current" page wp_redirect( $_SERVER["HTTP_REFERER"] ); // redirect to the "checkout" page function wpse_131562_redirect() { if (! is_user_logged_in() && (is_woocommerce() || is_cart()) ) { // feel free to customize the following line to suit your needs wp_redirect(site_url('checkout/')); exit; } } add_action('template_redirect', 'wpse_131562_redirect');
example is on link: http://www.etual.co.rs/index.php?route=product/product&product_id=1416 on line: <a onclick="$('#product').submit(); " id="add_to_cart" class="button"><span>U korpu</span></a> For example: I open some category and then open some article. When i click ADD TO CART button (U KORPU) i want add product to basket and go back to last visited page. Is there way to do these two things at the same time clicking ADD TO CART button? Thanks create table mimi (mimiId int(11) not null, mimiBody varchar(255) ); <?php //connecting to database include_once ('conn.php'); $sql ="SELECT mimiId, mimiBody FROM mimi"; $result = mysqli_query($conn, $sql ); $mimi = mysqli_fetch_assoc($result); $mimiId ='<span>No: '.$mimi['mimiId'].'</span>'; $mimiBody ='<p class="leading text-justify">'.$mimi['mimiBody'].'</p>'; ?> //what is next? i want to download pdf or text document after clicking button or link how to do that Hello everyone, Sorry if this has been answered but if it has I can't find it anywhere. So, from the begining then. Lets say I had a member table and in it I wanted to store what their top 3 interests are. Their$ row has all the usual things to identify them userID and password etc.. and I had a further 3 columns which were labled top3_1 top3_2 & top3_3 to put each of their interests in from a post form. If instead I wanted to store this data as a PHP Array instead (using 1 column instead of 3) is there a way to store it as readable data when you open the PHPmyadmin? At the moment all it says is array and when I call it back to the browser (say on a page where they could review and update their interests) it displays 'a' as top3_01 'r' as top3_02 and 'r' as top3_03 (in each putting what would be 'array' as it appears in the table if there were 5 results. Does anyone know what I mean? For example - If we had a form which collected the top 3 interests to put in a table called users, Code: [Select] <form action="back_to_same_page_for_processing.php" method="post" enctype="multipart/form-data"> <input name="top3_01" type="text" value="enter interest number 1 here" /> <input name="top3_02" type="text" value="enter interest number 2 here" /> <input name="top3_03" type="text" value="enter interest number 3 here" /> <input type="submit" name="update_button" value=" Save and Update! " /> </form> // If my quick code example for this form is not correct dont worry its not the point im getting at :) And they put 'bowling' in top3_01, 'running' in top3_02 and 'diving' in top3_03 and we catch that on the same page with some PHP at the top --> Code: [Select] if (isset($_POST)['update_button']) { $top3_01 = $_POST['top3_01']; // i.e, 'bowling' changing POST vars to local vars $top3_02 = $_POST['top3_02']; // i.e, 'running' $top3_03 = $_POST['top3_03']; // i.e, 'diving' With me so far? If I had a table which had 3 columns (1 for each interest) I could put something like - Code: [Select] include('connect_msql.php'); mysql_query("Select * FROM users WHERE id='$id' AND blah blah blah"); mysql_query("UPDATE users SET top3_01='$top3_01', top3_02='$top3_02', top3_03='$top3_03' WHERE id='$id'"); And hopefully if ive got it right, it will put them each in their own little column. Easy enough huh? But heres the thing, I want to put all these into an array to be stored in the 1 column (say called 'top3') and whats more have them clearly readable in PHPmyadmin and editable from there yet still be able to be called back an rendered on page when requested. Continuing the example then, assuming ive changed the table for the 'top3' column instead of individual colums, I could put something like this - Code: [Select] if (isset($_POST)['update_button']) { $top3_01 = $_POST['top3_01']; // i.e, 'bowling' changing POST vars to local vars $top3_02 = $_POST['top3_02']; // i.e, 'running' $top3_03 = $_POST['top3_03']; // i.e, 'diving' $top3_array = array($top3_01,$top3_02,$top3_03); include('connect_msql.php'); mysql_query("UPDATE members SET top3='$top3_array' WHERE id='$id' AND blah blah blah"); But it will appear in the column as 'Array' and when its called for using a query it will render the literal string. a r r in each field instead. Now I know you can use the 'serialize()' & 'unserialize()' funtcions but it makes the entry in the database practically unreadable. Is there a way to make it readable and editable without having to create a content management system? If so please let me know and I'll be your friend forever, lol, ok maybe not but I'd really appreciate the help anyways. The other thing is, If you can do this or something like it, how am I to add entries to that array to go back into the data base? I hope ive explained myself enough here, but if not say so and I'll have another go. Thanks very much people, L-PLate (P.s if I sort this out on my own ill post it all here) I have following piece of code below, and I would like to be able to express it pure SQL, something that could go into a .sql file :
$request_string='SELECT topic_forum_id FROM topic_table WHERE topic_id= 2014'; $query=database->prepare($request_string); $query->execute(); $data=$query->fetch(); $query->closeCursor(); $forum=$data['topic_forum_id']; $request_string='INSERT INTO post_table (post_topic,post_forum) VALUES (2014,:forum)'; $query=database->prepare($request_string); $query->bindValue(':forum',$forum,PDO::PARAM_INT); $query->execute(); $data=$query->fetch(); $query->closeCursor();Is it possible ? So i have this php as shown below. It should make a list of comments with comment replies below their comment respectively. The problem is that it only goes through and shows 1 comment and all the comment replies for that one comment. It should be showing all comments i have in the db for that article. If i remove the second while then it shows all the comments correctly but no comment replies then... How do i get this script to loop through the db for every comment but also loop through every comment reply for that $row[id]? If anyone has a better / more efficient way of what I am trying to do, please explain or show example (i am open to anything)... Code: [Select] // what article are we showing? $article_to_show_id = $_GET['article_id']; $active_is_set_text = "1"; // Active Column text that makes it okay to show // Finding the article $search_for_article = mysql_query("SELECT * FROM articles WHERE id = '$article_to_show_id' AND active = '$active_is_set_text'"); while($row = mysql_fetch_array($search_for_article)) { // format the last updated date right $update_date_edit = $row[update_date]; $update_date_edit = date('F j, Y \a\t h:ia', $update_date_edit); $row[update_date] = $update_date_edit; // format the submit updat date right $submit_date_edit = $row[submit_date]; $submit_date_edit = date('F j, Y \a\t h:ia', $submit_date_edit); $row[submit_date] = $submit_date_edit; echo ' <div> ', $row[title] ,' </div> <div> by: ', $row[author] ,' on ', $row[submit_date] ,' </div> <div> ', $row[content] ,' </div> <div> Last Updated: ', $row[update_date] ,' </div> <form action="article_reply.php" method="post"> <input type="hidden" name="article_id" value="', $row[id] ,'" /> <button name="article_reply" type="submit" value="submit">Reply</button> </form> '; } $comment_count = 0; $comment_reply_count = 0; // Finding all of the comments $search_for_article = mysql_query("SELECT * FROM article_comments WHERE article_id = '$article_to_show_id' AND reply_id = '0'"); while($row_comment = mysql_fetch_array($search_for_article)) { // format the submit updat date right $comment_date_edit = $row_comment[comment_date]; $comment_date_edit = date('F j, Y \a\t h:ia', $comment_date_edit); $row_comment[comment_date] = $comment_date_edit; echo ' <br> <br> COMMENT:<br> <div> By: ', $row_comment[username] ,' on ', $row_comment[comment_date] ,' </div> <div> ', $row_comment[comment] ,' </div> '; $comment_count++; // Finding all of the comment replies if any $search_for_article = mysql_query("SELECT * FROM article_comments WHERE article_id = '$article_to_show_id' AND reply_id = '$row_comment[id]'"); while($row_two = mysql_fetch_array($search_for_article)) { // format the submit updat date right $comment_date_edit = $row_two[comment_date]; $comment_date_edit = date('F j, Y \a\t h:ia', $comment_date_edit); $row_two[comment_date] = $comment_date_edit; echo ' <br> <br> COMMENT REPLY:<br> <div> By: ', $row_two[username] ,' on ', $row_two[comment_date] ,' </div> <div> ', $row_two[comment] ,' </div> '; $comment_reply_count++; } } Need some help I have 2 tables in a database and I need to search the first table and use the results from that search, to search another table, can this be done? and if it can how would you recommend that I go about it? Thanks For Your Help Guys! Im trying to compare two different server table and compare match email output. please tell me whats wrong in my code. Hey Guys I need some help, I have these two tables: (vouchers) (login) I also, have this page. (redeem.php) What i need, is when a user types in a voucher code, i adds 100 credits to there user account. My Logged in Session is currently: Quote $username = $_SESSION['loggedinsuccesfully']; Also, when the voucher has been used, the status of the voucher needs to change to 1 (means it cant be used again) If anyone can offer me this code, i will appreciate it. Thanks again fCooper94 Hi All, I inherited some code as part of a bought website, I am trying to convert it to make it better and add functionality... however I am having a hard time trying to figure out what is going on in one particular section of code. In short there is basically a block of PHP which is producing a SQL statement, but the SQL always returns 0 results. I can't figure out why this is because I can't figure out what the PHP is producing. Would someone with my knowledge than me be kind enough to take a look and advise me where possible? This is the part doing the generating: Code: [Select] // IF THE CATEGORY FIELD IS NOT EMPTY if (!empty($row['category'])) { // EXPLODE THE ARRAY ON , $strArr = explode(",",$row['category']); // FOR EACH ONE for($i=0; $i<sizeof($strArr); $i++) { $str = trim($strArr[$i]); $strs .= "'".trim($strArr[$i])."',"; $sch[] = "category LIKE '%$str%'"; } echo "Categories in the array a ". $strs; echo "<br /><br />"; $strs = substr($strs,0,-1); $sch[] = "category in ($strs)"; } // IF THE SUBCOUNTY FIELD IS NOT EMPTY if(!empty($row['subcounty'])) { // EXPLODE THE ARRAY ON , $strArr = explode(",",$row['subcounty']); // FOR EACH ONE for($i=0; $i<sizeof($strArr); $i++) { $str = trim($strArr[$i]); $strs2 .= "'".trim($strArr[$i])."',"; $sch[] = "subcounty LIKE '%$str%'"; } echo "SubCounties in the array a ". $strs2; echo "<br /><br />"; $strs2 = substr($strs2,0,-1); $sch[] = "subcounty in ($strs2)"; } // IF THE TITLE FIELD IS NOT EMPTY if(!empty($row['title'])) { // JOIN SEARCH TERM TO THE ARRAY $sch[] = "(position LIKE '%$row[title]%' || description LIKE '%$row[title]%')"; echo "The title is: ".$row['title']; echo "<br /><br />"; } And this is the SQL part that always returns blank: Code: [Select] // COUNT THE AMOUNT OF RESULTS THEN SELECT THE JOBS FROM THE DATABASE $result = mysql_query("SELECT count(*) FROM jobs ". (($sch)?"WHERE ".join(" AND ", $sch):"").""); $total = mysql_result($result, 0); $r9 = mysql_query("SELECT * FROM jobs ".(($sch)?"WHERE ".join(" and ", $sch):"")." ORDER BY jobid DESC"); echo "The count is: " . $total; echo "<br /><br />"; Any help would be appreciated, Many thanks, Greens85 This is my first time really working with more than 1 or two tables in a mysql database and I'd like to know what is the best way to go about querying my data so that i'm doing it in at least a somewhat efficient manner that the way I am currently doing it. First I will list my Tables and pastebin the Table creation code so you can get an idea of what I'm working with. Graff_Users, Drawings, Drawings_Stamps, Stamps, Packages Ok, those are the tables, the Graff_Users is the main table. The way I've got things setup is that I first do a query on the Graff_Users table for any uid that I want to lookup data for. Then, based on whether the artist column is equal to 1 will determine if there are Drawings to fetch, at least that is how I've been doing it and I dont feel like redesigning something that works so well for me right now. so everything is fine when artist=0 or null or anything but 1. But my trouble starts if artist=1, then I have to query a whole lot of data here, let me explain it. Ok, if artist=1, currently, I query the Drawings table to find any drawings where the house_owner_id is equal to the uid of the User. This leads me to a list of Drawings rows. Next, I check which of those rows has stamps_used=1 for each Drawing and gather up a list of id's of the Drawings that have that set to 1. Once I have the list of id's of the Drawings, I query the Drawings_Stamps table for rows where the drawings_id is equal to any of those id's. Then once I have that, I use the stamp_id's from those and do another query on the Stamps table to get all of the stamps matching those id's. Then each Stamp also contains an author_id so I gather those id's up and do another query back on the Graff_Users table to get the first_name,last_name and picture. Once I have all of that data in various array throughout my script, i create a new array and start putting the pieces back togather from the various arrays until I am left with an array that looks like this one here(JSON used for visualization here) Code: [Select] { "request_type": 1, "target_uid": "1234567", "data": { "id": "277", "uid": "1234567", "first_name": "Jeremy", "last_name": "Canada", "picture": "http://www.pictures.com/mypic.png", "signed_up": "2010-10-29 03:47:09", "selected_house": "10", "mp3": "1", "emblem_id": "2", "artistData": [ { "id": "210", "artist_id": "1234567", "house_owner_id": "1234567", "anonymous": null, "stamps_used": "1", "timestamp": "2010-09-23 00:52:42", "note": "wanna dance?", "first_name": "Jeremy", "last_name": "Canada", "picture": "http://blahblah.com/picture.png", "stampsArray": [ { "id": "250", "name": "", "author_id": "654321", "created": "2010-09-23 23:40:22", "keywords_id": null, "packages_id": "27", "public": "1", "package_category_id": "0", "filename": "drawingitems\/663231980_1285285221_445643.png", "number_of_users": "0", "description": "just another stamp my friend", "rating": "0", "thumbs_up": "0", "thumbs_down": "0", "first_name": "Cat Man", "last_name": "Blues", "picture": "http:\/\/pic.com\/_q.jpg", "packageData": { "id": "27", "name": "Circles Of cool", "description": null, "total_stamps": "6", "number_of_users": "0", "rating": "0", "thumbs_up": "0", "thumbs_down": "0" } }, { "id": "249", "name": "", "author_id": "1680999989", "created": "2010-09-23 23:38:28", "keywords_id": null, "packages_id": "26", "public": "1", "package_category_id": "0", "filename": "drawingitems\/663231980_1285285108_441450.png", "number_of_users": "0", "description": null, "rating": "0", "thumbs_up": "0", "thumbs_down": "0", "first_name": "Raymond", "last_name": "Coldstar", "picture": null, "packageData": { "id": "26", "name": "The nice pics pack", "description": "description of the package would go here", "total_stamps": "123", "number_of_users": "234", "rating": "3", "thumbs_up": "2", "thumbs_down": "7" } } ] }, { "id": "212", "artist_id": "4", "house_owner_id": "1234567", "anonymous": "0", "stamps_used": "1", "timestamp": "2010-07-09 03:45:59", "note": "shake it baby", "stampsArray": [ { "id": "248", "name": "flying stick man 1", "author_id": "663231980", "created": "2010-09-23 23:37:08", "keywords_id": "6", "packages_id": "26", "public": "1", "package_category_id": "0", "filename": "drawingitems\/663231980_1285285027_288422.png", "number_of_users": "1200", "description": "stamp description would go here", "rating": "6734", "thumbs_up": "18", "thumbs_down": "22", "first_name": "Gary", "last_name": "Hoss", "picture": "http:\/\/profiles.com\/63231980_1168_q.jpg", "packageData": { "id": "26", "name": "The nice pics pack", "description": "description of the package would go here", "total_stamps": "6546345", "number_of_users": "234", "rating": "3", "thumbs_up": "2", "thumbs_down": "7" } }, { "id": "249", "name": "", "author_id": "1680999989", "created": "2010-09-23 23:38:28", "keywords_id": null, "packages_id": "26", "public": "1", "package_category_id": "0", "filename": "drawingitems\/663231980_1285285108_441450.png", "number_of_users": "0", "description": null, "rating": "0", "thumbs_up": "0", "thumbs_down": "0", "first_name": "Raymond", "last_name": "Blues Brutha", "picture": null, "packageData": { "id": "26", "name": "The nice pics pack", "description": "description of the package would go here", "total_stamps": "6543534", "number_of_users": "234", "rating": "3", "thumbs_up": "2", "thumbs_down": "7" } } ] }, { "id": "221", "artist_id": "663231980", "house_owner_id": "1234567", "anonymous": null, "stamps_used": null, "timestamp": "2010-09-13 07:35:25", "note": "hi jeremy", "first_name": "Coolio", "last_name": "Stars", "picture": "http:\/\/nowhere.com\/1980_1168_q.jpg" }, { "id": "227", "artist_id": "4321", "house_owner_id": "1234567", "anonymous": null, "stamps_used": null, "timestamp": "2010-09-24 01:24:19", "note": "" } ] } } hello i am making a online cook for people to register and make and online cookbook on there account i want them to be able to add recipes and be able to see them on there file, i know how it would connect to the database and how to send the information but what tables would i use and what fields? this is my basic site now www.lachlanmcgrath.net, if you can help please reply here or even e-mail me at lmcgr44@me.com thank-you for your help Umm.. Yeah, this MySQL line needs some reviewing list($total_banned_servers) = mysql_fetch_row(mysql_query("SELECT COUNT(id) FROM `toplist` WHERE banned='1' && serverowner=". $_SESSION['user'] ."")); I got a new laptop running Windows 7 and wanted to develop some PHP coding for test purposes.
I want the data I test to go into MySQL.
What do I need to do and where can I get the appropriate downloads to get started with the most basic of set-ups?
|