PHP - Help In Mysql Fuction Date_add()
if($_POST['Submit']=="Check"){ /*$title=mysql_real_escape_string($_POST['title']); $subject=mysql_real_escape_string($_POST['subject']); $author=mysql_real_escape_string($_POST['author']);*/ $bookid=(int)$_POST['bookid']; $account=(int)$_POST['account']; $issuedate=mysql_real_escape_string($_POST['issuedate']); //Sduedate=$issuedate+15; $duedate=DATE_ADD('$issuedate'+interval 15 DAY) print $duedate; print $issuedate; $insert_query="insert into issue values($account,$bookid,'$issuedate','$duedate')"; $result=mysql_query($insert_query,$linkID1); if($result){ print "<html><body background=\"header.jpg\"> <p>book successfully added</p></body></html>"; } else{ print "<html><body background=\"header.jpg\"> <p>$insert_query</p>"; print "<p>there was a problem in adding</p></body></html>"; } } Quote i want $duedate should be 15 days from the issuedate Similar TutorialsHello everyone
Hoping someone could lend me a hand. I have a form that takes some end-user's details and adds the date and time into a MySQL table of when the form was submitted. I wish to display that date/time + 4 days ahead using PHP.
I believe the MySLQ DATE_ADD should do the trick quite nicely. In fact plumbing the following statement into phpMyAdmin gives me exactly the results I requi
SELECT DATE_ADD(`datetime`,INTERVAL 4 DAY) FROM `faults` WHERE fault_id = '51';However, just having a pig of a time getting this displayed using PHP. I'm sure this is elementary so forgive me. Here's what I had in mind but is no working. Can someone please point me in the right direction: <?php $date_query = mysqli_query($con, "SELECT DATE_ADD(`datetime`,INTERVAL 4 DAY) FROM `faults` WHERE fault_id = '51'"); while($row = mysqli_fetch_assoc($date_query)){ echo $row ['datetime']; } ?>Many thanks for your help and advice. $string = House Full 2010 Hindi Movie Watch Online : Dailymotions Video Link : Alternative Link : ; i want to take out ":" from the string.. can anyone tell me wat function should i use to get this following result House Full 2010 Hindi Movie Watch Online Dailymotions Video Link Alternative Link help please.. Is there any function in php lib that does the following $a = 1238; $n = 48; // 1*2*3*8 or I will have to create one for my script? (I want to do it for both client and server sides based on request sent by user. I actually want it in php that is why i asked it here, but if the solution (as function) is available in javascript (not jQuery) please share or guide me.) Edited January 5 by 684425create table mimi (mimiId int(11) not null, mimiBody varchar(255) ); <?php //connecting to database include_once ('conn.php'); $sql ="SELECT mimiId, mimiBody FROM mimi"; $result = mysqli_query($conn, $sql ); $mimi = mysqli_fetch_assoc($result); $mimiId ='<span>No: '.$mimi['mimiId'].'</span>'; $mimiBody ='<p class="leading text-justify">'.$mimi['mimiBody'].'</p>'; ?> //what is next? i want to download pdf or text document after clicking button or link how to do that Hello everyone, Sorry if this has been answered but if it has I can't find it anywhere. So, from the begining then. Lets say I had a member table and in it I wanted to store what their top 3 interests are. Their$ row has all the usual things to identify them userID and password etc.. and I had a further 3 columns which were labled top3_1 top3_2 & top3_3 to put each of their interests in from a post form. If instead I wanted to store this data as a PHP Array instead (using 1 column instead of 3) is there a way to store it as readable data when you open the PHPmyadmin? At the moment all it says is array and when I call it back to the browser (say on a page where they could review and update their interests) it displays 'a' as top3_01 'r' as top3_02 and 'r' as top3_03 (in each putting what would be 'array' as it appears in the table if there were 5 results. Does anyone know what I mean? For example - If we had a form which collected the top 3 interests to put in a table called users, Code: [Select] <form action="back_to_same_page_for_processing.php" method="post" enctype="multipart/form-data"> <input name="top3_01" type="text" value="enter interest number 1 here" /> <input name="top3_02" type="text" value="enter interest number 2 here" /> <input name="top3_03" type="text" value="enter interest number 3 here" /> <input type="submit" name="update_button" value=" Save and Update! " /> </form> // If my quick code example for this form is not correct dont worry its not the point im getting at :) And they put 'bowling' in top3_01, 'running' in top3_02 and 'diving' in top3_03 and we catch that on the same page with some PHP at the top --> Code: [Select] if (isset($_POST)['update_button']) { $top3_01 = $_POST['top3_01']; // i.e, 'bowling' changing POST vars to local vars $top3_02 = $_POST['top3_02']; // i.e, 'running' $top3_03 = $_POST['top3_03']; // i.e, 'diving' With me so far? If I had a table which had 3 columns (1 for each interest) I could put something like - Code: [Select] include('connect_msql.php'); mysql_query("Select * FROM users WHERE id='$id' AND blah blah blah"); mysql_query("UPDATE users SET top3_01='$top3_01', top3_02='$top3_02', top3_03='$top3_03' WHERE id='$id'"); And hopefully if ive got it right, it will put them each in their own little column. Easy enough huh? But heres the thing, I want to put all these into an array to be stored in the 1 column (say called 'top3') and whats more have them clearly readable in PHPmyadmin and editable from there yet still be able to be called back an rendered on page when requested. Continuing the example then, assuming ive changed the table for the 'top3' column instead of individual colums, I could put something like this - Code: [Select] if (isset($_POST)['update_button']) { $top3_01 = $_POST['top3_01']; // i.e, 'bowling' changing POST vars to local vars $top3_02 = $_POST['top3_02']; // i.e, 'running' $top3_03 = $_POST['top3_03']; // i.e, 'diving' $top3_array = array($top3_01,$top3_02,$top3_03); include('connect_msql.php'); mysql_query("UPDATE members SET top3='$top3_array' WHERE id='$id' AND blah blah blah"); But it will appear in the column as 'Array' and when its called for using a query it will render the literal string. a r r in each field instead. Now I know you can use the 'serialize()' & 'unserialize()' funtcions but it makes the entry in the database practically unreadable. Is there a way to make it readable and editable without having to create a content management system? If so please let me know and I'll be your friend forever, lol, ok maybe not but I'd really appreciate the help anyways. The other thing is, If you can do this or something like it, how am I to add entries to that array to go back into the data base? I hope ive explained myself enough here, but if not say so and I'll have another go. Thanks very much people, L-PLate (P.s if I sort this out on my own ill post it all here) I have following piece of code below, and I would like to be able to express it pure SQL, something that could go into a .sql file :
$request_string='SELECT topic_forum_id FROM topic_table WHERE topic_id= 2014'; $query=database->prepare($request_string); $query->execute(); $data=$query->fetch(); $query->closeCursor(); $forum=$data['topic_forum_id']; $request_string='INSERT INTO post_table (post_topic,post_forum) VALUES (2014,:forum)'; $query=database->prepare($request_string); $query->bindValue(':forum',$forum,PDO::PARAM_INT); $query->execute(); $data=$query->fetch(); $query->closeCursor();Is it possible ? So i have this php as shown below. It should make a list of comments with comment replies below their comment respectively. The problem is that it only goes through and shows 1 comment and all the comment replies for that one comment. It should be showing all comments i have in the db for that article. If i remove the second while then it shows all the comments correctly but no comment replies then... How do i get this script to loop through the db for every comment but also loop through every comment reply for that $row[id]? If anyone has a better / more efficient way of what I am trying to do, please explain or show example (i am open to anything)... Code: [Select] // what article are we showing? $article_to_show_id = $_GET['article_id']; $active_is_set_text = "1"; // Active Column text that makes it okay to show // Finding the article $search_for_article = mysql_query("SELECT * FROM articles WHERE id = '$article_to_show_id' AND active = '$active_is_set_text'"); while($row = mysql_fetch_array($search_for_article)) { // format the last updated date right $update_date_edit = $row[update_date]; $update_date_edit = date('F j, Y \a\t h:ia', $update_date_edit); $row[update_date] = $update_date_edit; // format the submit updat date right $submit_date_edit = $row[submit_date]; $submit_date_edit = date('F j, Y \a\t h:ia', $submit_date_edit); $row[submit_date] = $submit_date_edit; echo ' <div> ', $row[title] ,' </div> <div> by: ', $row[author] ,' on ', $row[submit_date] ,' </div> <div> ', $row[content] ,' </div> <div> Last Updated: ', $row[update_date] ,' </div> <form action="article_reply.php" method="post"> <input type="hidden" name="article_id" value="', $row[id] ,'" /> <button name="article_reply" type="submit" value="submit">Reply</button> </form> '; } $comment_count = 0; $comment_reply_count = 0; // Finding all of the comments $search_for_article = mysql_query("SELECT * FROM article_comments WHERE article_id = '$article_to_show_id' AND reply_id = '0'"); while($row_comment = mysql_fetch_array($search_for_article)) { // format the submit updat date right $comment_date_edit = $row_comment[comment_date]; $comment_date_edit = date('F j, Y \a\t h:ia', $comment_date_edit); $row_comment[comment_date] = $comment_date_edit; echo ' <br> <br> COMMENT:<br> <div> By: ', $row_comment[username] ,' on ', $row_comment[comment_date] ,' </div> <div> ', $row_comment[comment] ,' </div> '; $comment_count++; // Finding all of the comment replies if any $search_for_article = mysql_query("SELECT * FROM article_comments WHERE article_id = '$article_to_show_id' AND reply_id = '$row_comment[id]'"); while($row_two = mysql_fetch_array($search_for_article)) { // format the submit updat date right $comment_date_edit = $row_two[comment_date]; $comment_date_edit = date('F j, Y \a\t h:ia', $comment_date_edit); $row_two[comment_date] = $comment_date_edit; echo ' <br> <br> COMMENT REPLY:<br> <div> By: ', $row_two[username] ,' on ', $row_two[comment_date] ,' </div> <div> ', $row_two[comment] ,' </div> '; $comment_reply_count++; } } Need some help I have 2 tables in a database and I need to search the first table and use the results from that search, to search another table, can this be done? and if it can how would you recommend that I go about it? Thanks For Your Help Guys! Evening everybody! What I am trying to do is display infomation from a database, each item has a catid and a subid. I can display the correct information when I am looking at a particular subid by using: $catid = $_GET['catid']; if(isset($_GET['subid'])){ $subid = $_GET['subid']; } else $subid = '';?> //other code $query = mysql_query("SELECT * FROM merchants WHERE catid= '$catid' AND subid= '$subid'"); But I cant figure a way to change this so if the AND is not met it will still display the info based on $catid? Basically I want to display all the records with a particular catid, regardles of subid, but only if subid does not exits?! Does this make sense? Basically I think I am after and AND/OR I hope you can see what I am on about! Cheers I have a table that has a field called rating which can be from 0-100. I want to create a mysql query that will count the number of ratings between 0-20 then 21-40 then 41-60 etc. However I'm not really sure how to do this so any help would be great. Hi All, I inherited some code as part of a bought website, I am trying to convert it to make it better and add functionality... however I am having a hard time trying to figure out what is going on in one particular section of code. In short there is basically a block of PHP which is producing a SQL statement, but the SQL always returns 0 results. I can't figure out why this is because I can't figure out what the PHP is producing. Would someone with my knowledge than me be kind enough to take a look and advise me where possible? This is the part doing the generating: Code: [Select] // IF THE CATEGORY FIELD IS NOT EMPTY if (!empty($row['category'])) { // EXPLODE THE ARRAY ON , $strArr = explode(",",$row['category']); // FOR EACH ONE for($i=0; $i<sizeof($strArr); $i++) { $str = trim($strArr[$i]); $strs .= "'".trim($strArr[$i])."',"; $sch[] = "category LIKE '%$str%'"; } echo "Categories in the array a ". $strs; echo "<br /><br />"; $strs = substr($strs,0,-1); $sch[] = "category in ($strs)"; } // IF THE SUBCOUNTY FIELD IS NOT EMPTY if(!empty($row['subcounty'])) { // EXPLODE THE ARRAY ON , $strArr = explode(",",$row['subcounty']); // FOR EACH ONE for($i=0; $i<sizeof($strArr); $i++) { $str = trim($strArr[$i]); $strs2 .= "'".trim($strArr[$i])."',"; $sch[] = "subcounty LIKE '%$str%'"; } echo "SubCounties in the array a ". $strs2; echo "<br /><br />"; $strs2 = substr($strs2,0,-1); $sch[] = "subcounty in ($strs2)"; } // IF THE TITLE FIELD IS NOT EMPTY if(!empty($row['title'])) { // JOIN SEARCH TERM TO THE ARRAY $sch[] = "(position LIKE '%$row[title]%' || description LIKE '%$row[title]%')"; echo "The title is: ".$row['title']; echo "<br /><br />"; } And this is the SQL part that always returns blank: Code: [Select] // COUNT THE AMOUNT OF RESULTS THEN SELECT THE JOBS FROM THE DATABASE $result = mysql_query("SELECT count(*) FROM jobs ". (($sch)?"WHERE ".join(" AND ", $sch):"").""); $total = mysql_result($result, 0); $r9 = mysql_query("SELECT * FROM jobs ".(($sch)?"WHERE ".join(" and ", $sch):"")." ORDER BY jobid DESC"); echo "The count is: " . $total; echo "<br /><br />"; Any help would be appreciated, Many thanks, Greens85 hey Guys I have a table in a db that stores attack details for my game below Code: [Select] id attacker win defender time deleted 1 17 1 84 1288576720 0 2 22 1 84 1288576989 0 i want to give a stat like, total attacks made : 20 (times there id is attacker) percent successful = 20% (if win =1 its a win =0 its a loss) and the same with times attacked. I was thinking along the lines of getting the info using Code: [Select] $stat = mysql_fetch_array(mysql_query("select * from attacklog where attacker='$userid' AND win='1'")); would i just do that for every option in the database? I have been putting together a small project with an MySQL db and php. I am having trouble passing a date variable from a text input into a sql statement within php. I think I am going about this in the right way but I am confused as to what I need to do to finish off the code and make it work. $data = $_POST['datepicker']; //this line gets the string from the form text input box and assigns to var $data $time = strtotime($data); //this line converts the string $data to time (strtotime) and = $time unix time stamp $mydate = date('Y m d',$time); //this line formats date into Y m d from the time stamp $time and = $mydate echo $mydate; //print to screen as test function to view and the following sql called from php $result = mysql_query( //collects that data from the table "SELECT Room.roomName, booking.* FROM Room, booking WHERE (bookingDate = . "$mydate" .) AND booking.roomID = Room.roomID ORDER BY roomName, startTime" ); Thanks in advance for any guidance Hey guys I need some help for making some things work. This is my index.php and as you can see I have a table of my sql table and a drop list. Now when I press Add to chart on the table on my website, it goes to the cart. But when I select a item from the drop list and click on Add to chart, there only happens an increment of the quantity but the item does not go to the cart. http://fhcs.be/cart-demo2/index.php this is my website where you can check the problem out. Thanks Guys!!!! Code: [Select] <?php // Include MySQL class require_once('inc/mysql.class.php'); // Include database connection require_once('inc/global.inc.php'); // Include functions require_once('inc/functions.inc.php'); // Start the session session_start(); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>PHP Shopping Cart Demo · Bookshop</title> <link rel="stylesheet" href="css/styles.css" /> </head> <body> <div id="shoppingcart"> <h1>Your Shopping Cart</h1> <?php echo writeShoppingCart(); ?> </div> <div id="booklist"> <h1>Books In Our Store</h1> <?php $sql = 'SELECT * FROM products ORDER BY id'; $result = $db->query($sql); $output[] = '<ul>'; while ($row = $result->fetch()) { $output[] = '<li>"'.$row['name'].': €'.$row['price'].'<br /><a href="cart.php?action=add&id='.$row['id'].'">Add to cart</a></li>'; } $output[] = '</ul>'; echo join('',$output); ?> <? $Link = mysql_connect("fhcs.be.mysql","fhcs_be","xxxx"); $Query = "SELECT * FROM products"; $DBName = "fhcs_be"; $results = mysql_db_query($DBName, $Query, $Link); ?> Select a name <select name = "drop1" size="1"> <Option Value=" ">Select One:</option> <? //Begins PHP for($u=0;$u<mysql_num_rows($results); $u++) { $ID=mysql_result($results,$u,'name'); ?> <option value="<? echo($ID); ?>"><? echo($ID); ?></option><? //Begins PHP //Begins PHP } ?> </select> <? //Begins PHP if (mysql_db_query ($DBName, $Query, $Link)) { } else { print ("FAILURE<BR>\n"); } mysql_close ($Link); ?> </div> </body> </html> Just want to ask how to create a login system using these wml and php? i have a background on connecting html php and the database.. but in these wml i am confused.. can someone help me? What i'ved got here is Wap Proof for wap emulator to test my codes.. You can download it here http://www.wap-proof.com/ i have tried this code but i gets me to error.. // login.php <?php # Header Info header('Content-Type: text/vnd.wap.wml', true); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); # Version Type print "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"; # Import config file include "/home/jamieb/private/conf.php"; # Connect to database mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbname); ?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"> <wml> <!-- THIS IS THE LOGIN CARD --> <card id="login" title="Login"> <p> <do type="accept" label="Login"> <go href="process.php" method="post"> <postfield name="userName" value="$userName" /> <postfield name="password" value="$password" /> </go> </do> </p> <p> User Name: <input title="userName" name="userName" /> <br /> Password : <input title="password" name="password" type="password" /> <br /> </p> </card> </wml> // process.php <?php # Header Info header('Content-Type: text/vnd.wap.wml', true); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); # Version Type print "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"; # Import config file include "/home/jamieb/private/conf.php"; # Connect to database mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbname); # Verify the user $sql = mysql_query("SELECT userName,nickName FROM table WHERE userName = '".strtolower($_POST['userName'])."' AND password = '".md5($_POST['password'])."'"); $row = mysql_num_rows($sql); $login = mysql_fetch_array($sql); $user = md5($login['userName']); $nick = $login['nickName']; if ($row == 0): ?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"> <wml> <card id="failed" title="Login Failed"> <p> Sorry, username or password incorrect! </p> <p> <anchor>Home <go href="index.php#menu" /> </anchor> <do type="prev" label="Back"><prev/></do></p> </card> </wml> <?php exit; else: ?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"> <wml> <card id="success" title="Login Success"> <p> <do type="accept" label="Admin"> <go href="admin.php" method="post"> <postfield name="session" value="<?php echo "$user"; ?>" /> </go> </do> </p> <p>Welcome <?php echo "$nick"; ?>, please enter the admin area.</p> </card> </wml> <?php endif; ?> My problem here is it doesn't open anything on the wap proof.. or if i ever open it i can't see the submit button.. can someone give some login scripts using php wml? thanks I am having a problem with my PHP/MySQL coding and I can not figure out what I am doing wrong. I have two tables in a database. One called EmployeeInfo and another called Absence. In the Employee Info table, I have two employees, Derek and Adrian. In the Absence table, I have two records, One for Derek and Adrian. Goal: Using PHP/MySQL, I want to call upon an employee using a form and display that person's absence. The form pulls up correctly. If I do NOT put a WHERE clause into my SQL statement, it pulls up all the absences perfectly fine. Once I put in the WHERE = EmployeeInfo.Name = 'NameSelect' then it fails every time. Here is my SQL Coding: $result = mysql_query("SELECT * FROM Absence LEFT JOIN EmployeeInfo ON(Absence.Account = EmployeeInfo.Account) WHERE EmployeeInfo.Name='NameSelect'"); Any help is greatly appreciated. Hello, I am new to this site and hope I am posting this in the right section...
The thing is.....
I would like some help with php and mysql..
What I want to create is a page where users can create an account by entering their name, email and password, and if the username is taken they will have to try again otherwise their details will be registered to the mysql table and have an account to login.
Also I would like a redirect so if the user is a standard user it goes to say “home”, but if the user is an admin it will go to another page ie “home2”, and how would I create the admin in the same table on mysql or seperate?
Right the last thing is once the user can register and login, so can the admin, for instance if there are 10 users, when logged in I want each of those users to see different information can this be done and how could I do this ? I thought maybe have the table and the id would be from 1-10 so if user is 1 being dan show his column, and if user logged 2 being steve show column id 2.
Can somebody help me implement this please ?
I am currently learning php and mysql, im in university I managed to learn how to create the table, connect login, search, add to the database when logged in and edit etc.. but for what I want to achieve now I cannot find any tutorials or help, could somebody please help me with the coding for this and what pages are what and how to create the table in mysql being either 1 table for both user and admin, or 2 tables for separate users and admin.
Thanks for your help in advance guys
hello every one
I have some queries in mysql command..
I have a table schema like this
id | name | url | img1 | img2 | img3 | img4|
I want to randomly rotate the image by specific id....
suppose the select the id = 1, then the four images will be rotated randomly for with the tha id (i.e id = 1)
Any help wil greatly appreciated
Thank u.....
Hey guys, I've heard about MySQL being replaced with PDO some time in the future, but as a simple question, I'm coding a personal website for my use only, would I still be able to use MySQL rather than changing it to PDO and learning that?
Its not going to be anything big or nothing just to keep me active in my spare time.
Thanks for you help.
|