PHP - Keeping Two Db's In Sync?
I'm updating my database with a set of data from another database. When there is an item deleted from the source db, how would I make sure it's deleted from the db copy given that I have to run the update in a batch and can't run it when the item is deleted? Would I truncate the db at the beginning of each update, then pull all the of data over?
Similar TutorialsI am working with a site that needs some kind of calendar solution. Each user will have their own events calendar. The plan is that your events calendar could sync with google, ical, BB calendar when done. Should I build the calendar in PHP, then worry about syncing with these other apps? Or should I use come kind of 3rd party calendar to power the one I have? Or...does anyone know of any applications that help you sync calendars if I were to create one myself? I looked into google cals, but they have a limit on the amount of calendars per day you can create. Any ideas as to how I should go about this? All answers appreciated! Commands out of sync; you can't run this command now Query: DELETE FROM case_ref WHERE user_id='3';DELETE FROM updates WHERE user_id='3' php]<?php // Check if the form has been submitted: if (isset($_POST['delete'])) { if ($_POST['sure'] == 'Yes') { // Delete the record. // Make the query: $query = "DELETE FROM case_ref WHERE user_id='$id';"; $query .= "DELETE FROM updates WHERE user_id='$id'"; $r = mysqli_multi_query ($dbc, $query); if (mysqli_affected_rows($dbc) >= 1) { // If it ran OK. echo '<h3>All cases & updates associated with user have been deleted</h3>'; } // Make the query: $q = "DELETE FROM users WHERE user_id='$id' LIMIT 1"; $r = $r = mysqli_query ($dbc, $q); if (mysqli_affected_rows($dbc) == 1) { // If it ran OK. echo '<h3>User has been deleted</h3>'; } else { // If the query did not run OK. $errors[] = '<p class="error">The user could not be deleted due to a system error.</p>'; // Public message. $errors[] = '<p>' . mysqli_error($dbc) . '<br />Query: ' . $query . '</p>'; // Debugging message. } } else { // No confirmation of deletion. $errors[] = '<p class="error">The user has NOT been deleted.</p>'; } }else{ //show the form echo '<form id="form1" name="form1" method="post" action="delete_user.php?user_id=' . $id . '"> <table width="100%" border="1" cellpadding="5" cellspacing="5"> <tr> <td width="30%">Do you wish to delete this user?</td> <td width="19%"><input type="radio" name="sure" value="Yes" /> Yes </td> <td width="17%"><input type="radio" name="sure" value="No" checked="checked" /> No</td> <td width="34%"> <input type="submit" name="button" id="button" value="Submit" /> <input name="delete" type="hidden" id="delete" value="1" /></td> </tr> </table>'; } // Print any error messages, if they exist: if (!empty($errors)) { foreach ($errors as $msg) { echo "$msg\n"; } } mysqli_close($dbc); ?>[/php] Hey there I'm trying to gather a users Facebook info and use that to create a user account for them on my database. My code works perfectly for the first person who links his Facebook account with my site and adds all the user info to the database. After that with any other users it will display the logged in Facebook users name with their profile pic. The problem arises when it tries to add this person to the mysql database. It returns the error "An error has occurred and we are unable to sync your Facebook account." Before the <head> Code: [Select] <?php define('FACEBOOK_APP_ID', 'imagine_app_id_here'); define('FACEBOOK_SECRET', 'imagine_secret_here'); function get_facebook_cookie($app_id, $application_secret) { $args = array(); parse_str(trim($_COOKIE['fbs_' . $app_id], '"'), $args); ksort($args); $payload = ''; foreach ($args as $key => $value) { if ($key != 'sig') { $payload .= $key . '=' . $value; } } if (md5($payload . $application_secret) != $args['sig']) { return null; } return $args; } $cookie = get_facebook_cookie(FACEBOOK_APP_ID, FACEBOOK_SECRET); ?> In the <body> Code: [Select] <?php if ($cookie) { //###cookie is set, user is logged in $user = json_decode(file_get_contents('https://graph.facebook.com/'.$cookie['uid'])); define('INCLUDE_CHECK',true); require("connect.php"); $fbookid = $user->{'id'}; $fbookname = $user->{'name'}; $query = mysql_query("SELECT * FROM tz_members WHERE facebook_id='$fbookid'"); $numrows = mysql_num_rows($query); if ($numrows == 1){ echo "<font color='#FF0000'>You are logged in through Facebook.</font>"; } else { mysql_query("INSERT INTO tz_members(facebook_id,usr,regIP,dt) VALUES( '".$fbookid."', '".$fbookname."', '".$_SERVER['REMOTE_ADDR']."', NOW() )"); $query = mysql_query("SELECT * FROM tz_members WHERE facebook_id='$fbookid'"); $numrows = mysql_num_rows($query); if ($numrows == 1){ echo "<font color='#FF0000'>Your Facebook account has been synced with our user database.</font>"; } else { echo "<font color='#FF0000'>An error has occured and we are unable to sync your Facebook account.</font>"; } mysql_close(); } echo '<img src="http://graph.facebook.com/'.$user->{'id'}.'/picture" alt="'.$user->{'name'}.'"/>'; echo $user->{'name'}; echo '<fb:login-button perms="email,user_birthday" onlogin="window.location.reload(true);" autologoutlink="true"></fb:login-button>'; } else { //###user is not logged in, display the Facebook login button echo '<fb:login-button perms="email,user_birthday" autologoutlink="true"></fb:login-button>'; } ?> Javascript: Code: [Select] <div id="fb-root"></div> <script src="http://connect.facebook.net/en_US/all.js"></script> <script> FB.init({appId: '<?= FACEBOOK_APP_ID ?>', status: true, cookie: true, xfbml: true}); FB.Event.subscribe('auth.login', function(response) { window.location.reload(); }); </script> Any help would be greatly appreciated! Hi, I want to create a simple online buying site. I have an admin site with login where admin can add items to the database table, and change other fields such as price and description of product and I want to make a public html page to display the updates made in my admin page. I appreciate it if someone give me some suggestions on how to get started. My admin php scripts is working fine (so SQL queries for UPDATE, DELETE, INSERT) but I don't know how to 'sync' it with the an nice html table of products the user can checkbox off to purchase on the public website. Let me know, thanks. We are building a site for users to post articles on certain topics and we want to show their number of followers on various social media platforms. Apart from them having the means to add it manually, there must be a method of syncing with their account, that they punch in, so that it dynamically updates our database with their number of followers. How is it done? Hi folks, I'm curious if I can for example, save a file from my server and it will save to all other servers - obviously if they accepted the connection first. It's for a software I developed and is almost complete and know there will be frequent updates to it. Instead of users downloading upates, I want the update files from my server to somehow synchronize to their server automatically? Anything called this?? Thanks for info. Like 6 years ago I had made a forum software for me and my buddies to post on. It had worked all great until my friend had posted a character that skewed my whole database, unintentionly, he knew nothing about computers. But I really haven't dabbed in PHP since 2008, I'm just now getting back into it again. I need to know how I can make data from an input to be put into an MySQL database and not screw up my code. So something along the lines that make the code safe and not exploitable. Also any third party scripts on captcha would be great! What are the different ways you can keep a User "logged in"? From what I *vaguely* recall from a year or two ago when I read a whole hoard of PHP books, you commonly use cookies and sessions. But I'm asking this more from an OOP standpoint than a PHP standpoint. Let's say I have a User record in my database, and a User comes along and attempts to log in. In OOP terms, I would think you'd call some class to help log them in, and upon successfully logging in, you would "load" the User object into memory and set the "LoggedIn" field to "True". Then as long as that field was set in their object, they could surf all over the place and do things like change their account and buy things. Is that how you would do it in OOP? TomTees In my Payment Form, I have an ExpMonth (e.g. '01') and ExpYear (e.g. '2011'). Each value is assigned to $expMonth and $expYear respectively. I then need to combine them and keep the format ('MMYYYY'). I am afraid that this code may truncate leading zeros... Code: [Select] $expDate = $expMonth . $expYear Will my code work, or do I need to do something else to ensure the Month stays ('MM') and the year stays ('YYYY')? Debbie I've got a weird problem which affects only Safari browsers. Site A offers user a login page and validates the credentials by calling HTTPRequest on site B ( this call starts new session, user password is checked and session id stored in the db). If user login details are OK, site A redirects user to site B ( different domains and physical boxes). It worked well before the last Safari update (5.0.1) - when user login is being checked, server B creates session X, after the redirect, session_start() creates absolutely different session Y. All sessions are maintained by cookies only (SSL). Any ideas how to maintain the same session during the redirect? Thanks! Hi
I want to get my <footer> to appear at the bottom of my page, but I dont want it to be fixed there.
So if the middle contents of a page is very short, the <footer> will be visibled at the bottom of the browser, but if the page contents is long, then the <footer> would just disappear at the bottom of the contents.
Can this be done?
Thanks
Hi Guys
I'm building a php application where users must login to access a set of private images. The images display as a set of thumbs to the user, which they can click to download the full size image. so I need to read a whole batch images (500+) of them from a directory.
So I'd like some advice on the best way to:
1) Keep files from being world readable. I know you could probably achieve this using htaccess or storing them outside the document root but which is best given that I need to read a whole directory with hundreds of images? 2) How to access the images If it turns out storing the images off document root is the way to go, what's the most efficient way to read a directory off the doc root and access the individual images (readfile for instance)? Thanks in advance, Drongo I've finished designing my website home page and I've now moved on the some of the other pages, I want my header and footer to appear the same on every page. I've tried this basic way of linking the same stylesheet that makes up my header/footer in the second HTML file (already used in the homepage):
<link rel="stylesheet" href="footer.css" type="text/css"/> <link rel="stylesheet" href="header.css" type="text/css"/> I now understand that this isn't going to work. Would a server-side scripting language be my best bet here? Something like PHP? If so, would anyone be able to link me with an article on how I could do this in PHP, I presume with the include function? I've had answers elsewhere but this, for me, isn't working: "You are currently only linking the css for the header and footer. If you want to include the html as the same, create two separate files header.php and footer.php, then include them into each webpage. <?php include('path/to/header.php');?> // in the location you want the header in the page <?php include('path/to/footer.php');?> // in the location you want the footer Essentially, you're making partials and placing them wherever you want them" Any help would be greatly appreciated. Edited by Coplestone, 15 January 2015 - 11:52 AM. What is the best way to keep track of a User's (real-time) online status? Right now I have a Log In script and I set the status in the User's Session, and then "pass" that status from page to page with session_start();. However, the problems with this approach include... 1.) A User is idle for hours or days and thus not really online 2.) A User leaves my site and thus is not really online (Or does closing the window change that?) I want a fairly accurate and real-time reading of whether or not a User is actively using my site so I can set their "Online Status" icon as green (online) or yellow (in active) or grey (offline). Any idea how to accomplish that so I have monitoring like you'd see on an Instant Messenger App? Thanks, Debbie
I need to create the unique SKU (Stock Keeping Unit) name for each products mixed with i.e.: SKU for a product with
id=13, becomes : BI-IKHA0013 This is how I tried: $inm = "Bio Clean green500ml"; $cnm = "INSECTS KILLERS"; $bnm = "HARPIC "; echo SKU_gen($inm, $cnm,$bnm,20).'<br>'; function SKU_gen($pname, $cat=null, $brand=null, $id = null, $l = 2){ $results = ''; // empty string $str1 = array_shift(explode(' ',$pname)); $str1 = strtoupper(substr($str1, 0, $l)); $str2 = array_shift(explode(' ',$cat)); $str2 = strtoupper(substr($str2, 0, $l)); $str3 = array_shift(explode(' ',$brand)); $str3 = strtoupper(substr($str3, 0, $l)); $id = str_pad($id , 4, 0, STR_PAD_LEFT); $results .= "{$str1}-{$str2}{$str3}{$id}"; return $results; } But this function is not working as expected when category of brand values become NULL. Hello, I am having an issue where PHP nulls the donation amount after multiple form submits. Here is a synopsis of what is happening. 1: User enters donation amount and clicks 'submit' 2: Is taken to a confirmation page where they must agree to terms 3: User fails to agree to the terms, the page is reloaded with an error message, and the donation amount is set to null I want to make the donation amount display despite multiple confirm page reloads. How would I do this? Here is the site to test it yourself. Ignore the steamid input and check "do not change my rank upon donation" to test. http://forums.stgdarkrp.org/donate2/check.php Please note: If you use IE, the formatting is messed up, that is a problem I will look into later I am trying to take a specific link from my site and place it into my database. I only want links starts with CORPSEARCH.ENTITY_INFORMATION?p_nameid= Can someone point me in the right direction here? Code for this is below: // make the cURL request to $target_url $html= curl_exec($ch); if (!$html) { echo "<br />cURL error number:" .curl_errno($ch); echo "<br />cURL error:" . curl_error($ch); exit; } // parse the html into a DOMDocument $dom = new DOMDocument(); @$dom->loadHTML($html); // grab all the on the page $xpath = new DOMXPath($dom); $hrefs = $xpath->evaluate("/html/body//a"); for ($i = 0; $i < $hrefs->length; $i++) { $href = $hrefs->item($i); $url = $href->getAttribute('href'); $sql="INSERT INTO links(cid, nlink)VALUES('$i','$url')"; $result=mysql_query($sql); echo $result; echo $url; Hi all, I followed a tutorial to get the base of a php calendar done, then added some custom Javascript in order to be able to change the color of the cells. The calendar can be seen he http://www.education-world.co.uk/Education%20World%20Site/calendar.php The problem is now, that I need to integrate a SQL database to keep track of what was set for certain dates. I'm not sure of how to even begin this, all i need to do is keep track of if the candidate is available, not available or working for a specific day. The calendar is submitted to an email but this means when they return at a later date (availability may change) their previously set availability will have been wiped! I can provide code if needed. Can anyone help me out here, really struggling with this! Many thanks, Greens85 This sounds like it should be pretty simple but I've looked for a while and I'm having trouble finding an answer. What I have is a simple table with 3 columns with predetermined widths. When the text that is queried from the database is inserted into the table, and the text string is longer than the column width, it pushes the text to a second line, which throws the whole table out of whack. Instead, I want the text to be cut off before going to the next line. For example: This is what is happening: This is a sample string of text. This is what I'm trying to do: This is a sample string... Can anyone tell me where to find the solution to this problem? Not that it's needed, but here is some simple code that I'm working with: Code: [Select] <?php $message = "This is a sample string of text."; echo "<table width=\"150\" height=\"20\"border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"; echo "<tr>"; echo "<td width=\"50\" height=\"20\" align=\"left" valign=\"top\">Column 1</td>"; echo "<td width=\"50\" height=\"20\" align=\"left" valign=\"top\">Column 2</td>"; echo "<td width=\"50\" height=\"20\" align=\"left" valign=\"top\">$message</td>"; echo "</tr>"; echo "</table>"; ?> I have a directory in public WWW. The files throughout the directory have many PHP includes amongst themselves. For example, the file "registration.php" begins with require('../parameters.php'); The directory is complex, like this:
/Public WWW directory/ How would I do that without breaking all the include paths? (I know the solution is probably a one-liner involving __DIR__ ... but I can't seem to code it so it works). Thank you!!
|