PHP - Selecting All Data Of A Specific Date From Mysql Datetime
SELECT * FROM `booking_tbl` WHERE booking_status = 'Check In' AND departure_date_time = NOW()"I use the datetime datatype for the departure_date_time so i can get data from that data because it checking the date and time but i want it to check on the date from the datetime datatype So how can i get the data only with that date without the time in the mysql datetime datatype Similar TutorialsI'm having trouble inserting a formatted PHP DateTime into a MySQL table. I'm getting: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ',2012-01-31)' at line 4 I get the error when I try to insert the date as a string from a DateTime object via: $insertDate = $date->format('Y-m-d'); As well as when I try to recast it as a date object: $insertDate = date("Y-m-d",strtotime($date->format('Y-m-d'))); I've also tried putting the date in ' ' 's and escaped " " 's. My insert query is: $insert = "INSERT INTO pendingordersdetails (PartNumber,Oqty,Pqty,Aqty,PartStatus, PartPrice,idOrderNo,PrtTariffCode,PrtLocation,LineNum,PKqty,SPqty,AllocationDate) VALUES ('$partNum',$oQty,0,$aQty,'Excess',$price,$orderNum,'$tariffCode', '$location',$lineNum,$PKqty,$SPqty,'$allocDate');"; and the echoed output is: INSERT INTO pendingordersdetails (PartNumber,Oqty,Pqty,Aqty,PartStatus, PartPrice,idOrderNo,PrtTariffCode,PrtLocation,LineNum,PKqty,SPqty,AllocationDate) VALUES ('0446535240 ',3,0,1,'Excess',163.89,66,' ', 'A0406E01',2,,,'2012-01-31'); Anyone have any ideas? Hi there,
I'm a bit of a newbie and I have done a search online, but i'm still confused.
I need to search my MYSQL database in a filed named date_mod I need to search for todays date only $date=gmdate("Y-m-d");
But however the field is a datetime option so how can I search only todays date and not both date and time.
Thank you for reading.
Hi I am trying to select and order data/numbers from a colum in a mysql data base however i run the code and it returns no value just a blank page no errors or any thing so i think the code is working right but then it returns no result? Please help thanks Here is the code: <?php $host= "XXXXXX"; $mysql_user = "XXXXXX"; $mysql_password = "XXXXXX"; $mysql_database = "XXXXXXX"; $connection = mysql_connect("$host","$mysql_user","$mysql_password") or die ("Unable to connect to MySQL server."); mysql_select_db($mysql_database) or die ("Unable to select requested database."); $row = mysql_fetch_assoc( mysql_query( "SELECT XP FROM Game ORDER BY number DESC LIMIT 1" ) ); $number = mysql_result(mysql_query("SELECT XP FROM Game ORDER BY number DESC LIMIT 1"), 0); echo "The the highest XP is $number"; ?> I have the following code, and really can't see what is wrong with it. Any help would be great. <?php if (!mysql_connect('127.0.0.1', 'root', '')) { echo 'Could not connect to mysql'; exit; } $dbname = 'Requests'; $result = mysql_list_tables($dbname); if (!$result) { echo "DB Error, could not list tables\n"; echo 'MySQL Error: ' . mysql_error(); exit; } while($row2 = mysql_fetch_row($result)) { foreach ($row2[0] as $table_id) { $query = "SELECT * FROM $table_id"; $dbresult = mysql_query($query); // added code to use the tablename and select all records from that table // create a new XML document $doc = new DomDocument('1.0'); // create root node $root = $doc->createElement('mixes'); $root = $doc->appendChild($root); // process one row at a time while($row = mysql_fetch_assoc($dbresult)) { // add node for each row $occ = $doc->createElement($table_id); $occ = $root->appendChild($occ); // add a child node for each field foreach ($row as $fieldname => $fieldvalue) { $child = $doc->createElement($fieldname); $child = $occ->appendChild($child); $value = $doc->createTextNode($fieldvalue); $value = $child->appendChild($value); } // foreach } // while } } echo 'Wrote: ' . $doc->save("s.xml") . ' bytes'; // Wrote: 72 bytes ?> Hi all, I am trying to get data from MySQL to display in a html table in TCPDF but it is only displaying the ID. $accom = '<h3>Accommodation:</h3> <table cellpadding="1" cellspacing="1" border="1" style="text-align:center;"> <tr> <th><strong>Organisation</strong></th> <th><strong>Contact</strong></th> <th><strong>Phone</strong></th> </tr> <tbody> <tr>'. $id = $_GET['id']; $location = $row['location']; $sql = "SELECT * FROM tours WHERE id = $id"; $result = $con->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { '<td>'.$location.'</td> <td>David</td> <td>0412345678</td> </tbody>'; } } '</tr> </table>'; Anyone got any ideas? Alright, I have a Datetime field in my database which I'm trying to store information in. Here is my code to get my Datetime, however it's returning to me the wrong date. It's returning: 1969-12-31 19:00:00 $mysqldate = date( 'Y-m-d H:i:s', $phpdate ); $phpdate = strtotime( $mysqldate ); echo $mysqldate; Is there something wrong with it? I am trying to get specific data from a MySQL table but cannot seem to find a proper command. Code: [Select] $link = mysqli_connect('#####', '########', '########'); $user = $_SESSION['username']; $email = mysqli_query($link,"select email from members where username='$user'"); echo $email; Specifically, I am trying to get the email address stored for the user specified by the session, and display that address. However, I do not get any output with the current code, and am not sure what to try next. I have tried mysqli_fetch_row() but it only returns an error. Hi guys ..
please help me .. I don't know how to do this and I tried but there were no satisfied results..
I want to retrieve a Title (ing_title) from a database called k_db2 , in a table called content_langs
depending on its ID , which called ing_contID
example: if ing_contID=1 , then show the ing_title with this id ing_contID
the above code should be in a php file ..
then I want to include this php file inside the header of my website..
by importing the ing_contID from the database and depending on it the title should be shown..
I really tried but I couldn't find any solution ..
if you could help me in the first part of this problem I'll be glad ..
Hello,
First of all I'd like to say thank you for all the great information on the forums, I've been reading a lot on here lately.
I've started to make a website where users can log in and submit items to a database, which is then displayed on another page.
If Tom and Bill both post 10 items, all 20 items will be displayed on the "listings" page, however on the main log in screen Tom will only see his own 10 items and Bill will see his own 10 items.
This is all working perfectly, however, I now need to add a delete button so that they can delete specific items.
I have loosely followed this tutorial here to get the table to display as I want it (amongst a few other things, such as the user logins) http://www.wickham43...mphptomysql.php
I've added the delete button in the PHP loop for each row, I just can't figure out how to delete the specific row when clicked.
Any help would be really appreciated
Edited by eklem, 22 October 2014 - 08:10 AM. Hello. I'm a newbie so sorry if this isn't the best forum to post my problem.
I am using a MySQL and PHP to create a web app. I have authentication, and I can register users. I also have a form that users provide information and it is successfully inserting data into a table in my database.
I will use fictional fields for my database table called meal_info:
username
dateStartedDiet
numberMealsPerDay
costPerMeal
Problem: Select user-specific data from the MySQL database, using Session username to select only the current user's data, then display it and do some calculations.
Here is thecode at the top, and I am fairly sure it's working:
session_start(); //execute commone code
require("common.php"); //includes code to connect to database, etc.
if(empty($_SESSION['user'])) I am not sure if the title is correct; I tried my best.
I'm a PHP/MySQL beginner and I really need some help.
I have a small script that I am using for sending SMS. I recently added a phonebook. The problem with the phonebook right now is that it's available to all users, i.e. they can all update and delete all rows. What I would like to do is make it so that each user can update and delete only their own contacts.
I have a table call contacts. Inside that table there is first name, last name, company and phonenumber.
How can I accomplish this with PHP & MySQL?
CREATE TABLE IF NOT EXISTS `contacts` ( `contact_id` int(10) NOT NULL AUTO_INCREMENT, `firstname` varchar(255) NOT NULL, `lastname` varchar(255) NOT NULL, `company` varchar(255) NOT NULL, `cell_no` text NOT NULL, PRIMARY KEY (`contact_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ; CREATE TABLE IF NOT EXISTS `users` ( `user_id` int(11) NOT NULL AUTO_INCREMENT, `users_name` varchar(30) NOT NULL, `uname` varchar(30) NOT NULL, `u_pass` varchar(60) NOT NULL, `utype` varchar(30) NOT NULL, `timezone` varchar(30) NOT NULL, `uapi_user` varchar(30) NOT NULL, `uapi_pass` varchar(60) NOT NULL, PRIMARY KEY (`user_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=20 ; <?php if (isset($_POST['submit'])){ //form has been submitted1 $firstname = trim($_POST['firstname']); $lastname = trim($_POST['lastname']); $company = trim($_POST['company']); $cellno = trim($_POST['cell_no']); if($firstname == ''){ echo '<div class="alert alert-danger">First Name is not Valid!</div>'; exit; }elseif($lastname == ''){ echo '<div class="alert alert-danger">Last Name is not Valid!</div>'; exit; }elseif($company == ''){ echo '<div class="alert alert-danger">Company is not Valid!</div>'; exit; }elseif($cellno == ''){ echo '<div class="alert alert-danger">Cellphone Number is not Valid!</div>'; exit; }else{ $query = "Select cell_no from contacts where cell_no = '".$cellno."' "; $result = mysql_query($query); if (!mysql_num_rows($result)) { $sql = "INSERT INTO contacts(firstname, lastname, company, cell_no) values('{$firstname}','{$lastname}', '{$company}', '{$cellno}')"; $result = mysql_query($sql); confirm_query($result); //echo '<div class="alert alert-success">Successfully added.</div>'; //exit; ?> <script type="text/javascript"> window.location = "contact_list.php"; </script> <?php } else{ echo '<div class="alert alert-danger">Username. already exist!.</div>'; echo '<p><a href="new_contact.php" class="btn btn-success"> Back </a></p>'; exit; }} }else{ $firstname = ""; $lastname = ""; $company = ""; $cellno = ""; } ?> Hi PHPFreaks.com I wrote in here a while ago about updating table rows by selecting rows which end dates is greater than the current day, much like a experation dates with blog posts in a CMS. I was told to make sure my datatype for the end dates in the database was the datetime format is YYYY-MM-DD HH:mm:SS now I have now changed that, but I am still have trouble creating a query that does exactly what I mentioned. mysql_query("UPDATE ". $db_prefix ."events WHERE end_time >= TIMESTAMP: Auto NOW() SET cat = 1" ); Now what I am trying to is that if the current time is greater than the end date I need the "cat" row changed to 1 So thanks in advance if you can help me guys this is my query Code: [Select] SELECT SUM(no_Yards) AS 'yards', AVG(no_yards) AS 'avg', MAX(no_Yards) AS 'max', MIN(no_Yards) AS 'min' FROM swimming WHERE Season = '$ws' and when i display the data i want to display the date that the max and the min happened (from the database in the column Day_Swam) something like this Code: [Select] <?php echo "<tr>"; echo "<td style='background-color:#F90'>Max Length:</td>"; echo "<td>" . number_format($wsi_row['max']) . "</td>"; echo "<td>" . DATE WOULD GO HERE . "</td>"; echo "</tr>"; echo "</tr><tr>"; echo "<td style='background-color:#F90'>Min Length:</td>"; echo "<td style='background-color:#FF9'>" . number_format($wsi_row['min']) . "</td>"; echo "<td>" . DATE WOULD GO HERE . "</td>"; echo "</tr>"; ?> Hi this is what I have set up - SQL tables - Members - memberid - primary key Username Password Orders - Orderid - primary key memberid - foreign key orderno In my sql table there are two members and two orders. 1 order is assigned to 1 member and the other order to the other member. After each member logs in I need to 'echo' that order on the page. I've not been able to write any succesful php code that 'gets' the specific order that is related to the member that has signed in. I would appreciate help on this! Thanks What I'm basically trying to accomplish is, that the datetime of the user posted information is registered with the Now() function in the query, BUT that the user entered information gets echo'd out with the Date showing ONLY. What I have is this: -Just as an example- INSERT INTO db (date_created) VALUES (now()) while ($row = mysqli_fetch_array($data)) { echo '<tr><td>' . $row['date_created'] . '</td></tr>'; } mysqli_close($dbc); With this way of course I get Date and Time showcased just like it's inserted into the DB. What would be a legit way of showcasing just date. Thanks for help. EDIT: or is there a better way than using now() to showcase the date when the user entered information was posted? hi there..im new to php mysql and im having trouble inserting a string data to mysql from a php date() function. here's my code: Code: [Select] $year = date('Y'); echo $year; $insertSQL = sprintf("INSERT INTO tbl_elections (election_id=$year)"); mysql_select_db($database_organizazone_db, $organizazone_db); $Result1 = mysql_query($insertSQL, $organizazone_db) or die(mysql_error()); when i try to output the $year variable on a webpage, it returns "2012" but when i try to insert this data into my database table, it returns an error like this: check the manual that corresponds to your MySQL server version for the right syntax to use near '=2012)' is there a way to convert "2012" into a normal string data type? I have a field called date_time in the database which is of type datetime. I have a form which on submit needs to enter the current date and time in the date_time field. I know I can get the current time using time() $time=time(); Can do I do some kind of manipulation using strtotime() and store in the database in datetime format? I am using the following code to get the third sunday of every month for +6 Months from todays date. I have put together the following code which works perfectly when the date is echoed however when it comes to inserting those dates into mysql db it throws a unable to convert to string error. Im new to this and my head is in a spin as to why those dates can't be inserted if they can echoed ok. I have spent 2 days at it now and searched many forum however they seem to get side tracked from my issue (or do they)??????? I figure I can't go mixing DateTime and date() the way I have? Please help??? Code: [Select] [php] $month=date('F'); $now=date('Y-m-d'); $year=date('Y'); $num='3'; //example only this will be a $_POST value 0-3 $day='Sunday'; //example only this will be a $_POST value Monday-Sunday $start= date('Y-m-d', strtotime('+'.$num.' week '.$day.' '.$month.' '.$year.'')); if($start>$now) { $begin=strtotime('+'.$num.' week '.$day.' '.$month.' '.$year.''); } else { $d = new DateTime( $start ); $d->modify( 'first day of next month' ); $nextmonth = $d->format( 'F' ); $year = $d->format( 'Y' ); $begin=strtotime('+'.$num.' week '.$day.' '.$nextmonth.' '.$year.''); } $date=date('Y-m-d', $begin); # insert into db first occurance //mysql_select_db($database); //$query_rsFirst = "INSERT INTO event_date VALUES (NULL, '$event', '$d', '$date', '$date')"; //$rsFirst = mysql_query($query_rsFirst) or die(mysql_error()); echo $date.'<br/>'; for($i = 0; $i <= 4; $i++) { $d = new DateTime( $date ); $d->modify( 'first day of next month' ); $nextmonth = $d->format( 'F' ); $date=date('Y-m-d', strtotime('+'.$num.' week '.$day.' '.$nextmonth.' '.$year.'')); # insert into db //mysql_select_db($database); //$query_rsDate = "INSERT INTO event_date VALUES (NULL, '$event', '$d', '$date', '$date')"; //$rsDate = mysql_query($query_rsDate) or die(mysql_error()); echo $date.'<br/>'; if($nextmonth=="December") { $d = new DateTime( $date ); $d->modify( 'first day of next year' ); $year = $d->format( 'Y' ); } } [/php] Hello I am getting an error in my php code. I think the error is in the first line of code but I am not 100% for sure. The error states... Notice: Undefined index: paid_date ... Can you tell me if I am going down the correct route to select the max date in a column? Code: [Select] [b]$query = "Select MAX(paid_date) as paidDate from players INNER JOIN players_paid ON players.player_number=players_paid.player_number"; $query = mysql_query($query) or die(mysql_error());[/b] /*SELECT column_name(s) FROM table_name1 INNER JOIN table_name2 ON table_name1.column_name=table_name2.column_name*/ //echo "SELECT 1 FROM players_paid WHERE (((players_paid.player_number)="+str_replace("'","''",$rsNewPlayer__ssPlayerNumber)+") AND ((players_paid.paid_type)=1))"; ?> <html> <body> <?PHP echo $user; ?> <br> <?php echo $password; ?> <br> <?PHP while($rows=mysql_fetch_assoc($query)) { ?> <table width="100%" border="1"> <tr> <th scope="col"><?PHP echo $rows['paid_date'] ?></th> </tr> </table> <?PHP } ?> </body> </html> |