PHP - Date Field Problem
I have such a little code. If I echo $order_date, I receive normal date in YYYY-MM-DD format. But when I use $order_date in mysql query it is not showing me anything. I do not receive any error or warning also.
Please help me. $query = "SELECT Product,Amount FROM orders WHERE Date='$order_date'"; $result = mysql_query($query) or die(mysql_error()); while($products_list = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $products_list["Product"] . "</td>"; echo "<td>" . $products_list["Amount"] . "</td>"; echo "</tr>"; } Similar TutorialsThis 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 have a date of birth field(dob) in my table, eg 16/05/2011 (dd/mm/yyyy). I need to run a query but it must not include the year, how do I do that? Code: [Select] $sql = "SELECT * FROM detail WHERE dob='$mydate'"; The dob is in the format dd/mm/yyyy, how do I change my query to just use dd/mm? Thank you Hi: I'm going crazy trying to do the following: I'm making a job registration process where the user registers on one php page to the website, must acknowlege and email receipt using an activate php page, then is directed to upload their C.V. (resume) based on the email address they enter in the active page output. I then run an upload page to store the resume in teh MySQL db based on the users email address in the same record. If I isolate the process of the user registering to the db, it works perfectly. If I isolate the file upload process into the db, it works perfect. I simply cannot upload teh file to the existing record based on teh email form field matching the user_email field in the db. With the processes together, teh user is activated, but teh file is not uploaded. Maybe I've simply been at this too long today, but am compeled to get through it by end day. If anyone can help sugest a better way or help me fix this, I will soo greatly appreciate it. My code is as follows for the 2 pages. ---------activate.php------- <?php session_start(); include ('reg_dbc.php'); if (!isset($_GET['usr']) && !isset($_GET['code']) ) { $msg = "ERROR: The code does not match.."; exit(); } $rsCode = mysql_query("SELECT activation_code from subscribers where user_email='$_GET[usr]'") or die(mysql_error()); list($acode) = mysql_fetch_array($rsCode); if ($_GET['code'] == $acode) { mysql_query("update subscribers set user_activated=1 where user_email='$_GET[usr]'") or die(mysql_error()); echo "<h3><center>Thank You! This is step 2 of 3. </h3>Your email is confirmed. Please upload your C.V. now to complete step 3.</center>"; } else { echo "ERROR: Incorrect activation code... not valid"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>Job application activation</title> </head> <body> <center> <br/><br/><br/> <p align="center"> <form name="form1" method="post" action="upload.php" style="padding:5px;"> <p>Re-enter you Email : <input name="email" type="text" id="email"/></p></form> <form enctype="multipart/form-data" action="upload.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="4000000"> Upload your C.V.: <input name="userfile" type="file" id="userfile"> <input name="upload" type="submit" id="upload" value="Upload your C.V."/></form> </p> </center> </body> </html> --------upload.php---------- <?php session_start(); if (!isset($_GET['usr']) && !isset($_GET['code']) ) { $msg = "ERROR: The code does not match.."; exit(); } if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $email = $_POST['email']['user_email']; $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); $content = addslashes($content); fclose($fp); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } include 'reg_dbc.php'; $query = "UPDATE subscribers WHERE $email = user_email (name, size, type, content ) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$content')"; mysql_query($query) or die('Error, query failed'); mysql_close($dbname); } ?> <center> <br/> <br/> <br/> <br/> Thank you for uploading your <?php echo "$fileName"; ?> file, completing your registration, and providing us your C.V. for this position. <br/> <br/> <br/> We will contact you if your canditature qualifies. </center> Ok, i can't understand whats wrong with the DATE field in MySQL and PHP. I have a form in PHP witch has 3 birth day dropdown menus that looks like this (YYYY-MM-DD). An in my database i have a birth_day colum with DATE as type and i've tried to set the default value to "None" and "0000-00-00" but nothing works. Everytime i try to input something (e.g. 1993-16-05) i get this error: Incorrect date value: '05' for column 'birth_day' at row 1 I've tried to set the value for the "Day" dropdown in the PHP form to both 5 and 05 but still nothing, what am i doing wrong? Hi People. I am building a logbook application and have a form field where the user will enter a date. However, I would like to simplify it for the user and give them a button which would add "todays" date into the box for them. Please could someone tell me the code to do so. The date format in my DB is YYYY-MM-DD. The form would also need to take input from the user if they were adding info from a different day instead of today. Thanks in advance. Code: [Select] <input type="text" name="date" id="date" size = "25"/> </label> <input type="submit" name="today" id="today" value="Add Today" /> Okay, I have a field called "created" in my `users` table, and I'd like to be able to view it in-game on an administrator panel. However, it's being captured in a long number format (i.e. 1335076320) which, I believe, has to deal with seconds and such. How can I take that number and convert it to an actual date/time output? Here's how I currently have it coded in my php form: <tr><td width="20%">Registered On:</td><td>{{created}}</td></tr> So, obviously it's not converting it to any format, rather just pulling that 1335076320 number out. Thanks in advance! Hi all,
I have a search page where I'd like members to be able to search for races that they and their friends have entered into a database. When entering the data, users put the race date into the race_date field (Which is a DATETIME field) in the table.
I've set up the search and display pages, so users can search by a number of other criteria (first name, last name, race distance, time, etc), but am having trouble with searching by year. On my search form, is a field called race_year.
So, obviously I need some change in the code below, specifically in relation to the line $where .= " AND race_date='$race_year'"; because I want to extract the year part of the race_date column from the table and see if it matches $race_year .
Any advice would be appreciated.
Cheers,
Dave
$race_year = $_POST['race_year']; if ($race_year != '') { // A year is selected $where .= " AND race_date='$race_year'"; } Here is one part of php code. Here I try to show in last 1 month which dates exactly user made orders. When I run the SQL code in command prompt it works. I think problem is in while loop. Thanks beforhand for contribution. $query = "SELECT Date FROM orders WHERE User='$username' and DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= Date;"; $result = mysql_query($query,$link_id) or die (mysql_error()); echo "<table border='1'> <tr> <td> Last 1 month's orders:</td> </tr>"; while($order_date = mysql_fetch_row($result)) { echo "<tr>"; echo "<td>" . $order_date[0] . "</td>"; echo "</tr>"; } echo "</table> Hi, I need to add a function for a date field on a form being submitted to MySQL DB. Something similar to this for a website field, except it shoudl make sure the format is in 01/05/2010 or 2numbers/2 numbers/4 numbers format... if(!mb_eregi("^[a-zA-Z0-9-#_.+!*'(),/&:;=?@]*$", $website)) $this->setError('website', 'invalid website'); elseif(mb_strlen(trim($website)) > 120) $this->setError('website', 'too long! 120 characters'); thanks in advance for any assistance. hi i have a mysql table with upddate and updtime field as follows: upddate updtime 2011-02-25 11:03:05 2011-01-28 08:01:09 2011-02-20 07:00:08 2011-02-15 06:10:02 2011-02-05 10:21:04 2011-02-09 10:20:25 the data types for upddate is mysql date and for updtime its mysql time In my php page i use Code: [Select] <?php echo $date = date("d M Y",strtotime($row_rs1['upddate'])); ?> to retrieve date and the results displays as 25 Feb 2011. And for time right now im using Code: [Select] <?php echo $row_rs1['updtime']; ?> which displays time as 11:03:05 I want to display time as HH:MM only, how can i do it? I am trying to import into a csv file and filter the results to a particular user and only results based on the time the data was uploaded within one hour. In other words anything not uploaded within the last hour of the start_time will not appear in the csv file. Everything works fine except for the time part. I get no results at all with the 'and unix_timestamp........ For all I know possibly I am way off with my effort. The field name is start_time. Here is code below. Appreciate any help.
<code> header('Content-type: application/csv'); </code> I'm using mcrypt to encrypt a field and decrypt it. That works OK. But when I insert the encrypted field into a mySQL table, select it, decrypt it and try to display it, I get garbage. What am I missing? Thanks for any suggestions. Here's the code: echo "The encrypt and decrypt example...<br/>"; // Designate string to be encrypted $string = "Ed O'Reilly"; // Encryption/decryption key $key = "arG4thaker2"; // Encryption Algorithm $cipher_alg = MCRYPT_RIJNDAEL_128; // Create the initialization vector for added security. $iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher_alg, MCRYPT_MODE_ECB), MCRYPT_RAND); // Output original string print "Original string: $string <p>"; // Encrypt $string $encrypted_string = mcrypt_encrypt($cipher_alg, $key, $string, MCRYPT_MODE_CBC, $iv); // Convert to hexadecimal and output to browser print "The encrypted string: ".bin2hex($encrypted_string)."<p>"; $decrypted_string = mcrypt_decrypt($cipher_alg, $key, $encrypted_string, MCRYPT_MODE_CBC, $iv); print "The decrypted string: ".rtrim($decrypted_string).""; echo "<br/>testing db storing & retrieval for the encryption/decryption...<br/>"; # make connection (Game server connections are variable and are done later when needed) if (!$cxnAdmin = mysqli_connect($hostAdmin, $userAdmin, $passwordAdmin, $dbnameAdmin)) { die("Could not connect to MySQL server Admin (".mysqli_connect_error().")"); } $sql="INSERT INTO testdb.nametable ( name, ) VALUES ( '$encrypted_string', 'test@test.com' ) ; "; $result = mysqli_query($cxnAdmin,$sql); if($result == false) { echo "<h4>Error on nametable Insert: ".mysqli_error($cxnAdmin)."</h4>"; } $sql="SELECT name FROM testdb.nametable WHERE email='test@test.com'"; if (!$result = mysqli_query($cxnAdmin,$sql)) { echo "<h4>Error on nametable Select: ".mysqli_error($cxnAdmin)."</h4>"; } $row = mysqli_fetch_assoc($result); extract($row); // Convert to hexadecimal and output to browser print "The encrypted string from db: ".bin2hex($name)."<p>"; $decrypted_name = mcrypt_decrypt($cipher_alg, $key, $name, MCRYPT_MODE_CBC, $iv); print "The decrypted string from db: ".rtrim($decrypted_name).""; and here's the output: The encrypt and decrypt example... Original string: Ed O'Reilly The encrypted string: 01bc70f5dc5a7ca204cb45bd2eeb0214 The decrypted string:Ed O'Reilly testing db storing & retrieval for the encryption/decryption... The encrypted string from db: 5938f7fc81961d2efc6db64607baf465 The decrypted string from db: <garbage characters I can't display here> Hey, I'm using a script which allows you to click on a calendar to select the date to submit to the database. The date is submitted like this: 2014-02-08 Is there a really simple way to prevent rows showing if the date is in the past? Something like this: if($currentdate < 2014-02-08 || $currentdate == 2014-02-08) { } Thanks very much, Jack Hi Guys...i have this problem... I have this page where user can type in their date of birth...I would like to convert the date of birth input by the user to the DATA format which is defined by phpmyadmin (YYY-MM-DD) so that i can put into the database... My main objective of this is to calculate age... I have this form to allow use to type date of birth: Code: [Select] <label for="dob">D.O.B.: </label> <input type="text" name="dob" id="dob" class="regfields"/> This is to store the input to a variable: Code: [Select] $adddob = $_POST['dob']; and finally this query to insert all the input into the database: Code: [Select] $query = "insert into emp (FNAME, LNAME, CDSID, PAYNO, MAIL , TELNO , DOB , BRANCH , LICNO , CLASS , VFROM , VTO , EID , PASS , PIN) values ('$addfname','$addlname','$addcdsid','$addpayno','$addmail','$addtelno','$adddob','$addbranch','$addlicno','$addclass','$addvfrom','$addvto','$addeid','$addpassword','$addpin')"; Thanks in advance...If this is possible then I will set my dob column to the DATA format... Code: [Select] <?php $dayNames = array("Nedelja", "Ponedeljak", "Utorak", "Srijeda", "Četvrtak", "Petak", "Subota"); $dan = $dayNames[date('N')]; echo $dan.", ".date('d.m.Y.') ; ?> This is my code for showing days in my language, but it works on every day except sunday! Does anybody have any clue? Thanks! Hi, I have the date stored in my datrabase like this: 2010-04-03 I am then outputting the date like this: Sat 13 Nov This is done using this code: list($year,$month,$day) = explode('-',$Coursedate); $time_stamp = mktime(0,0,0,$month,$day); $Coursedate2 = date("D d M",$time_stamp); The problem I have come across is when listing a date for next year. The database has a value of 2011-01-29 which is a Saturday but it is outputting it as a Friday: Fri 29 Jan The 29th of January 2010 is a Friday but 2010 is a Saturday. Any idea what is wrong with the code? hey guys, i have my code set up to run substrings through a db to check for matches...even when there is a match it wont insert correctly Code: [Select] $result = mysql_query("select * from friends where userid=$userid"); while($row = mysql_fetch_assoc($result)) { $first_name = $row['first_name']; $last_name = $row['last_name']; $strpos_1 = strpos($friend_1, ' '); $substr_1 = substr($friend_1, 0, $strpos_1); $substr_2 = substr($friend_1, $strpos_1); if($substr_1 == $first_name && $substr_2 == $last_name) { $sql = "insert into fav_friends values('', '$userid', '$friend_1', '$friend_2', '$friend_3', '$friend_4', '$friend_5', '$friend_6')"; $query = mysql_query($sql); } } and i don't receive any errors, any thoughts?
Hi guys, <form id='contact-form".$KitchConfigID."' name='contact-form".$KitchConfigID."' action='_pages/_kitchenconfig/adm_saveKitchConfig.php?Nav=".$NavHash."&kcid=".$KitchConfigID."' method='POST'> <div class='row'> <div class='col-sm-12'> <div class='md-form mb-0 form-sm'> <input value='".$KitchConfig."' type='text' id='configname".$KitchConfigID."' name='configname".$KitchConfigID ."' class='form-control'> <label for='configname".$KitchConfigID ."' class=''>Config Name:</label> </div> </div> </div> <div class='row'> <div class='col-sm-12'> <div class='md-form mb-0 form-sm'> <select id='designer_".$KitchConfigID."' name='designer_".$KitchConfigID."' class='mdb-select md-form' searchable='Search here..' onchange='changeInput(this.value, ".$SelField.");'>"); $designersql = "SELECT * FROM `tbl_contacts` ORDER BY `FirstName`"; $resultdesigner = $conn->query($designersql); if ($resultdesigner->num_rows > 0) { $resultdesigner->MoveFirst; echo("<option value='designer_".$KitchConfigID."'></option>"); while($rowdesigner = $resultdesigner->fetch_assoc()) { $DesignerName = $rowdesigner["FirstName"]." ".$rowdesigner["LastName"]; $DesignerID = $rowdesigner["ContactID"]; if($rowdesigner["ContactID"]==$rowkitch["Designer"]){ echo("<option value='".$DesignerID."' selected='selected'>".$DesignerName."</option>"); } else { echo("<option value='".$DesignerID."'>".$DesignerName."</option>"); } } } echo("</select> <input type='text' name='".$SelField."' value='' /> <label for='designer_".$KitchConfigID."' class=''>Designer:</label> </div> </div> </div> <div class='md-form mb-0 float-right'> <button type='submit' class='btn btn-outline-danger waves-effect btn-sm float-right'>Save <i class='fas fa-magic ml-1'></i></button> </div>
$upd_KitchConfigID = $_GET["kcid"]; if(isset($_POST["configname$upd_KitchConfigID"])) { $upd_KitchConfig = $_POST["configname$upd_KitchConfigID"]; } else { $upd_KitchConfig = 'NotSet'; $ErrMsg = $ErrMsg . 'No KitchConfig, '; } if(isset($_POST["designer$upd_KitchConfigID"])) { $upd_KitchConfigDesigner = $_POST["designer_$upd_KitchConfigID"]; } else { $upd_KitchConfigDesigner = 1; $ErrMsg = $ErrMsg . 'No Designer, '; } echo("designer_$upd_KitchConfigID: ".$_POST["designer_$upd_KitchConfigID"]."<br><br>");
Hi FYI I'm a n00b in this particular forum & php n00b really but I'm having a problem & cant find a solution anywhere! I need to be able to send an email from a form. Within the form is a dropdown field for different regions. When a region is selected it sets the email address for that region into an input/text field. I need to pickup that value and send the email to that address but not sure how. Have been told to use echo$email & that perhaps my variable is empty but I haven't got a clue where to put it or what that means. Help please?! my code: include ('maketable.php'); include ('mailbot.php'); include ('auditFile.php'); $office = $_REQUEST["office"]; $callername = $_REQUEST["callername"]; $callerphone = $_REQUEST["callerphone"]; $callaction = $_REQUEST["callaction"]; $callerInfo = "Callers Name=".$callername; $commentInfo = "Callers Phone No=".$callerphone; $callDetail = "Action Taken=".$callaction; $title = "DOC Call Results"; $stylesheet = "stylesheet.css"; $logo = "tcclogo.jpg"; $display = makeHeader($title,$stylesheet,$logo); $display .= makeTable("Caller Details",$callerInfo,1); $display .= makeTable("",$commentInfo,1); $display .= makeTable("",$callDetail,1); $display .= '</body></html>'; $info = $callerInfo."; ".$commentInfo."; ".$callDetail; auditFile($title, $info); echo $email; mailbot($title,$display,"email","info@tcc.co.nz","ThankYou.html"); This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=351353.0 |