PHP - Storing Info In A Database Vs. Creating A Txt File [facebook Related]
Okay, I'll make this short and sweet, and all side comments are irrelevant. I'm doing this for my own happies
So using Facebook.com's API you can extract all of a specific user's friends in an array. Well I'm making a array check to see who on that users friend list was removed or deleted them that week using array_dif(); in this method: 1) User allows the application 2) Application catches the user's friends_id's in an array and stores them // this is where i'm having trouble, i'll come back to it 3) User then waits a few days and notices their friend count is no longer 400, it's now 399! 4) User logs into my application, and checks the previously uploaded array against their current array of friends. Okay now to the part i'm struggling with is, what would you do? Should i store them each uniquely in a database? Because some users have 4,000+ friends and that gets quite strenuous. OR! Should i save them into a txt file unique to that person's user_id. I kind of like the 2nd option, however it's less ( to my newbish mind ) customizable versus the sql_queries. Once again, i'd like to reiterate, i don't care that this is again Facebooks terms of service, it's for my own personal gain and just enjoy taking on projects in my spare time that force my brain to work hard. That's all, hope you excuse the typos and poor grammar. Typed this pretty quickly, any questions - feel free to ask! Similar TutorialsTo me it is logical to store config data such as site name, meta, etc in a php file rather than storing ina table in mysql database. This will reduce the number of calls to the mysql database, as these are key parameters and needed in every page. But, a well-developed CMS like Wordpress uses a mysql table to store such basic data. What is your idea? Ain't it better to reduce mysql loads? I've created a function to update the database with the information from the text file...I've already got additional code (not posted here) that displays the orders that have NOT been shipped (and works beautifully). Then when they click the button it should process the text file and update the database (input the tracking number into the database) and change the order status and send an email to the customer, I know I've got something mixed up because it's not working... function process_shipping($ordernumber, $status=''){ $order_updated = false; $check_status_query = tep_db_query("select customers_name, customers_email_address, orders_status, date_purchased from " . TABLE_ORDERS . " where orders_id = '" . $ordernumber . "'"); $check_status = tep_db_fetch_array($check_status_query); $orders_statuses = array(); $orders_status_array = array(); $orders_status_query = tep_db_query("select orders_status_id, orders_status_name from " . TABLE_ORDERS_STATUS . " where language_id = 1"); while ($orders_status = tep_db_fetch_array($orders_status_query)) { $orders_statuses[] = array('id' => $orders_status['orders_status_id'], 'text' => $orders_status['orders_status_name']); $orders_status_array[$orders_status['orders_status_id']] = $orders_status['orders_status_name']; } if ($status!==''){ if ($check_status['orders_status'] !== $status) { tep_db_query("update " . TABLE_ORDERS . " set fedex_track_num = '" . $tracking . "'orders_status = '". $status . "', last_modified = now() where orders_id = '" . $oID . "'"); $customer_notified = '0'; $notify_comments = ''; $email = STORE_NAME . "\n" . EMAIL_SEPARATOR . "\n" . EMAIL_TEXT_ORDER_NUMBER . ' ' . $oID . "\n" . EMAIL_TEXT_INVOICE_URL . ' ' . tep_catalog_href_link(FILENAME_CATALOG_ACCOUNT_HISTORY_INFO, 'order_id=' . $oID, 'SSL') . "\n" . EMAIL_TEXT_DATE_ORDERED . ' ' . tep_date_long($check_status['date_purchased']) . "\n\n" . $notify_comments . sprintf(EMAIL_TEXT_STATUS_UPDATE, $orders_status_array[$status]); tep_mail($check_status['customers_name'], $check_status['customers_email_address'], EMAIL_TEXT_SUBJECT, nl2br($email), STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS); $customer_notified = '1'; tep_db_query("insert into " . TABLE_ORDERS_STATUS_HISTORY . " (orders_id, orders_status_id, date_added, customer_notified, comments) values ('" . (int)$oID . "', '" . tep_db_input($status) . "', now(), '" . tep_db_input($customer_notified) . "', '" . tep_db_input($comments) . "')"); $order_updated = true; } } } if ($_POST['update']=='1') { echo '<div class="dataTableContent" align="left">'; $arr=file("/home/onest4/public_html/beta/fedex.txt"); $x=1; foreach($arr as $str){ if (trim($str) != ''){ if ($x > 3){ list($tracking,$oID)=explode(" ",$str); if(ctype_digit($tracking)){ echo "Order# $oID, <b>$tracking</b> (DATABASE UPDATED)<br>"; } }else{ $x++; continue; } } } } I have an facebook application, I look in the errors log routinely to see if there are any abnormalities. Today, I found one. Code: [Select] [Sun Feb 27 15:28:25 2011] [error] [client **.***.71.38] PHP Notice: Undefined offset: 0 in *** on line 33 [Sun Feb 27 15:28:26 2011] [error] [client **.***.71.38] Exception: 121: Param pid must be a valid merged photo id Now, I have no idea what is going on here. I have found the location of where the error occurs: Code: [Select] $fb_photo = $facebook->api("me/photos", "POST", $attachement); $FQLQuery = "SELECT object_id, pid, src_big, link FROM photo WHERE object_id = " . $fb_photo['id']; $FQLResult = $facebook->api(array('method' => 'fql.query', 'query' => $FQLQuery, 'access_token'=> $session['access_token'])); $targetPhoto = $FQLResult[0]; I tried to help a user of mine get their account back on track, however, re-authenticating the application seems like the only way to fix it. It works for most of the users, however, there are a couple few who get my exception message. If anyone has any knowledge of whats going on here, that would be appreciated Hi guys, hoping for some help here. I've a database created with a website. I recently got help here off Muddy Funster who was a MASSIVE help to me on this thread - http://www.phpfreaks.com/forums/index.php?topic=357580.new;topicseen#new I've another slight problem with what I am trying to do. At the moment the user can search for an ID and it brings up the relevant information. What I am doing now is that the user has entered the ID, their taken to the results where they can be viewed. What I have added is a form at the bottom of the results page, which has to be filled in and saved. I thought this would be relatively easy. I have the form storing in the database, but there is one problem, its being added as another document! So instead of clicking save and the information being added to the ID that is already associated with it, it is incrementing the ID in the database and being stored separately to the ID that was searched. Could anyone give any help as to why this might be happening? I have on the button 'Save' click, it goes to another php file and inserts the data to the relevant fields, I'm not sure why it is incrementing the ID separately instead of just saving to the ID that it is associated with I don't no if I'm making it clear enough but what I wanted to do was save the form they filled out with the ID that was searched if you get me? Thanks for any help This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=315057.0 Hello every one i need your help please about this i would like to add this tabs to my facebook fan page i got App allowing me to put php coding or html but i need when some one add his info and click on submit i receive it at my email so can any 1 here help me or tell me what shall i do ? i newbie and hope to get your help guys please Hi Im created a market place website, sort of like eBay. I want to allow the shop owners to be able to message the user who has purchased an item from them and vice-versa. I want it to be like Facebook where a user sends a message, and if they reply, it becomes a thread which they reply to. But if a user send a message thats not in reply to a thread, a new thread is formed What I'm looking for is the correct model to use. I set up these 2 table: Message table MessageID -> primary key FromID -> id of sender ToID -> id of receiver Message -> the text of the messsage Date -> date message was sent Thread table ThreadID -> ID linking messages together that aer in the same thread MessageID -> foreign key to Message table I want to know, am I on the right track with this? Its loooking like I'll need to use a cursor to get back the Username of the FromID person and ToID person in the same row. i dont like cursors! Any tips on what i should do or does anybosy have links to a site with a tutorial on building a system like this? Thanks in advance I have a standard form that displays users current data from a mysql database once logged in(code obtained from the internet). Users can then edit their data then submit it to page called editform.php that does the update. All works well except that the page does not display the updated info. Users have to first logout and login again to see the updated info. even refreshing the page does not show the new info. Please tell me where the problem is as i am new to php.
my form page test.php
<?PHP require_once("./include/membersite_config.php"); if(!$fgmembersite->CheckLogin()) { $fgmembersite->RedirectToURL("login.php"); exit; } ?> <form action="editform.php?id_user=<?= $fgmembersite->UserId() ?>" method="POST"> <input type="hidden" name="id_user" value="<?= $fgmembersite->UserId() ?>"><br> Name:<br> <input type="text" name="name" size="40" value="<?= $fgmembersite->UserFullName() ?>"><br><br> Email:<br> <input type="text" name="email" size="40" value="<?= $fgmembersite->UserEmail() ?> "><br><br> Address:<br> <input type="text" name="address" size="40" value="<?= $fgmembersite->UserAddress() ?> "><br><br> <button>Submit</button>my editform.php <?php $con = mysqli_connect("localhost","root","user","pass"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } mysqli_query($con,"UPDATE fgusers3 SET name = '".$_POST['name']."', email= '".$_POST['email']."', address= '".$_POST['address']."' WHERE id_user='".$_POST['id_user']."'"); header("Location: test.php"); ?> This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=331354.0 Hello guys, hope all of you are doing good. I want to ask a quick question . I have developed this track and trace application (php script) through which users can trace their shipment by entering a bill of lading number in the track and trace interface on our website and then the information stored in our database is displayed to them. Currently, what I do to add new or change the status of existing bill of lading numbers is that first I have to log in to the cPanel of my website, then I need to log in to phpmyadmin and then I can add new bill of lading numbers or change the number of existing bill of lading numbers. This is a pretty long way and I don't want to give the cPanel password to other employees so that they can do the job of entering bill of lading numbers. So I was thinking that can an interface be created through which any employee can add new or change the status etc. of the bill of lading numbers stored in the database without actually logging in to phpmyadmin? The interface would obviously be connected to the database and any new bill of lading number entered through the interface should automatically be stored in the database. And on the other hand, the bill of lading numbers which are already stored in the database, they can also be edited through this interface. Please let me know if such an interface can be created. And if yes, is there any tutorial on how this can be done? Thanks. Quote i want to store a value from a database and use it as variable in php code can anyone help me out in this code i want to store value of copies in a php variable and want that it should be more than 0 (zero) for furthur calculations $update_book="update book set copies=copies-1 where bookid='$bookid'"; $result=mysql_query($update_book,$linkID1); if($result) { print "<html><body background=\"header.jpg\"> <p>book successfully subtracted from database</p></body></html>"; } else { print "<html><body background=\"header.jpg\"> <p>problem occured</p></body></html>"; } Hello. Trying to learn MVC better by creating my own little framework to understand how it works. Things were going OK til now. I have a base class: <?php /** * Base class most classes will extend from. * Simply put, this class just has methods that * most, if not all, classes will need. */ class Application { public function includer($path) { if (is_readable($path) == true) { include_once($path); } else { die("404 not found =["); } } } ?> So the above method 'includer' just sees if a file exists/is readable and if so, include it. Here's where I am using said method. class Index extends Application { function __construct($method = 'view') { // load the index model include(ROOT . '/app/models/model.index.php'); // Invoke requested method. $this->$method(); } public function view() { $name = 'Smith'; $this->includer(ROOT . '/app/views/view.index.php'); # Problem here, i think } } view.index.php just contains <?php echo $name; ?> All that is called from the index page, with this line of code Application::includer($controller_path); Now, in line $this->includer(ROOT . '/app/views/view.index.php'); # Problem here, i think If i get rid of $this->includer, the script will work and say 'Smith'. If i have $this->includer(...) or parent::includer(...), it doesn't work. why? I need some advice, I'm not sure if this is the right section to post this or not but I'll give it a try. I am creating a website for a small group of people to be able to message back and forth. I ran into a problem when doing the whole reply to a message option. I dont want to have each individual message as a new entry in my database, and then look for each message in that conversation when loading the conversation, I thought about inserting something like +=+=+=+=+=+= in between messages in the conversation so that when i pull up that conversation i could just separate the messages into an array by looking for that +=+=+=+=+=+= in the string of text and separating all the messages out. I want to know if anyone knows a better way of doing this or if this is a good way to go. thanks for any suggestions. Dear All, I am developing a like/dislike voting system for a scientific experiment in which the user will cast vote on a number of images. I have already written the code for it but the code is unable to store the data in the database. Kindly help me out in this issue. Below is my code for it: HTML Form for Like/Dislike Button: Code: [Select] <html> <head> <title> Like/Dislike buttons </title> </head> <body> <h1> Like/Dislike buttons </h1> <form name="form1" action="likedislike.php" method ="post"> <input type="submit" name="Like" value="Like"> <input type="submit" name="Dislike" value="dislike"> </form> </body> </html> PHP code for retrieving data and storing the vote in the database: Code: [Select] <?php session_start(); ob_start(); $host="localhost"; $username="computat_abhi"; $password="1123581321"; $databasename="computat_button"; $tbl_name="record"; $db=mysql_connect ("localhost","computat_abhi","1123581321")or die("cannot connect"); mysql_select_db($databasename,$db); if( isset($_POST['Like']) ) { $sql = 'INSERT INTO record(Image Number,Like Counter) VALUES ("b1.php",1)'; $result = mysql_query($sql); } elseif(isset($_POST['Dislike'])){ $sql = 'INSERT INTO record(Image Number,Dislike Counter) VALUES ("b1.php",1)'; $result = mysql_query($sql); } ob_end_flush(); ?> Thank you for your help. Hi I am using Zen-Cart to which I have made significant changes. Two years ago I managed to change the Products Sort Order from Integer to Decimal(5,2) to store books such as 1, 1.5, 1.75, 2 etc. Regrettably we had a major server issue and I also lost the new coding. Having restored everything else whenever we enter a book series number such as 1.5 it only stores as 1. To date the zen-Cart forums have been unable to offer a solution so I am reaching out to see if anyone else can advise me of how to get this working again please.
Thanks in advance Owen
I've got an array like this: $firstquarter = array('January', 'February', 'March'); Then I'm adding it to a MySQL DB as follows: $insert = "INSERT INTO sometable (months) VALUES ('$firstquarter') "; $insertresult = mysql_query($insert) or die ('Error in Insert query: ' . mysql_error()); When I use PHPMyAdmin I see a this value stored in the DB: 'Array' Can I retrieve the values, by index, from this database field?? For some reason my for loop only seems to be storing some data in my fields, most of the time the data is not true but simply duplicating one of the entries. So instead of having a string of 1,2,3,4 for instance it would store all of them as 4. The entires are selected using fields in a multiple select box, in theory of someone choses 10 unique entries from the "Systems" category all 10 should be made into rows in the MySQL table. Any idea why this is happening? The form, if ($type == "games") { echo "<tr><td>".$name."</td><td><select name='".$name."_".$i."'[] multiple='multiple'><option value='' selected>--------</option>"; $sqla = mysql_query("SELECT * FROM ".$pre."games ORDER BY `name` ASC") or die(mysql_error()); while($row2a = mysql_fetch_array($sqla)) { $system = mysql_fetch_array(mysql_query("SELECT * FROM ".$pre."systems WHERE id = '".$row2a[system]."'")); echo "<option value='".$row2a[id]."'>".$row2a[name]." - ".$system[name]."</option>"; } echo "</select></td></tr>"; } if ($type == "system") { echo "<tr><td>".$name."</td><td><select name='".$name."_".$i."'[] multiple='multiple'><option value='' selected>--------</option>"; $sqlb = mysql_query("SELECT * FROM ".$pre."systems ORDER BY `name` ASC") or die(mysql_error()); while($row2b = mysql_fetch_array($sqlb)) { echo "<option value='".$row2b[id]."'>".$row2b[name]."</option>"; } echo "</select></td></tr>"; } The PHP code, while($row = mysql_fetch_array($query)) { $name = "$row[name]"; for ($i = 0; $i < count($_POST["systems_$i"]); $i++) { mysql_query("INSERT INTO ".$pre."fielddata VALUES (null, 'systems', '".$_POST["systems_$i"]."', '".$fetch[0]."', 'content')"); } for ($i = 0; $i < count($_POST["games_$i"]); $i++) { mysql_query("INSERT INTO ".$pre."fielddata VALUES (null, 'games', '".$_POST["games_$i"]."', '".$fetch[0]."', 'content')"); } Okay I'm a newbie at PHP but was trying to write a counter for my website to count the amount of times a specific button is clicked. My desired outcome is as follows: If the form submit button "like" or "dislike" is clicked, get user's ip and check to see if it already exists in the database. If it exists, don't increment the count (of either button), otherwise log the ip and increment the count (of whichever button is clicked) by 1. Currently I've got the increment working (testing only the like button at the moment) and I've got the ip being stored into the database, but cannot get the comparison to work. Each time the button is clicked it adds the ip address into the database instead of disallowing it. Note: there are two different tables--one storing the ip (counter) and one storing the like clicks (Designs) (dunno if there's a better way?) Excuse my newbieness. The problem area: (like button only): if(isset($_POST['like'])) { $ip_address = $_SERVER['REMOTE_ADDR']; $query = mysql_query("SELECT ip FROM counter WHERE ip = '$ip_address'"); $num_rows = mysql_num_rows($query); if ($num_rows > 0) { die ("You've already clicked the button!"); } else { mysql_query("INSERT INTO counter VALUES ($ip_address)"); mysql_query("UPDATE Designs SET up = up + 1 WHERE ref = 'cataclysm'"); } } $select = mysql_query("SELECT up FROM Designs"); while($row = mysql_fetch_array($select)) { echo $row['up']; } Hi, wondering if somebody can tell me where I'm going wrong (I'm new to all of this). I have the following php code which uploads an image file into my database: Code: [Select] //Connect to database include 'Resources/Include/db.inc.php'; $tmp=$_FILES['image']['tmp_name']; //get users IP $ip=$_SERVER['REMOTE_ADDR']; //Don't do anything if file wasn't selected if (!empty($tmp)) { //Copy file to temporary folder copy($tmp, "./temporary/".$ip.""); //open the copied image, ready to encode into text to go into the database $filename1 = "./temporary/".$ip; $fp1 = fopen($filename1, "rb"); //record the image contents into a variable $contents1 = fread($fp1, filesize($filename1)); $contents1 = addslashes($contents1); //close the file fclose($fp1); $ftype = $_FILES['image']['type']; //insert information into the database if(!mysql_query("INSERT INTO LetterImages (Data,Type,LetterID,Page)"." VALUES ( '$contents1', '$ftype',1,1)")){ echo mysql_error(); } //delete the temporary file we made unlink($filename1); } This seems to work ok, as when I go to the LetterImages table there is now an additional row with a file in the blob field. I then have the following code which is supposed to display the image: Code: [Select] $result=mysql_query("SELECT * FROM LetterImages WHERE LetterID=1 AND Page=1"); //fetch data from database $sqldata=mysql_fetch_array($result); $encoded=stripslashes($sqldata['Data']); $ftype=$sqldata['Type']; //tell the browser what type of image to display header("Content-type: $ftype"); //decode and echo the image data echo $encoded; Instead of displaying an image, however, this just displays pages and pages of incomprehensible data. Can anybody tell me where I'm going horribly wrong? hi, I have created a login page this is my code <?php if (!isset($_SESSION)) { session_start(); } $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="Marketing"; // Database name $tbl_name="Marketinglogin"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM Marketinglogin WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("myusername"); session_register("mypassword"); if ($myusername == "sandeep") { header("location:Marketingadmin.php"); } else { header("location:Marketingemployeeform.php"); } } else { echo "wrong password"; } ?> Marketingemployee form has some fields..here when we click submit button all the fields as well as the loginusername has to be stored in the database <?php if (!isset($_SESSION)) { session_start(); } $con = mysql_connect("localhost","root", ""); if (!$con) {die('Could not connect to DB: ' . mysql_error() );} mysql_select_db ("Marketing", $con); $date = $_POST['year'].$_POST['month'].$_POST['dt'] ; $_SESSION['myusername']=$_POST['myusername']; $myusername=$_SESSION['myusername']; $sql="INSERT INTO Marketingemployeetable (Employeeid, Date,Sector,Place,Contactpersonname,Contactaddress,Mobileno)VALUES ( '$myusername','$date','$_POST[project]','$_POST[place]','$_POST[Contactpersonname]','$_POST[Contactaddress]','$_POST[Mobileno]')"; if (!mysql_query($sql,$con)) {die ('Error: ' . mysql_error());} echo "Record added"; mysql_close($con)?> please help me out here |