PHP - Query "where String Is Blank And Date Is At Least 6 Months Ago.
I'm getting this error "Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/westiehi/public_html/groupBOS.php on line 36"
for this code: Code: [Select] $query_rs_specialty = "SELECT * FROM specialty WHERE Group_Place <> '' and Date>= DATE_SUB(CURDATE(), INTERVAL 6 MONTH) ORDER BY Date DESC"; I've tried everything to get this to take records where the one field is blank and the date is greater than a date 6 months ago but nothing seems to work. Help would sure be appreciated!! Similar TutorialsI am working on a report generation. Here I need to count the number of months involved in the selected date range. I need to apply the monthly charges accordingly. Example: If the user selects 25-08-2011 to 03-10-2011, it should return 3 as the number of months. Yes, the number of days are less than 60 but still the date range is spread across 3 months. Any solution.. Please. Girish So this is a simple code that finds out the difference between two dates and displays it in number of days. $date1=date_create("2013-03-15"); $date2=date_create("2013-12-12"); $diff=date_diff($date1,$date2); echo $diff->format("%R%a days"); // RESULT +272 days
My first question. Is it possible to remove the + sign in the result above? Second question. Is it possible to show "months" if it's greater than 30 days? And years if the days are greater than 365? How would I do this? 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] ...added to an error log? Currently, my coding is as follows: Form to gather data: Code: [Select] <html><head><title>Car Accident Report Form</title></head> <form action="errorlog.php" method="post"> First Name: <br><input type="text" name="name"><br> Surname:<br> <input type="text" name="surname"><br> Age: <br><input type="text" name="age"><br> Weeks Since Accident: <br><input type="text" name="weeks"><br> <input type="submit" value="Submit"> </form> Coding for error log: Code: [Select] <html><head><title>Validating Car Accident Report Form Details</title></head> <?php $name=$_POST["name"]; $surname=$_POST["surname"]; $age=$_POST["age"]; $weeks=$_POST["weeks"]; $subtime = strftime('%c'); $pass = "The details uploaded are fine<br><br>"; if ((((trim($name)="" && trim($surname)="" && trim($age)="" && trim($weeks)="")))) { echo "It seems that you have not entered a value for the Name, Surname, Age or Weeks fields. This has been added to the error log.<br><br>"; error_log("<b><u>Error</b></u><br>The user has not entered any values", 3, "C:/xampp/htdocs/errorlog.txt"); } if (($age<18)&& ($weeks<=1)) { echo "It seems that you have entered an invalid age and number of weeks since the accident. This has been added to the error log.<br><br>"; error_log("<b><u>Error</b></u><br>The user has entered an age that is below 18 and the number of weeks since the accident is equal to or under 1 week!<br>Age entered:" . $age . "<br>Number Of Weeks Since Accident entered:" . $weeks . "<br>Time that form was submitted:" . $subtime . "<br><br>", 3, "C:/xampp/htdocs/errorlog.txt"); } else if ($age<18) { echo "It seems that you have entered an invalid age. This has been added to the error log.<br><br>"; error_log("<b><u>Age Error</b></u><br>The user has entered an age that is below 18!<br>Age entered:" . $age . "<br>Time that form was submitted:" . $subtime . "<br><br>", 3, "C:/xampp/htdocs/errorlog.txt"); } else if ($weeks<=1) { echo "It seems that you have entered an invalid age number of weeks since the accident. This has been added to the error log.<br><br>"; error_log("<b><u>Week Error</b></u><br>The user has entered a number of weeks since the accident that is equal to or under 1 week!<br>Number Of Weeks Since Accident entered:" . $weeks . "<br> Time that form was submitted:" . $subtime . "<br><br>", 3, "C:/xampp/htdocs/errorlog.txt"); } else { echo $pass; } echo "Car Accident Report Form details have been sent<br>"; echo "<a href='readlog.php'>Read Error Log</a>" ?> </html> How can I get it so that if a user presses the space bar in a field, then the trim function sees that there's no white space and then this gets added to the error log? Any help is appreciated! I'm confused... how do you say check if the field in MYSQL is blank? it's not getting what I'm attempting to get. Please help. I want to do actionA... if either of these 3 conditions are true tf1=="RED" tf1=="" tf2=="" AND tf=="apple" if(tf1=="RED" or tf1=="" or tf2=="" AND tf=="apple") { do actionA... } Hi, I am trying to convert a String date into numeric date using PHP function's, but haven't found such function. Had a look at date(), strtotime(), getdate(); e.g. Apr 1 2011 -> 04-01-2011 Could someone please shed some light on this? Regards, Abhishek friends whenever i include this coding to my page, everything goes blank. how could i fix this? Code: [Select] $time_count = 7*24*60*60; // count the 7 days Ads will be deleted $match_time = time()-$time_count; $query = "SELECT id FROM classifieds WHERE time<'".$match_time."' ORDER BY RAND() LIMIT 1"; $result = mysql_query($query); while($ad_id = mysql_fetch_array($result)) $delete =$ad_id[0]; mysql_query("DELETE FROM classifieds WHERE id='$delete'"); I have a form that allows my client to update some products. Now the products are simple just basic info and 1 picture. I have set this up so they can edit the products and change the information, having done this many times in the past, but now hit a puzzling block that I am baffled. The client when editing is presented with the form with the information pulled from the database and the form fields loaded with that data ready to edit. The image can either be left alone or they can choose to upload a new image. They are shown the image they currently have stored in the database. The problem I have is EVEN if they decide not to upload an image and change other information, when the submit the form it must be sending a blank value for the image somewhere as it is updating the database and removing the image reference as if it has been removed. I have an if/else statement based on the form to perform 2 different queries for the update in mysql. Here is the code for the form update, as you can see the image should not update?? Please help?? if ($_SERVER['REQUEST_METHOD'] =='POST') { //This stops SQL Injection in POST vars foreach ($_POST as $key => $value) { $_POST[$key] = mysql_real_escape_string($value); } // **************************** THIS IS FOR NO NEW IMAGE ******************************** if ($_SERVER['REQUEST_METHOD'] =='POST' && empty($_FILES['product_image']['name'])) { # setup SQL statement for no new image $SQL = " UPDATE products SET product_title = '{$_POST['product_title']}', product_description = '{$_POST['product_description']}', standard_price = '{$_POST['standard_price']}', deluxe_price = '{$_POST['deluxe_price']}' WHERE product_id = '{$_REQUEST['product_id']}' "; } // **************************** THIS IS FOR A NEW IMAGE ******************************** else { // Check the image type is a jpeg or gif for the image. if (($_FILES['product_image']['type'] != "image/gif") && ($_FILES['product_image']['type'] != "image/jpeg") && ($_FILES['product_image']['type'] != "image/pjpeg")) { echo "<FONT FACE=\"Verdana\"><SPAN CLASS=\"content\">You have chosen not to upload a <b>Product Image</b>.<BR></SPAN>" ; } elseif ($_FILES['product_image']['size'] > 100000) { echo "<FONT FACE=\"Verdana\"><SPAN CLASS=\"content\">The file size is bigger than 300kb.<BR></SPAN>" ; } else { move_uploaded_file($_FILES['product_image']['tmp_name'], "/httpdocs/product_images/".$_FILES['product_image']['name']) ; echo "<FONT FACE=\"Verdana\"><SPAN CLASS=\"content\"><B>Your front image has successfully uploaded.</B><BR></SPAN>" ; } } # setup SQL statement for update $SQL = " UPDATE products SET product_title = '{$_POST['product_title']}', product_description = '{$_POST['product_description']}', standard_price = '{$_POST['standard_price']}', deluxe_price = '{$_POST['deluxe_price']}', product_image = '{$_FILES['product_image']['name']}' WHERE product_id = '{$_REQUEST['product_id']}' "; } #execute SQL statement $result = mysql_db_query( *****,"$SQL",$connection ); # check for error if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); } Hello. My query results are only pulling partial values for table entries with a space (Example: AJ Smith only returns AJ and not the full name ). I am sure this is an easy fix and I am just missing something. Thank you. $params = array(); $sqlFilters = ""; if(isset($filtertown)) { $sqlFilters .= " AND town =:town"; $params["town"] = $filtertown; } if(isset($filterinstagram) && !empty($filterinstagram)) { $sqlFilters .= " AND instagram >=:instagram"; $params["instagram"] = $filterinstagram; } if(isset($filtertwitter) && !empty($filtertwitter)) { $sqlFilters .= " AND twitter >=:twitter"; $params["twitter"] = $filtertwitter; } if(isset($filterfacebook) && !empty($filterfacebook)) { $sqlFilters .= " AND facebook >=:facebook"; $params["facebook"] = $filterfacebook; } if(isset($filterpinterest) && !empty($filterpinterest)) { $sqlFilters .= " AND pinterest >=:pinterest"; $params["pinterest"] = $filterpinterest; } if(isset($filteryoutube) && !empty($filteryoutube)) { $sqlFilters .= " AND youtube >=:youtube"; $params["youtube"] = $filteryoutube; } if (isset($userstatus)) { if ($userstatus == "active") { $sqlFilters .=" AND profilecomplete = 'yes'";} if ($userstatus == "incomplete") { $sqlFilters .=" AND profilecomplete IS NULL";} if ($userstatus == "block") { $sqlFilters .=" AND status = 'block'";} if ($userstatus == "cancel") { $sqlFilters .=" AND status = 'cancel'";} if ($userstatus == "showall") { $sqlFilters .=" AND status IS NULL";} } if (isset($search)) { if (isset($searchfirstname)) { $sqlFilters .= " AND firstname LIKE :searchfirstname"; $params["searchfirstname"] = $searchfirstname; } if (isset($searchsurname)) { $sqlFilters .= " AND surname LIKE :searchsurname"; $params["searchsurname"] = $searchsurname; } } if (isset($sort)) { $sqlStart = "SELECT * FROM users WHERE usertype = 'influencer'"; $sqlEnd = " ORDER BY `$col` $order LIMIT $offset, $rowsPerPage;"; $sql = $sqlStart.$sqlFilters.$sqlEnd; $sqlfiltercount = $sqlStart.$sqlFilters; $result = $pdo->prepare($sql); $result->execute($params); $resultfiltercount = $pdo->prepare($sqlfiltercount); $resultfiltercount->execute($params); $num_users = $result->rowCount(); $num_usersfiltered = $resultfiltercount->rowCount(); } else { $sqlStart = "SELECT * FROM users WHERE usertype = 'influencer'"; $sqlEnd = " LIMIT $offset, $rowsPerPage;"; $sql = $sqlStart.$sqlFilters.$sqlEnd; // sqlfiltercount removes the LIMIT to show ALL users on this userstatus filter $sqlfiltercount = $sqlStart.$sqlFilters; $result = $pdo->prepare($sql); $result->execute($params); $num_users = $result->rowCount(); echo "$sqlfiltercount"; $resultfiltercount = $pdo->query($sqlfiltercount); $num_usersfiltered = $resultfiltercount->rowCount(); } Hi there. I am writing a tool that displays a list of users. The page has pagination, set at 99 per page. This script combines the various filters added by the administrator, but if they select Active, Blocked or a few others, it bypasses that and runs the bottom {} brackets of query. You have the $num_users which is the total on screen at the time, plus the secondary count of TOTAL users in the system. This count is then show by 'users' on the page.
This runs fine on my local machine running php7.2, but on the live 7.2 server, it's showing nothing. No errors. If I comment out the $resultfiltercount lines, the page loads, but of course no count. Why might it be getting upset at that, and why would it not throw errors on screen at me? Code: [Select] The form below is meant to retrieve the named attribute of a form input called "limitedtextfield" , along side the current date and store those values in a database. The form contains some javascript which can be disregarded for this particular problem. [code] <form name="mymind" style= "position:relative;left:40px;" action="insert_status.php" method="post"> <input name="limitedtextfield" type="text" onKeyDown="limitText(this.form.limitedtextfield,this.form.countdown,55);" onKeyUp="limitText(this.form.limitedtextfield,this.form.countdown,55);" maxlength="55"><br> <font size="1">(Maximum characters: 55)<br> You have <input readonly type="text" name="countdown" size="3" value="55"> characters left.</font> <input type="hidden" name="submitted" value="TRUE"/> <input style="position:relative;left:0px;bottom:0px;" type="submit" name="submit" value="Submit!" /> </form> Here is the php script that processes the form. What it is meant to do is search the database and if no record is found for the authenticated member, input the relevant values into the database. If a record is found, it should update the record. Well every time I hit the submit button, all I get is a blank page. Any clue as to what is going wrong? PS: I checked the database and no values got inserted. Code: [Select] <?php //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); //authenticate user require('auth.php'); //Connect to database require ('config.php'); if (isset($_POST['submitted'])) { $query = "SELECT* FROM publications WHERE member_id ='".$_SESSION['id']."' AND cartegory='status'"; $result = @mysql_query($query); $num = @mysql_num_rows($result); if ($num> 0) { $update = mysql_query("UPDATE publications SET publication = '{$_POST['limitedtextfield']}' WHERE member_id = '".$_SESSION['id']."' AND cartegory = 'status'"); header("Location: member.php"); } else { $query = "INSERT INTO publications ( member_id, publication, cartegory, pub_date) VALUES ( '{$_SESSION['id']}','{$_POST['limitedtextfield']}', 'status', NOW() )"; header("Location: member.php"); } } ?> I've been struggling with being able to send an e-mail via the php mail() function when the body of the e-mail includes a "unique" URL. The string that will not work is: "https://p11.secure.hostingprod.com/@www.domain.com/dir/directory/file.ext" The point within the string that breaks the capability, is the "/" after www.domain.com. I have tried escaping it like so: "https://p11.secure.hostingprod.com/@www.domain.com\/dir/directory/file.ext" This allows the e-mail to successfully send, however the body of the e-mail contains the backslash as well as the frontslash. Any ideas? Hi, I am new to the forums. I am having an issue with a snippet of code that generates random strings. I have already searched the forums, but the fix that I found is already in my code. I am still receiving the error though and was wondering if there was something else going on that I didn't see. Here is my code: Code: [Select] $Data = 'Ahmet'.md5(mt_rand(0, 123456789)); $length = 30; $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; $string = ''; $string2 = ''; for ($a = 0; $a < $length; $a++) { $pos = mt_rand(0, strlen($chars)-1); $string .= $chars{$pos}; $pos2 = mt_rand(0, (strlen($Data))-1); $string2 .= $chars{$pos2}; } I appreciate any help on this, as it is cluttering my system log table. Thanks. Hi. I have just one question (I have searched for an answer for this but have not been able to locate one): How do you go about changing the text on a "Submit Query" button to display simply "Submit"? Below is the current code for the page that displays said button. Thank-you in advance for any help or direction. <?php include 'connection.php'; $query = "SELECT * FROM people"; $result = mysql_query($query) or die(mysql_error()); while ($person = mysql_fetch_array($result)){ echo $person ['name']; echo $person ['descrip']; } ?> <H1>Add Your Review:</H1> <form action="create.php" method="post"> Subject <input type="text" name="inputName" value=""/> </br > Review <textarea cols="50" rows="4" name="inputDesc" value=""/></textarea> </br > <input type= "submit" name= "submit"/> </form> <html> <head></head> <body> <p>The current second is <span style='font-size:16px;font-weight:bold;color:red;position:absolute;right:25px;'><?php echo time(); ?></span> on this computer.</p> </body> </html> An insert function is not inserting. I keep getting "Could not store data, please try again." After some probing, it seems that "$result = $conn->query($user_degree_insert_query); " is where the problem is. Variables before it seem to pass testing. I can't figure out why this line is messing thins up though. Any idea? Thank you in advance for your help! The "//$degree_id = mysql_fetch_array($degree_id_query, MYSQL_BOTH) ;" is commented out because it was giving me trouble, i replaced it with the line above that $conn = db_connect(); $arraycount = count($degree_Array); //loop through the categories chosen and add them each into member-category for($i =0; $i < $arraycount; $i++){ $degree_id_query = "SELECT degree_id FROM degree WHERE degree_type ='".$degree_Array[$i]."'"; $result = $conn->query($degree_id_query); //place the id found into the array, which automatically cancatonates it. $degree_id = $result->fetch_array(); //$degree_id = mysql_fetch_array($degree_id_query, MYSQL_BOTH) ; $user_degree_insert_query = "INSERT INTO user-degree ( `user_id` , `degree_id` ) VALUES ( '".$user_id."', '".$degree_id[0]."' )"; $result = $conn->query($user_degree_insert_query); if($result) { header("Location: survey2.php"); }else { echo "<p>Could not store data, please try again.</p>"; exit; Hi there - can anyone lend me a little advise as to what I'm doing wrong here. I have this line: $query=mysql_query("SELECT * FROM gallery a JOIN gallery_image b ON a.id = b.gallery_id where gallery_id=$gallery_id"); I am trying to add an order by statement: order by gallery_image.priority So I created: $query=mysql_query("SELECT * FROM gallery a JOIN gallery_image b ON a.id = b.gallery_id where gallery_id=$gallery_id order by gallery_image.priority"); But, I receive the error (even though there is table called "Gallery Image" and a column called "Priority": Code: [Select] Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/***/public_html/***/gallery.php on line 5 select: Unknown column 'gallery_image.priority' in 'order clause' In a function of a php script there is the following code line: function convert_mails($source_path, $mail_file = '') { global $output_path; print "sp=$source_path"; // -- parameters must have a trailing backslash -- if ($source_path[strlen($source_path)] != '\\') $source_path .= '\\'; ... When running it yields the following error: sp=D:\storage\AABB.ACT\Archi0.FLD; Notice: Uninitialized string offset: 35 in D:\WAMP\www\test.php on line 67 where line 67 is the line with the "if" statement. So why and where is there an uninitialized string offset? How can I repair the code? Peter Hello Everyone, I am having issues where people are submitting null characters on my website (I.e. %00). Currently, I check if their is a value by using the empty function, and I also am checking if the value after running the trim command is =="". How can I check for these special characters to make sure that whatever they are submitting actually contains some sort of legitimate value? Thanks!
Question:
Background:
Example: The Pacific ("Los Angeles") time right now is 7:58pm, but my code says it's 6:58pm. So now I have to go in and correct the "PT8H" portion. I'm wondering if there is some code I can use whereby I can simply "set it and forget it." Thank you! Edited May 2, 2020 by StevenOliverI'm setting a date using: $day = date("d")+1; However when I echo this result I get a single character rather than two i.e '7' and not '07', anyone know what could be up with this? I'm sure it's something to do with the '+1' because i create the current date with this code and returns with the format I want. Thanks! |