PHP - If The Day Is A Friday 13th, Then Display Text?
Hi there, I am trying to write a simple piece of code that will display a little text phrase on every Friday 13th in any year. How would I best go about doing this? Thank you. Similar TutorialsIm using the script to let users login in to our site from 9.00 am to 6.00 pm from Monday To friday, timing is working fine but the day part don't, any ideas why, here is the top of the script is on the login.php page Code: [Select] <? $hour = date('H');//hour 1-24 $dayofweek = date('N');//numeric day of week 1=mon, 7=sun if($hour < 6 || $hour > 15 || $dayofweek > 5) { header( "Location:Messages.php?msg=12" ); }else { //login code session_start(); if(isset($_GET['reg'])){ $reg=$_GET['reg']; }else{ $reg=""; } if($reg==1){ $msg1="<font color=\"#FF6600\">Your details have been added, please login</font>"; }elseif($reg==2){ $msg1="<font color=\"#FF6600\">You have been successfully logged out.</font>"; } if(isset($_POST['submit'])){ if( empty($_POST['uname']) && (empty($_POST['upass']))){ header( "Location:Messages.php?msg=1" ); exit(); } //transfer to shorter var $n=$_POST['uname']; $p=$_POST['upass']; //connect to db include('config.php'); $query="SELECT * FROM user WHERE uname = '".$_POST['uname']."' AND pw = PASSWORD('".$_POST[upass]."')"; $result=mysql_query($query); $num=mysql_num_rows($result); if($num>0 ){ //put in session vars $mytime=time(); $mytime=date("H:i:s A",$mytime); $_SESSION['time'] = $mytime; $_SESSION['status'] = 'logged'; $_SESSION['username'] = $n; //goto next page header("location:Welcome.php"); exit; }else{ $_SESSION['status'] = 'not logged'; header( "Location:Messages.php?msg=2" ); exit(); } } } ?> Sorry if this is too obvious or hard to understand. I'm echoing a database value onto a webpage, the value in question is a large paragraph of text. I need it to only display the first 40 characters or so of that text, then trail off with a "..." So the users will be able to click a 'More Info' button which will take them to a page containing the full paragraph of text. I'm just not sure how to cut off the text after 40 characters. Any help HUGELY appreciated I have a field in my database called description. How can I echo out only 500 out of the 2000 max characters? Like for example: Code: [Select] $query = mysql_query("SELECT description FROM `servers` ORDER BY votes DESC LIMIT 5"); If I were to echo out the value of description for the database, how can I only echo out the first 500 characters? Hello, I have started a DB for simple web based inventory system, I have only dabbled in PHP before 6 weeks ago, within the last 6 weeks with some help and going through countless tutorials and asking questions when I need. At this time setup an insert, delete and update function for this db and are working perfectly, now what I need to know is there a way to display something like 'in stock' and 'out of stock' using php, based on the value of the quantity in my db next to the item in a table?
Example : when the table is generated it will display:
| Part number | Description | Stock | (normally Stock would show the quantity of each part, I just wish to
|10-1111 | Some info | In Stock | display In or out os stock)
|10-1112 | Some Info | Out of Stock |
I the only code I have is the tables and just not sure what to do next to get the results I have described above. So I will include the table code I have and see where we can go from there. Or if you have some webs site that I can read through that will be great as well as long as it can give me basic instruction on how to do this.
Reminder, I am self taught and still learning.
<?php $con = mysqli_connect("localhost","user","pass","part_inventory"); // Check connection if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } else { $result = mysqli_query($con, "SELECT * FROM amp20"); echo "<table border='1'> <tr> <th>ID</th> <th>Part number</th> <th>description</th> <th>location</th> <th>Quantity</th> </tr>"; while ($row = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['amp20ptid'] . "</td>"; echo "<td>" . $row['partnum'] . "</td>"; echo "<td>" . $row['description'] . "</td>"; echo "<td>" . $row['location'] . "</td>"; echo "<td>" . $row['quantity'] . "</td>"; echo "</tr>"; } echo "</table>"; mysqli_close($con); } ?> Edited by Thunder_Wolf, 22 October 2014 - 11:16 AM. Hi, Wonder if someone could help with the problem below. Got a main page that includes a header, footer and a link to a database. I can get the two Includes to work but can't seem to display the database fields in the body of the page. What has me baffled is that it appears to be connecting to the database, (Opening the connection to the database server The connection worked. The link is: Resource id #3) but no text (see below for database text) is appearing on the screen. Yet I'm not getting a "page_not_found" message. I can go to the database in MYSQL console and query it successfully. Read and (hopefully) applied the section Debugging: A Beginner's Guide, but still can't see the problem. Any help greatly appreciated. Bren --------------------CODE FOR MAIN PAGE START------------------- <?php $page_name = $_REQUEST['name']; /*http://localhost/exemples/page.php?name=about_us*/ // Get the body of the page mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); $sql = "SELECT * from pages WHERE name='$page_name'"; print "Opening the connection to the database server<br>"; $link = mysql_connect("localhost","root", ""); print "The connection worked. The link is: $link <br>"; /* --------------What is being selected from the database-------------- +----------+------------------------------------------------------------------------+ | name | body | +----------+------------------------------------------------------------------------+ | about_us | <h1>About Us</h1> ACME Toys has been established in 1850 to provide toys | to children all over the world +----------+------------------------------------------------------------------------+ 1 row in set (0.00 sec) ---------------------------------------------------------------------- */ $result = mysql_query($sql) or die(mysql_error() ); // If the page is not found, redirect to a static page if(mysql_num_rows($result) == 0 ) { header("Location: page_not_found.html"); } $row = mysql_fetch_assoc( $result ); $body = stripslashes( $row["body"] ); // Include the header include("c:/wamp/www/exemples/header.php"); // Print the body of the page echo $body; // Include the footer include("c:/wamp/www/exemples/footer.php"); ?> --------------------CODE FOR MAIN PAGE END------------------- Hi all I have a MySQL data base that is saving information from a form. One the form a user can add a business name which is text and a logo if they have one. Now on my web page I want to beabe to display the picture if present if not I would like it to display the business name. How do I do this please. I know how to conect to DB etc just having problems getting my head around this problem. Hi, I have the following code in a WordPress theme which displays a companies website, Twitter and Facebook links. What I am trying to do is display the text "Useful Links:" if one of the links exists, and hide the text if all are not present. <p>Useful Links:</p> <?php if ( $website = get_the_company_website() ) : ?> <a class="company-website" href="<?php echo esc_url( $website ); ?>" itemprop="url" target="_blank" rel="nofollow"><?php _e('Website', 'jobseek'); ?></a> <?php endif; ?> <?php if ( get_the_company_twitter() ) : ?> <a class="company-twitter" href="http://twitter.com/<?php echo get_the_company_twitter(); ?>" target="_blank"><?php _e('Twitter', 'jobseek'); ?></a> <?php endif; ?> <?php $facebook_link = get_post_meta( get_the_ID(), '_facebook_link', true ); if ( ! empty($facebook_link) ) : ?> <a class="company-facebook" href="<?php echo $facebook_link; ?>" target="_blank">Facebook</a> <?php endif; ?> What would be the best way to show/hide the text depending on if the items are present or not? Thanks I wonder if someone can advise me on how to best tackle this issue. At the moment I am displaying a gallery of images pulled from the database. These are displayed as a thumbnail across my page, currently 4 in each row (then a new row is started dispalying the next 4 thumbnails). This works fine and does exactly what it should do. Now however I would like to display the username of who uploaded the image underneath each thumbnail. So it would go something like this: Display first 4 thumbnails pulled from database - breakline - Display username under each thumbnail - repeat for remainder of images, e.g: image image image image user user user user image image image image user user user user How would I go about this so it doesn't just display all the images in one vertical column, e.g: Image User Image User Image User I hope this makes sense. Any help would be greatly appreciated. hey guys so im trying to display data into text boxes that are fetched from database according to checkbox with value id. processing is located before <!DOCTYPE html>: if(isset($_POST['edit_event']) && isset($_POST['check'])) { require "connection.php"; foreach ($_POST['check'] as $edit_id) { $edit_id = intval($GET['event_id']); //i tried (int)$edit_id; $sqls = "SELECT event_name,start_date,start_time,end_date,end_time,event_venue FROM event WHERE event_id IN $edit_id "; $sqlsr = mysqli_query($con, $sqls); $z = mysqli_fetch_array($sqlsr); { }button and form opens: <form method="post" action="event.php"> <input type="submit" name="edit_event" value="Edit Event">this is the html where the data will be echoed: <div id="doverlay" class="doverlay"></div> <div id="ddialog" class="ddialog"> <table class="cevent"> <thead><tr><th>Update Event</th></tr></thead> <tbody> <tr> <td> <input type="text" name="en_" value="<?php echo $z['event_name']; ?>"> </td> </tr> <tr> <td> <input type="text" name="dates_" value="<?php echo $z['start_date']; ?>"> <input type="text" name="times_" value="<?php echo $z['start_time']; ?>"> </td> </tr> <tr> <td><input type="text" name="datee_" value="<?php echo $z['end_date']; ?>"> <input type="text" name="time_" value="<?php echo $z['end_time']; ?>"> </td> </tr> <tr> <td><input type="text" name="ev_" value="<?php echo $z['event_venue']; ?>"> </td> </tr> <tr> <td><input type="submit" name="update" value="Update Event" id="update"> <input type="submit" id="cancelupdate" name="cancel" value="Cancel" > </td> </tr> </tbody> </table> </div>this is the part which is populated by data from database where isset($_POST['check']) gets the 'check' from: echo "<tr> <td><input type='checkbox' name='check[]' value='$id'>$name </td> </tr>";</form> thanks in advance! Edited by noobdood, 19 May 2014 - 10:42 PM. Hello.
I'm not sure whether this would come under PHP or HTML, but some sites display how many shares an article has had in a font, like this:
https://dl.dropboxus...0726.183853.png
What would the best way of doing this be?
Thanks.
I have a Php application that already has 2 buttons with input on the index page that perform some functions and output to different Php pages. Works good. How do I add a button with no input that would just perform a function and then just display a popup window showing the contents of a text file? I want to add several of these buttons for different functions and just display the contents of the resulting text files in popup windows. Any help would be greatly appreciated. Thanks in advance. Hello all , here is another problem of my project. I need to create a textarea , drop down list and submit button . At first , I can type whatever I want in the textarea , but for certain part I can just choose the word I want from drop down list and click submit , then the word will appear in the textarea as my next word . But I have no idea how to make this works , is there any simple example for this function ? Thanks for any help provided . Hi i have this edit form that allows user to mofy data but the problems on the text box is that it deletes the rest of the data after the space from the first word i tried to increase the size of the varChars on mysql but did no work why it happens how can i stop from happening?? this the form input <input type="text" name="name" id="name" class='text_box' value="<?php echo $_GET['name'];?>"/> I'd like to use a text editor like this one: http://tinymce.moxiecode.com/examples/full.php for my forums. But I am not sure exactly how I would prevent abuse and injects to messed up the page, rather than being contained in the designated area it is meant for. Could some one please help me, I know htmlspecailchars will not work, since some of the code needs to render as html I’m trying to construct a button that simply writes an "aleph" character into a text area, see below.
My code does not work, can anyone tell me why ? How should I fix it ?
<!DOCTYPE html> <html> <meta charset="UTF-8"> <head> <title>Example</title> <script type="text/javascript"> //JavaScript code goes here function insertAtEnd(text) { var theArea = document.getElementById("thisArea"); theArea.value += '' + text + '';; } </script> </head> <body> <input type="button" id="aleph" name="aleph" value="Write an aleph" onClick="javascript:insertAtEnd(\'<span>א</span>\');return(false)" /> <textarea id="thisArea"> </textarea> </body> </html> Hi, I am writing several scripts and some are used to amend extra information to a text file. However, I added a hyperlink to the text file so that the user can go back to a page where they can add extra information. However, since I have done this every time I amend more text to the text file, the extra text appears below the hyperlink rather than above it, and I was wondering if there was a way around this. My amend code is as follows: Code: [Select] <html> <head> <title>Amend File</title> <link rel="stylesheet" type="text/css" a href="rcm/stylesheet.css"> </head> <?php if($_POST['append'] !=null) { $filename="C:/xampp/htdocs/rcm/denman2.txt"; $file=fopen($filename, "a"); $msg="<p>Updated Information: " .$_POST['append']. "</p><br>"; fputs ($file, $msg); fclose($file); } ?> <body> <h1>Do you want to append to a document?</h1> Enter Updated Information: <form action="amendfile2.php" method="post"> <input type="text" size="40" name="append"><br><br> <input type="submit" value="Add updated information to report"> </form> <form action="viewfile3.php" method="post"> <input type="submit" size="40" value="View Web Blog"> </form> <form action="loginform.php" method="post"> <input type="submit" value="Click here to go to the Log In Screen"> </form> </body></html> And my text file is as follows: Code: [Select] <h1>Accident Report</h1> <p>First Name: Andrew Last Name: Denman Age: 18 Complete Weeks Since Accident: 2<br> <a href="amendfile2.php">Amend to this file</a> Any help would be appreciated I currently am working on a project where I code a "simple" telephone directory. There are three main tasks that it needs to do: 1. Directory.php(index page) has a "First Name" and "Last Name" field and a search button. When a name is searched from the directory.txt file, it displays First Name, Last Name, Address, City, State, Zip and phone in findinfo.php in designated text boxes...first name, last name, etc. 2. From the findinfo.php, like previously stated, the users information is listed in the appropriate text boxes. From there, there is an update button that will overwrite the user's information to directory.txt if that button is selected. It will then say the write was sucessful. 3. (completed this step) From the index page, there is a link that will take you to addnew.php where you enter First Name, Last Name, Address, City, State, Zip and phone in a web form and write it to directory.txt. This is the php code for the third step: <?php $newentryfile = fopen("directory.txt", "a+"); $firstname = $_POST['fname']; $lastname = $_POST['lname']; $address = $_POST['address']; $city = $_POST['city']; $state = $_POST['state']; $zip = $_POST['zip']; $phone = $_POST['phone']; $newentry = "$firstname $lastname\n\r $address\n\r $city, $state $zip\n\r $phone\n\r"; if (flock($newentryfile, LOCK_EX)) { if (fwrite($newentryfile, $newentry) > 0) echo "<p>" . stripslashes($firstname) . " " . stripslashes($lastname) . " has been added to the directory.</p>"; else echo "<p>Registration error!</p>"; flock($newentryfile, LOCK_UN); } else echo "<p>Cannot write to the file. Please try again later</p>"; fclose($newentryfile); if(empty($firstname) || empty($lastname) || empty($address) || empty($city) || empty ($state) || empty($zip) || empty($phone)) { echo "<p>Please go back and fill out all fields.</p>"; } ?> So to sum it all up, what would be my best approach? I am totally stumped and not sure which function to use. Should I work my way from step 1 to step 2? I see it as when I do the search for the name from directory.php, it takes me to findinfo.php, listing the users information in the text boxes. From there, if I needed to, having the user's information already listed I could hit the update button to overwrite the new information to directory.txt. Doing the update when then tell me that the write was successful. I have literally been scouring the internet for hours. What would be the best function to do this? I hope I was clear enough. Please help me out and thank you for your time. Hi there. How do I reflect the text content of the variable $a in this text form: <input type="text" name="artist"> Regards Morris Ok i have been working on this for a day+ now. here is my delema simple .ini text file. when a user makes a change (via html form) it makes the correct adjustments. problem is the newline issue 1. if i put a "\n" at the end (when using fputs) works great, except everytime they edit the file it keeps adding a new line (i.e. 10 edits there are now 10 blank lines!!!!) 2. if i leave off the "\n" it appends the next "fgets" to that lilne making a mess Code: [Select] ##-- Loop thruoght the ORIGINAL file while( ! feof($old)) { ##-- Get a line of text $aline = fgets($old); ##-- We only need to check for "=" if(strpos($aline,"=") > 0 ) { ##-- Write NEW data to tmp file fputs($tmp,$info[$i]." = ".$rslt[$i]."\n"); $i++; } ##-- No Match else { fputs($tmp,$aline."\n"); }//Checking for match }//while eof(old) what in the world is making this such a big deal. i dont remember having this issue in the past I tried opening with w+, and just w on the temp file a typical text line would be some fieldname = some value the scipt cycles through the file ignoring comments that are "#" ps the tmp file will overwrite the origianl once complete all i really want to know is WHY i cant get the newline to work, and what is the suggested fix EDIT: i just tried PHP_EOL and it still appends another newline Is it possible to have a text field on my site, and the text that is entered into it, be given to another site that I auto redirect the user to? If it is possible, could somebody give me the exact code (I'm not a programmer) I would need to use? Thanks for any help on this. |