PHP - Php_sql ; Copy Sql Table Daily
Hi... 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
Similar TutorialsHi 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 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! 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. 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')"); 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 Hi guys, I am wirting a script to upload an image file, but I get the error: copy() [function.copy]: Filename cannot be empty in Obviouly it has something to do with the copy() function - (copy($HTTP_POST_FILES['product_img']['tmp_name'], $path)) I think it is not copying from my temp folder or something. Can anyone help me out? Code is: Code: [Select] //IMAGE FILE $file_name = $_FILES['product_img']['name']; echo '<p>File Name:' . $file_name . '</p>'; //IMAGE UPLOAD // random 4 digit to add to file name $random_digit=rand(0000,9999); //combine random digit to file name to create new file name //use dot (.) to combile these two variables $new_image_name = $random_digit.$file_name; echo $new_image_name; //SET DESINATION FOLDER $path= "uploads/".$new_image_name; echo '<p>Path:' . $path . '</p>'; if($product_img !=none) { if(copy($HTTP_POST_FILES['product_img']['tmp_name'], $path)) { echo "Successful<BR/>"; echo "File Name :".$new_file_name."<BR/>"; echo "File Size :".$HTTP_POST_FILES['product_img']['size']."<BR/>"; echo "File Type :".$HTTP_POST_FILES['product_img']['type']."<BR/>"; } else { echo "Image upload Error<BR/>"; } } Any help would be greatly appreciated! Thanks Ok I am designing a php upload that will take a image file from a form and change the name of the file to the productnumber also recieved from the form. I had it working the otherday now it says Warning: copy() [function.copy]: open_basedir restriction in effect File() is not within the allowed path(s): (/home:/tmp:/usr) addpro.php on line 51. my files are attached.... note that $pnum is the product number gotten from my form and image is the image being uploaded gotten from the form also. The thing is it worked the other day but now it don't is it a change to the server ( I dont run the server) or did I mess up my code since then? I really need a code that will do this two time over once for a small image being put into a folder called small and once for a folder called large both images being uploaded and being changed to $pnum.ext so they will both be displayed when being called out by the product number. but I can work on that after I get this one working. line 51 is $copied = copy($_FILES['image']['tmp_name'], $newname); This was generated through phpFormGenerator, but I'm getting the following warning message when a file is not uploaded. I didn't set it as a required field. "Warning: copy() [function.copy]: Filename cannot be empty ..." If it possible to skip this check since it's not supposed to be required to upload a file? I'm simply trying to make a contact form that emails basic information with the added option of attaching a file/picture. Code: [Select] <?php include("global.inc.php"); $errors=0; $error="The following errors occured while processing your form input.<ul>"; pt_register('POST','FullName'); pt_register('POST','Email'); pt_register('POST','Phone'); pt_register('POST','QuestionsorComments'); $QuestionsorComments=preg_replace("/(\015\012)|(\015)|(\012)/"," <br />", $QuestionsorComments);$AttachPictureforQuote=$HTTP_POST_FILES['AttachPictureforQuote']; pt_register('POST','Howdidyoufindus'); if($FullName=="" || $Email=="" ){ $errors=1; $error.="<li>You did not enter one or more of the required fields. Please go back and try again."; } if($HTTP_POST_FILES['AttachPictureforQuote']['tmp_name']==""){ } else if(!is_uploaded_file($HTTP_POST_FILES['AttachPictureforQuote']['tmp_name'])){ $error.="<li>The file, ".$HTTP_POST_FILES['AttachPictureforQuote']['name'].", was not uploaded!"; $errors=1; } if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$Email)){ $error.="<li>Invalid email address entered"; $errors=1; } if($errors==1) echo $error; else{ $image_part = date("h_i_s")."_".$HTTP_POST_FILES['AttachPictureforQuote']['name']; $image_list[4] = $image_part; copy($HTTP_POST_FILES['AttachPictureforQuote']['tmp_name'], "files/".$image_part); $where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/")); $message="Full Name: ".$FullName." Email: ".$Email." Phone: ".$Phone." Questions or Comments: ".$QuestionsorComments." Attach Picture for Quote: ".$where_form_is."files/".$image_list[4]." How did you find us: ".$Howdidyoufindus." "; $message = stripslashes($message); mail("webmaster@gmail.com","Form Submitted at your website",$message,"From: phpFormGenerator"); ?> <!-- This is the content of the Thank you page, be careful while changing it --> <h2>Thank you!</h2> <table width=50%> <tr><td>Full Name: </td><td> <?php echo $FullName; ?> </td></tr> <tr><td>Email: </td><td> <?php echo $Email; ?> </td></tr> <tr><td>Phone: </td><td> <?php echo $Phone; ?> </td></tr> <tr><td>Questions or Comments: </td><td> <?php echo $QuestionsorComments; ?> </td></tr> <tr><td>Attach Picture for Quote: </td><td> <?php echo $AttachPictureforQuote; ?> </td></tr> <tr><td>How did you find us: </td><td> <?php echo $Howdidyoufindus; ?> </td></tr> </table> <!-- Do not change anything below this line --> <?php } ?> Thanks for your time and any help you can provide! I came across the PHP clone method. Does this clone first level fields and methods or does it also do deep copying e.g. copying references to those fields. For example, a field may be an array. Does it make a copy of the actual array or does it refer to the same array position in memory, so if the original changes, then the copy's changes as well?
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!. Hi, I can't think how to make a counter which goes up during the day, and when a new day starts it gets reset to 0. How can I do this without relying on visitors to the site to run the script? Cheers, Tom. Im looking for some example code for countdowns. I need to be able to count down to the same time each day for example 9PM each day. and be displayed as 5hr 8m 15s. When the timer runs out, then run some code then start again for the next day. what would be the best route to take for this? Thanks in advance I have a weird issue. I'm working on something where people will submit hours for a business. Originally it was free form text, but then I figured it may get messy with people doing M-F 9-5 then Monday through Friday, 9AM to 5PM, Mon-Fri, etc. So I switched to a bunch of inputs. It has each day then a select for from and one for to. Data is passed to the script as a form submission. Vars are named HF# and HT# (hours from, hours to and a 0-6 digit for Mon-Sun). I want to take the input and output a string as such:
Mon-Tue, 8:00 AM to 5:00 PM
Thu-Fri, 8:00 AM to 5:00 PM
Sat, 9:00 AM to 1:00 PM
Sun, 12:00 PM to 3:00 PM
I did this:
$formdata = array(); $formdata["hf0"] = "8:00 AM"; $formdata["ht0"] = "4:30 PM"; $formdata["hf1"] = "8:00 AM"; $formdata["ht1"] = "4:30 PM"; $formdata["hf2"] = ""; $formdata["ht2"] = ""; $formdata["hf3"] = "8:00 AM"; $formdata["ht3"] = "4:30 PM"; $formdata["hf4"] = "8:00 AM"; $formdata["ht4"] = "4:30 PM"; $formdata["hf5"] = "9:00 AM"; $formdata["ht5"] = "1:00 PM"; $formdata["hf6"] = "12:00 PM"; $formdata["ht6"] = "3:00 PM"; $WeekDays = array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"); $hours = ""; $sd = "Mon"; $ld = ""; $fr = $formdata["hf0"]; $to = $formdata["ht0"]; for ($x=0; $x<=6; $x++) { if (empty($sd) && !empty($formdata["hf$x"])) { $sd = $WeekDays[$x]; $fr = $formdata["hf$x"]; $to = $formdata["ht$x"]; } if ($fr != $formdata["hf$x"] || $to != $formdata["ht$x"]) { $hours .= "$sd" . (($sd==$ld)?", ":" - $ld, ") . " $fr to $to<br/>"; if (!empty($formdata["hf$x"])) { $sd = $WeekDays[$x]; $fr = $formdata["hf$x"]; $to = $formdata["ht$x"]; } else { $sd = ""; } } $ld = $WeekDays[$x]; }($formdata was because I was tired of hitting back, changing the data then resubmitting) This kinda works, but it skips Sunday. There has got to be a better way to do this.. any ideas? Hi, This is my first post so dont kill me if i did somthing wrong. Im trying to make a simple php/javascript page that will display the time remaining in each period every day (we have 4 periods per day). I found a nice javascript library from www.hashemian.com and am using the example that he linked to to do multiple countdown timers on one page. The problem i am having is that the only way i can think of to make it so that it counts down to a dynamic date is to specify that date as a variable and then combine it with the string that specifys the rest of the date/time combo for the target date/time. The current live version is at smd75jr.com/test/index2.php The first timer is just a test that im using to make sure i havent completely broken it. THe second timer is the one im trying to troubleshoot, it is currently set for 11:59 PM EST "today". (see code below) Any help would be greatly appreciated!! This is my code: Code: [Select] <html> <head> <title>Multiple Countdown Clocks</title> </head> <body> <div id="clock1">[clock1]</div> <div id="clock2">[clock2]</div> </body> <script language="JavaScript"> StartCountDown("clock1","06/27/2012 9:33 PM -0400") StartCountDown("clock2","periodTest") TodaysDate() //var today = new Date() //var todayMonth = today.getMonth() + 1 //var todayDay = today.getDate() //var todayYear = today.getFullYear() //var todayDate = (todayMonth + "/" + todayDay + "/" + todayYear) var periodTest = (todayDate + " 11:59 PM -0400") var periodA1 = (todayDate + " 8:53 AM -0400") var periodA2 = (todayDate + " 10:26 AM -0400") var periodA31 = (todayDate + " 12:32 PM -0400") var periodLunch1 = (todayDate + " 11:00 AM -0400") var periodLunch2 = (todayDate + " 12:32 PM -0400") var periodA32 = (todayDate + " 11:59 AM -0400") var periodA4 = (todayDate + " 2:05 PM -0400") //function Periods(todayDate, periodA1, periodA2, periodA31, periodA32, periodA4, periodB1, periodB2, periodB31, periodB32, periodB4, periodLunch1, periodLunch2, periodSchoolStart, periodSchoolEnd) // { // var today = new Date() // var todayMonth = today.getMonth() + 1 // var todayDay = today.getDate() // var todayYear = today.getFullYear() // var todayDate = (todayMonth + "/" + todayDay + "/" + todayYear) // // var periodA1 = (todayDate + " 21:25 PM -0400") // } function TodaysDate(todayDate) { var today = new Date() var todayMonth = today.getMonth() + 1 var todayDay = today.getDate() var todayYear = today.getFullYear() var todayDate = (todayMonth + "/" + todayDay + "/" + todayYear) } /* Author: Robert Hashemian (http://www.hashemian.com/) Modified by: Munsifali Rashid (http://www.munit.co.uk/) Modified by: Tilesh Khatri */ function StartCountDown(myDiv,myTargetDate) { var dthen = new Date(myTargetDate); var dnow = new Date(); ddiff = new Date(dthen-dnow); gsecs = Math.floor(ddiff.valueOf()/1000); CountBack(myDiv,gsecs); } function Calcage(secs, num1, num2) { s = ((Math.floor(secs/num1))%num2).toString(); if (s.length < 2) { s = "0" + s; } return (s); } function CountBack(myDiv, secs) { var DisplayStr; var DisplayFormat = "%%D%% Days %%H%%:%%M%%:%%S%%"; DisplayStr = DisplayFormat.replace(/%%D%%/g, Calcage(secs,86400,100000)); DisplayStr = DisplayStr.replace(/%%H%%/g, Calcage(secs,3600,24)); DisplayStr = DisplayStr.replace(/%%M%%/g, Calcage(secs,60,60)); DisplayStr = DisplayStr.replace(/%%S%%/g, Calcage(secs,1,60)); if(secs > 0) { document.getElementById(myDiv).innerHTML = DisplayStr; setTimeout("CountBack('" + myDiv + "'," + (secs-1) + ");", 990); } else { document.getElementById(myDiv).innerHTML = "Period Over"; } } </script> </html> hi i have daily data table it's contain ID, Date, and Rain i need to make a new table but tendays period ,,, any clues ,,, will be very greatfull thanks a lot ,,, Hey everyone. Currently I have a site set up where I manually edit the txt file and the site pulls it from the text file and displays via php. I wanted to automate it by creating one file which contains the sunset times for the whole year, and have php determine todays date and then display the corresponding sunset time. Can someone please point me in the right direction? maybe it can be set up in a way where each line in the txt file represents the day of the year. ex: Jan 1 would be line 0, Feb 1's sunset time would be on line 31 etc. Thanks Hello everyone, so I made this script that creates directories via "a hack around" cPanel, on my own server, in order to create directories via my own software, but I also need to copy files from one directory into that newly created directory... Therein lies the problem... I created a script a few years ago that worked, but for the life of me I can't remember how I enabled myself to be able to use the copy function of php... Anybody know? Hello freaks, I am currently creating a member system that will place a default handle image into a newly registered members file. I have used the mkdir function create the directory successfully based on the members ID, but I can't get the copy function to work. Code: Code: [Select] mkdir("memberFiles/$memberID", 0755); $old = 'images/defaultlogo.jpg'; $new = 'memberFiles/$memberID/logo.jpg'; copy($old, $new); Error Message: Warning: copy(memberFiles/$memberID/logo.jpg) [function.copy]: failed to open stream: No such file or directory Lastly, this folder is created to store members files. hey people i cant get copy() to work. im working on an online server and trying to copy a file into directories i just created. i read about fopen() having to be enabled if both source and destination files are urls, and fopen is enabled and both files are urls (and on the same server). the directories get created but the file doesnt get copied. the directories have permission 777. could it be that when i call the copy function the directories aren't yet available on the server? i am copying the file in the same code block as 'create folders', right after. any pointers? Hello, im new to php and I would appreciate help with this one.... Error code is Warning: copy() expects parameter 1 to be string, array given in /path/to/file/http.class.php on line 143 Error block Code: [Select] if (count($_FILES) > 0) { foreach ($_FILES as $name => $file) { if ($file['tmp_name']) { $newfile=dirname(__FILE__).'/../cache/'.$file['name']; $newfiles[]=$newfile; copy ($file['tmp_name'],$newfile); if ($file['tmp_name']) $this->post[$name]='@'.$newfile; } } } Line 143 Code: [Select] copy ($file['tmp_name'],$newfile); |