PHP - Copy Table Data From One Databse To Another Databse Table Daily
Hi all
I am describing my problem below can any body please look into this I have two databases DB1:datain1 DB2:datain2 having the below structure database, table, fields datain1 , student , id,name datain2 , student , id,name the two databases having same structure My query is i want copy all data from datain1 to datain2 on daily process through php script(script will be executed manually on daily) i don't want any duplicate or repeated data in datain2 give me some script to do this kindly help me to solve this its so urgent Similar TutorialsHi... I planned to create db table daily. When day begin button clicked (text box has date Value) master dB can be copied,with the name of text box value ($date). If already day begin then it show day begin done. How can I do that. Please guide me
My db table has columns "id" (int-11), "date(varchar-50)", "author name(varchar-100)", "text (varchar-100000)"... I am storing images + text in text field of database. Everything is going fine while i am using ckeditor to insert data into the database for that particular text field. Now when i am retrieving data from database... i am able to extract id, date, autorname successfully (i have check it while the issue came)..but when i am trying to retrieve text field which have image, that jumps to page not found error... what could be the issue... am i having problem with database or editor that i am using???? Code: [Select] $sql= ("INSERT INTO custcards (username,Card_Number,Card_Type,Card_Name,Card_End) VALUES('$username','$cardnumber','$cardtype','$cardname','$cardend')"); if (isset($_GET['submitted'])) { if (checkCreditCard ($_GET['CardNumber'], $_GET['CardType'], $errornumber, $errortext)) { $errortext = 'This card has a valid format'; // Default text if card is VALID $result = mysql_query($sql)){ echo "$errortext"; // Echo/Show this text } } else { echo '<p align=center>';echo "$errortext"; // Display ERROR Type/Text echo "ERROR: ".mysql_error(); } } The code is to check details beign entered and to make sure thier correct and then print the correcrt message but i also want it to store the details into a table i know i havent got the syntax correct was wondering is anyone can help ? I need to perform a search of my DB using 6 fields. I want to progress thru the searches as so: Row: A B C D E F Select A, if A then select B, if B then select C if C then select D, if D select E, if E then select F I then want to extract the data from each field. if A then $a = A, if B then $b = B, etc etc. I don't want to have a whole bunch of different select statements or if conditions if I don't need to. Also, the DB is rather large so i think evaluating: $query = "SELECT * FROM table" Might be overkill. Is there anyway to do something like: $queryA = SELECT * FROM table WHERE A = subject1 if($queryA){$queryB = SELECT * FROM $queryA WHERE B = subject2} if($queryB){$queryC = SELECT * FROM $queryB WHERE C = subject3} etc etc etc So basically I just progressively filter down one original mysql query to get what I need. Ik probeer een online gehost .xml bestand in een database te plaatsen.
Ik heb inmiddels alle foutmeldingen weg weten te werken (door ze op te lossen :-)) maar heb nu een blanco pagina zonder errors en geen data in mijn database
Hier is wat ik tot nu toe heb gedaan.
<?php // Turn off all error reporting error_reporting(0); // Report simple running errors error_reporting(E_ERROR | E_WARNING | E_PARSE); // Reporting E_NOTICE can be good too (to report uninitialized // variables or catch variable name misspellings ...) error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE); // Report all errors except E_NOTICE error_reporting(E_ALL & ~E_NOTICE); // Report all PHP errors (see changelog) error_reporting(E_ALL); // Report all PHP errors error_reporting(-1); // Same as error_reporting(E_ALL); ini_set('error_reporting', E_ALL); // specify url of xml file $xmlData = file_get_contents(get_bloginfo('template_directory').'/import/external_db.xml'); // read XML data string $xml = simplexml_load_string($xmlData) or die("ERROR: Cannot create SimpleXML object"); // create and execute INSERT queries foreach ($xml->item as $item) { $id = $item->id; $name = mysqli_real_escape_string($item->name); $code = mysqli_real_escape_string($item->code); $email = mysqli_real_escape_string($item->email); $jobdescription = mysqli_real_escape_string($item->jobdescription); $salary = mysqli_real_escape_string($item->salary); $sql = "INSERT INTO wajv_employees (id, name, code, email, jobdescription, salary) VALUES ('$id', '$name', '$code', '$email', '$jobdescription', '$salary')"; mysqli_query($sql) or die ("ERROR:"); } //mysql_close($connection); ?>Dit is de XML: <?xml version="1.0" encoding="utf-8"?> <data> <Item> <field name="name">xxx</field> <field name="code">101</field> <field name="email">xxx@xxx.nl</field> <field name="jobdescription">Job Description</field> <field name="salary">1000</field> </Item> <Item> <field name="name">xxx</field> <field name="code">102</field> <field name="email">xxx@xxx.nl</field> <field name="jobdescription">Job Description</field> <field name="salary">1000</field> </Item> <Item> <field name="name">xxx</field> <field name="code">103</field> <field name="email">xxx@xxx.nl</field> <field name="jobdescription">Job Description</field> <field name="salary">1000</field> </Item> <Item> <field name="name">xxx</field> <field name="code">104</field> <field name="email">xxx@xxx.nl</field> <field name="jobdescription">Job Description</field> <field name="salary">1000</field> </Item> </data>Hoop dat iemand mijn fout over het hoofd ziet Hi All,
I need to get a small function working for a site I need to build for a group of friends.
I was able to get a login page, and a way to add data to the data base.
Now I am stuck on the search and show results fuctionalities.
I have found tens of scripts on the internet, but most of them are outdated, or I cant get them to work, either it sends me back a blank page, does nothing or sends me to an error page
The GOAL
User Inputs text in a text box, clicks submit, the data in the text box is looked for in the second collumn of the DB, The information of the collumns 2 to 7 of the DB for the name search are displayed either on the same page or on a new page.
Is there any chance you could hel me with that, taken into account that I dont need the html part of the code, I only need help with the php part...
Thanks in advance to all the people reading this and the ones helping me...
Hi guys, Im currently doing a project for college and i have experienced some problems with saving my php drop down values to my database. im am getting no error but my values are not being stored to my db.If anyone could help me or point me in the correct direction then id be grateful. Ive attached my code. I have insert image using this following code but i want to know where it is storing i want file path of the imahe what i have inserted Code: [Select] <html> <head><title>File Insert</title></head> <body> <h3>Please Choose a File and click Submit</h3> <form enctype="multipart/form-data" action= "<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="10000000" /> <input name="userfile" type="file" /> <input type="submit" value="Submit" /> </form> </body> <?php // check if a file was submitted if(!isset($_FILES['userfile'])) { echo '<p>Please select a file</p>'; } else { try { upload(); //this will upload your image echo '<p>Thank you for submitting</p>'; //Message after uploading image } catch(Exception $e) { echo $e->getMessage(); echo 'Sorry, could not upload file'; } } // the upload function function upload(){ include "file_constants.php"; $maxsize = $_POST['MAX_FILE_SIZE']; if(is_uploaded_file($_FILES['userfile']['tmp_name'])) { // check the file is less than the maximum file size if( $_FILES['userfile']['size'] < $maxsize) { // prepare the image for insertion $imgData =addslashes (file_get_contents($_FILES['userfile']['tmp_name'])); // put the image in the db... // database connection mysql_connect($host, $user, $pass) OR DIE (mysql_error()); // select the db mysql_select_db ($db) OR DIE ("Unable to select db".mysql_error()); // our sql query $sql = "INSERT INTO test_image (image, name) VALUES ('{$imgData}', '{$_FILES['userfile']['name']}');"; // insert the image mysql_query($sql) or die("Error in Query: " . mysql_error()); } } else { // if the file is not less than the maximum allowed, print an error echo '<div>File exceeds the Maximum File limit</div> <div>Maximum File limit is '.$maxsize.'</div> <div>File '.$_FILES['userfile']['name'].' is '.$_FILES['userfile']['size']. ' bytes</div> <hr />'; } } ?> </html> I am building a new web app and want to make sure I do everything right from the beginning. What is the best method of storing the date and time into a database using PHP along with the table field settings? Dear all, Please help me. I have two sites and both run on separate DB, both have separate signup and login process, Now i want if any user login from any site can access both sites. There are separate session for both sites now i want to use any of the session for user authentication. Please give suggestions. Thanks, Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <?php $hostname='xxx'; $username='xxx'; $password='xxx'; $dbname='xxx; $usertable=xxx; $myconn=mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.'); if ((($_FILES["file"]["type"] =="image/gif") || ($_FILES["file"]["type"] =="image/jpeg") || ($_FILES["file"]["type"] == "image/png")) && ($_FILES["file"]["size"]< 200000)) { if ($_FILES["file"]["error"] >0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br/>"; } else { if (file_exists("uploads/" . $_FILES["file"]["name"])) { echo "File already exists. Choose another name."; } else { move_uploaded_file($_FILES["file"]["tmp_name"],"uploads/" . $_FILES["file"]["name"]); } } } else { echo "Invalid file"; } $path="uploads/" . $_FILES["file"]["name"]; $desc=$_POST["desc"]; if (!myconn) { die ('Could not connect: ' . $mysql_error()); } $db_selected=mysql_select_db('xxx',$myconn); if (!$db_selected) { die ('Can\'t use xxxx : ' . mysql_error()); } mysql_query("INSERT INTO partners (desc,photopath,state) VALUES ('$desc','$path','$state')"); mysql_close($myconn); ?> </body> </html> Im trying to write some code for a raffle, when someone buys one ticket it works well but if someone buys ten tickets. i would like it to put each one on a new row, the last column is the ticket number which is got by another table called count and i want the new count in the last column of each row. In the actual script there is more than two columns but this is an example just to try to let you know what im trying to do. As you can see i want the ticket number to increment by one every time someone buys tickets. (the ticket number is in a simple table with just id and ticket number) EXAMPLE someone buys 2 tickes name | ticket number John | 1 john | 2 then someone buys three tickets jane | 3 jane | 4 jane | 5 This is what i have. (WORKING EXAMPLE of the code tha doesnt work.) as you can see the ticker number stays the same and not increment by one. <?php $num //is a number between 1 and 10 $tr //is the current count got from database (this needs to count up by one every entry) include 'includes/connect.php'; $num = "3"; // number of tickets someone buys. $count = "5"; // count of tickets already sold (so this is start count for this transaction). $id = "1"; // this is the line the counter is on to keep count updated for the amount of tickets sold. $name = 'john'; //example name for($i=0;$i< $num;$i++){ $count="$count+1"; // increments count by 1 $sql123 = "UPDATE count SET count=$count WHERE id='$id'"; //should update database to new count $sql = "INSERT INTO test (name, number) VALUES ('$name', '$count')"; if($result = mysqli_query($con, $sql)){ echo "<br>tickets bought and entered into database,<br>Thank you<br>"; } else { echo "Error: " . $sql . "<br>" . $con->error; } } ?> Not sure what im doing wrong? Thank you in advance Nook6 I want to delete rows in a table of my database using check-box. Here are my codes below: Code: [Select] <?php $con = mysql_connect('localhost', 'root', '') or die ('Connection Failed'); mysql_select_db('img', $con) or die ('Connection Failed'); $display = mysql_query("SELECT * FROM photos WHERE email='$lemail'"); echo '<input type="submit" value="Delete" name="del"/>'; echo "<table> <tr> <th>#</th> <th>Images</th> <th>Image description</th> <th>Delete</th> </tr>"; while($row = mysql_fetch_array($display)) { echo "<tr>"; echo "<td>".$row['img_ID']."</td>"; echo "<td><img src='folder/".$row['imaged']."' alt='alt text' width='100' height='100' class='thumb'/> </td>"; echo "<td>".$row['image_description']."</td>"; echo '<td><input type="checkbox" name="delete[]" value="'.$row['img_ID'].'"/></td>'; echo "</tr>"; } echo "</table>"; echo "</form>"; if (isset($_POST['delete'])) { $del = $row['img_ID']; for($i=0;$i<count($_POST["delete"]);$i++) { if($_POST["delete"][$i] != "") { $str = "DELETE FROM photos WHERE img_ID='$del' "; mysql_query($str); echo "Record Deleted."; } } } mysql_close($connect); ?> Here are the problems: 1/ Not working at all, I mean no image is being deleted 2/ At then end, I display a message that the record has been deleted, but if I check multiple checkbox, it keeps writing the message "Records deleted" multiple times My images are stored in a folder while its details in database... Help, thank you I'm working on a chat using basic textarea input, post, but the problem that I'm facing is, if a person doesn't send something, then the output is not updated eg. other messages from other users updating in real time.
How is that achieved when you see new database entries pop up live, milliseconds after they are entered?
Do I set a constant refresh rate of some sort?
How do you update a section of a webpage without "refreshing" the entire page like the POST method?
Hi All,
I want to copy into a table values from another table that partially match a given value, case-insensitively. So far I do as follows but I wonder whether there is a quicker way.
$input_table=array('1'=>'toto','2'=>'tota','3'=>'hello','4'=>'TOTO','5'=>'toto'); $input_table_2 = array_map('strtolower', $input_table); $value_to_look_for='Tot'; $value_to_look_for_2=strtolower($value_to_look_for); $output_table=array(); foreach ($input_table_2 as $k=>$v) { if(false !== strpos($v, $value_to_look_for_2)) { $output_table[]=$input_table[$k]; } }One drawback is that $input_table_2 is 'foreached' whereas there might be no occurrences, which would lead to a loss of time/resources for big arrays. Thanks. Hey all, Im currently working on a site which I save a cookie on users computer for 1 month as well a row in a table with the 1 month expiring date plus cookie id. What I would like to know is if theres a way to make the server check the table every day at say 12pm to see if any corresponding user cookies in each row have expired on that day as to remove them from the table to match the expiring cookie on the users computer? I would like not to have to rely on a user/admin accessing in to make a script run instead have something thats timed to go off automatically instead? Is there anyway of doing this? Thanks! I know this code works
INSERT INTO archive_table SELECT * FROM original_table WHERE id = 1But i want to also add the current date whenever i copy the data into a new table. Thanks in advance I have a survey that uses colors. At the moment someone takes the survey I need to capture the values that are in a table called "tbl_colors" and write them to each survey in "tbl_surveys" as a row. tbl_colors id, hex_color 1 FFF432 2 CC3399 3 DD3399 and so on to the number 12 tbl_survey id, timestamp, name, hex01, hex02, hex03, hex04, etc to hex12 I have written code that "works" but I know it is extremely redundant and overloaded and someone could probably do the same thing in less than 10 lines of code. So, I post it here so I can learn from my mistakes. // Make a MySQL Connection $query = "SELECT * FROM tbl_colors WHERE id = 1"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color1 = $row['hex_color']; $query = "SELECT * FROM tbl_colors WHERE id = 2"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color2 = $row['hex_color']; $query = "SELECT * FROM tbl_colors WHERE id = 3"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color3 = $row['hex_color']; $query = "SELECT * FROM tbl_colors WHERE id = 4"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color4 = $row['hex_color']; $query = "SELECT * FROM tbl_colors WHERE id = 5"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color5 = $row['hex_color']; $query = "SELECT * FROM tbl_colors WHERE id = 6"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color6 = $row['hex_color']; $query = "SELECT * FROM tbl_colors WHERE id = 7"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color7 = $row['hex_color']; $query = "SELECT * FROM tbl_colors WHERE id = 8"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color8 = $row['hex_color']; $query = "SELECT * FROM tbl_colors WHERE id = 9"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color9 = $row['hex_color']; $query = "SELECT * FROM tbl_colors WHERE id = 10"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color10 = $row['hex_color']; $query = "SELECT * FROM tbl_colors WHERE id = 11"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color11 = $row['hex_color']; $query = "SELECT * FROM tbl_colors WHERE id = 12"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color12 = $row['hex_color']; //echo $color1.$color2.$color3.$color4.$color5.$color6.$color7.$color8.$color9.$color10.$color11.$color12; mysql_query("INSERT INTO tbl_surveys (hex01, hex02, hex03, hex04, hex05, hex06, hex07, hex08, hex09, hex10, hex11, hex12) VALUES ('$color1', '$color2', '$color2', '$color3', '$color4', '$color5', '$color6', '$color7', '$color8', '$color9', '$color10', '$color11', '$color12')"); This is my first real jump into PHP, I created a small script a few years ago but have not touched it since (or any other programming for that matter), so I'm not sure how to start this. I need a script that I can run once a day through cron and take the date from one table/filed and insert it into a different table/field, converting the human readable date to a Unix date. Table Name: Ads Field: endtime_value (human readable date) to Table Name: Node Field: auto_expire (Converted to Unix time) Both use a field named "nid" as the key field, so the fields should match each nid field from one table to the next. Following a tutorial I have been able to insert into a field certain data, but I don't know how to do it so the nid's match and how to convert the human readable date to Unix time. Thanks in advance!. hello friends I'm dealing with this problem for two days. I put here the screenshot for easier understanding.Sorry about my bad english. Here is the ss http://i61.tinypic.com/2rz5q55.jpg I don't want to inner join or table join. All image links which same sku should displayed in single row where products.resimler colon I can join the tables but i want to one table.Because i can import single csv file for e-commerce script.How can I use a update query for list multiple images in table products. Edited by nogai, 10 October 2014 - 07:01 AM. |