PHP - How To Fix The Code Display Problem
hello
I need to fix code display problem. The code below cause the disorder problem. When I delete the part of it , the code display in the right way. I do not really understand it . The template try to use bx_textarea to display code,so I find the function in it. Finally , I found this function cause the disorder code problem. Code: [Select] <?php echo bx_highlight(bx_textarea($view_query_result['jdescription']), $kwd_search);?> Code: [Select] if ($char == "<") { $skip=1; } elseif ($char == ">") { $skip=0; } elseif ($char == " ") { $wrap=0; } if ($skip==0) { $wrap=$wrap+1; } Code: [Select] function bx_wordwrap($a_str, $a_break_length=75) { $length = strlen($a_str); for ($i=0; $i<=$length; $i=$i+1) { $char = substr($a_str, $i, 1); if ($char == "<") { $skip=1; } elseif ($char == ">") { $skip=0; } elseif ($char == " ") { $wrap=0; } if ($skip==0) { $wrap=$wrap+1; } $res_str = $res_str . $char; if ($wrap>$a_break_length) { $res_str = $res_str." "; $wrap=0; } } return $res_str; } function bx_textarea($text) { return nl2br(preg_replace('/\t/',' ',bx_wordwrap($text, 75))); }//end function bx_textarea($text) Similar TutorialsI have the following code in html: <html> <head> <script type="text/javascript"> <!-- function delayer(){ window.location = "http://VARIABLEVALUE.mysite.com" } //--> </script> <title>Redirecting ...</title> </head> <body onLoad="setTimeout('delayer()', 1000)"> <script type="text/javascript"> var sc_project=71304545; var sc_invisible=1; var sc_security="9c433fretre"; </script> <script type="text/javascript" src="http://www.statcounter.com/counter/counter.js"></script><noscript> <div class="statcounter"><a title="vBulletin statistics" href="http://statcounter.com/vbulletin/" target="_blank"><img class="statcounter" src="http://c.statcounter.com/71304545/0/9c433fretre/1/" alt="vBulletin statistics" ></a></div></noscript> </body> </html> Is a basic html webpage with a timer redirect script and a stascounter code. I know a bit about html and javascript, but almost nothing about php. My question is: How a can convert this html code into a php file, in order to send a variable value using GET Method and display this variable value inside the javascript code where says VARIABLEVALUE. Thanks in adavance for your help. hello i need help on displaying php code on my website so people can come and just copy it but it wont let me display it Hey guys, I'm opening a HTML file from my server, and i can successfully echo it both as code to show the page, and as code which the person can then edit in a <textarea>. However, there are certain sections of the code i do not what echo'd to the page. What is the best way to go about stipping them? For example i do not want the user to be able to edit the doctype, head element, <header> or <nav> sections of the code. Thanks in advance Danny. Bad title, I know. What I mean is I have a code that shows a pop-up error message if you try to post with a username someone else has. Well, I use this code for my user/pass/message fields: $user = preg_replace("/[^A-Z a-z0-9]/", "", $_POST['user']); $password = preg_replace("/[^A-Za-z0-9]/", "", $_POST['password']); $message = preg_replace("/[^A-Za-z0-9]/", "", $_POST['message']); What that does is, if you post with, say, a less than or greater than sign, or some other whack character, it makes the field blank for whichever field(s) you enter other characters into. So really, when someone posts on my forums with a character I do not want them to use in their user/message, it makes the message completely blank, no matter what other allowed characters are used, and the same with the username...so the post will show up without a poster. My question is, what is a code to use so a pop-up box would show up instead of letting the post go through and post blanks? Doesn't even have to be a pop-up box, just something to say to the user, "Hey, you can't use (insert disapproved character(s) here)" and to have the post not go through. Hi guys, I am still working on the same code, but encountered another problem. I have a form that takes imput to a MySQL database. It is 5 fields (id,title,category,content,tags). Then I have form a new page that searches with FullText on the (title and tags) fields and echos a link with the content of the result like this: $link = "<h2><a class='example7' href='tutorial.php?id=" . $rowS['id'] . "&title=" . htmlentities($rowS['title'], ENT_QUOTES) . "&category=" . htmlentities($rowS['category'], ENT_QUOTES) . "&content=" . htmlentities($rowS['content'], ENT_QUOTES) . "&tags=" . htmlentities($rowS['tags'], ENT_QUOTES) . "'>" . htmlentities($rowS['title'], ENT_QUOTES) . "</a></h2><br><br>"; Then when the user clicks this link, it takes them to the tutorial.php page that all it does is echo the content passed by this link and make it look nice. The problem is that when the data of the content field is greater than 3972 characters in length it doesn't generate the code in the tutorial.php page. It's like if the url is too long to be passed or something... Is that my problem that I'm passing the content in a url? If that is the problem then how can I correct it? How else can I pass the result from the link to the tutorial.php page? I have a database that contains results of fantasy football games. I have a query that returns the results of the games team X played against the other teams in the league. The query works perfect in the database. Results are Quote Opponent Name: America Enforcers Wins Losses Draws 1 1 0 Last Game: Week 2 of 2011: 416.6 - 369.8 the query and the php code cycle thru each team that team X has played and brings up team X's record and the results of the last game played. My problem is that the code stops one team short. So Team X played teams A, B, C, D, E but the code only returns teams A, B, C, D E is left off. I can't for the life of me figure out what silly mistake I made. Code: [Select] <?php include_once('../other/functions.php'); $con = mysql_connect($hostname, $username, $password) OR DIE ('Unable to connect to database! Please try again later.'); $db = mysql_select_db($dbname, $con); $thing = $_GET['thing']; $query = "select selected.teamname AS selected_team, selected_score.score AS selected_score, week.week, year, home_id, ". "target_score.score as target_score, target.teamname as targetname, week.ID ". "from owners as selected ". "JOIN game_scores AS selected_score ON selected.owner_id = selected_score.team_id ". "JOIN game_setup ON game_setup.game_id = selected_score.game_id ". "JOIN game_scores AS target_score ON target_score.game_id = game_setup.game_id AND target_score.team_id != selected_score.team_id ". "JOIN owners AS target ON target.owner_id = target_score.team_id ". "JOIN week ON week.week = game_setup.week ". "WHERE selected.owner_id = $thing ". "and target.active = 1 ". "GROUP BY target.teamname, year, week.ID "; $result = mysql_query($query); $row = mysql_fetch_array($result); $result1 = mysql_query($query); $row1 = mysql_fetch_array($result1); if (!$result) { die('Invalid query: ' . mysql_error()); } $wins=0; $losses=0; $draws=0; $last_target = false; echo '<h2>' . $row1['selected_team'] . ' vs. Active Teams</h2>'; while ($row = mysql_fetch_assoc($result)) { if ($last_target['targetname'] != $row['targetname']) { if ($last_target) { printf(' <table border="1" width="600"> <tr> <th>Opponent Name:</th> <th colspan="2">%s</th> </tr> <tr> <th>Wins</th> <th>Losses</th> <th>Draws</th> </tr> <tr> <td align="center">%d</td> <td align="center">%d</td> <td align="center">%d</td> </tr> <tr> <th>Last Game:</th> <td colspan="2">%s of %s: %.1f - %.1f</td> </tr> </table><br/>', $last_target['targetname'], $wins, $losses, $draws, $last_target['week'], $last_target['year'], $last_target['selected_score'], $last_target['target_score'] ); } $wins = $losses = $draws = 0; } if ($row['selected_score'] < $row['target_score']) ++$losses; elseif ($row['selected_score'] == $row['target_score']) ++$draws; else ++$wins; $last_target = $row; } ?> Any ideas on how to make the magic elvish be good??? Thank you for your time. Hi guys! How do I display different code depending on the title/url? This is the code for the form that brings you from "http://www.xxx.uk/index.php" to "http://www.xxx.uk/index.php?name=ro": Code: [Select] <form name="input" action="http://www.xxx.uk/index.php?name=ro" method="post"> Enter student number:<input type="text" name="sid"/> <input type="submit" value="Submit"> Now when you are on "http://www.xxx.uk/index.php?name=ro" I would like another content(but written in the same php file). I tried with _GET, but the problem is that I don't simply want to add a word but a lot of content. With _GET, that whole content would have to be displayed in the title and I don't want that. Hello, I'm pretty new to php and have a small problem I can't figure out. I have passed some copy (john & mary) from a small form to a url with php (i used urlencode). The code in the url looks like this john+%26+mary. My problem is, how do I display the %26 as an actual ampersand (&) on the html page? Here is the snippet of code that I am currently using to display the names. <?php echo htmlentities($_GET['gallery']); ?> I have searched and searched and can't find anything to figure this out. Any help would be great. Thanks. So currently I have 2 files that pretty much does the same thing but connects to 2 different tables. I sort of want to merge it together to save file space and make everything more efficient: Hey guys I have a client who wants to upload images then have them display on his page... obviously that process is not an issue at all. The catch is he wants the image to change at midnight and display the next image in the sequence, then display it until midnight strikes, and then the next in the sequence is displayed. Is there any code type that will recognise a set time/date and display coressponding images in a database? I realise I made need to add a field for an ID number/date ID for the code to identify which image to display, but not sure what code will/wont work Can some one point me in the right direction would be much appreciated Thanks Tom Hi
I require a PHP code to get output table.
My Table
Item Qty Date aa-1 2 2014-10-01 aa-2 5 2014-10-01 aa-3 1 2014-10-01 ab-1 2 2014-10-01 ab-2 1 2014-10-01 bb-1 4 2014-10-01 bb-2 3 2014-10-01 bb-3 2 2014-10-01 aa-1 1 2014-10-02 aa-2 2 2014-10-02 aa-3 5 2014-10-02 ab-1 6 2014-10-02 ab-2 1 2014-10-02 bb-1 9 2014-10-02 bb-2 0 2014-10-02 bb-3 4 2014-10-02 aa-1 1 2014-10-03 aa-2 2 2014-10-03 aa-3 5 2014-10-03 ab-1 4 2014-10-03 ab-2 3 2014-10-03 bb-1 1 2014-10-03 bb-2 8 2014-10-03 bb-3 2 2014-10-03 I wrote code as mentioned below. <?php $accounts=mysql_connect("localhost", "root", "") or die("could not connect"); mysql_select_db("shops",$accounts) or die("could not find db!"); if(isset($_POST['search']) && ($_POST['from']) && ($_POST['to'])){ $searchq=$_POST['search']; $searchq=preg_replace("#[^0-9a-z]#i", "" , $searchq); $from=$_POST['from']; $to=$_POST['to']; $dateInput = explode('-',$from); $fdate = $dateInput[2].'-'.$dateInput[1].'-'.$dateInput[0]; $dateInput = explode('-',$to); $tdate = $dateInput[2].'-'.$dateInput[1].'-'.$dateInput[0]; for ($date=$fdate; $date<=$tdate; $date++) { $sql = "SELECT item, SUM(CASE WHEN `date` = '$date' THEN Qty ELSE 0 END) FROM shop WHERE item LIKE '%$searchq%' GROUP BY item"; $query = mysql_query($sql) or die("could not search!"); echo "<table border='1'>"; echo "<tr> <td>Item </td> <td>$date</td> </tr>" ; while ($row=mysql_fetch_array($query)) { echo "<tr> <td>". $row[0] ." </td> <td>" . $row[1] . "</td> </tr>"; } echo "</table>"; } } ?> I am getting result like this as I asked for three days. Item 2014-10-01 aa-1 2 aa-2 5 aa-3 1 Item 2014-10-02 aa-1 1 aa-2 2 aa-3 5 Item 2014-10-03 aa-1 1 aa-2 2 aa-3 5 But I need result like below Item 2014-10-01 2014-10-02 2014-10-03 aa-1 2 1 1 aa-2 5 2 2 aa-3 1 5 5 Can anybody help me to write PHP code to display result as needed. Please help. Thanks in advance. Hi, I'm trying to fetch rows of data from a mysqli table and display them in the browser in categories. I have the while loop working fine, but I want to break the results down into categories, instead of one big list sorted by a field using ORDER BY. So for example, let's say I have a database table containing people's names, email address, phone numbers, etc. and I want to display them in the browser in separate tables by the city in which they live (each city name would be a h1 or h2 tag) and the appropriate rows would be displayed under each heading, sorted by the person's name. I can do it by using multiple while loops, separating each city into it's own array and then repeating my html table code a bunch of times, but I know there has to be a much cleaner way. Can anyone point me in the right direction? Thanks! Hi everyone, I am a beginner web designer and a novice php user. I am a regular forum user and understand that you should always do a search and try to find the answer yourself but I have done that and didn't get any results (or I didn't understand them!). So I ask for some assistance - either you can tell me the code or link me to the correct answer. I am working on a website that I have built a enquiry form for and it has a php script for it. I have managed to get the form running properly and got the reCaptcha working correctly (with a custom error page) but I do not understand how to add custom error pages for incomplete email addresses, empty email addresses, or for a blank form? I tried using the same tactic I used for the reCaptcha error page but it didn't work - probably because I was guessing and just tried it in a bunch of different places. The error msg that displays now is just a plain white page with the msg - Email address is invalid appearing at the top left. While this is suitably functional it doesn't really look like much so I want to build a custom page for each error that could happen. So the code is below - if anyone can point a beginner in the right direction I would be super happy. :mrgreen: if you need anymore code or other details just tell me and I will post them up. The url of the form page is http://www.sunsolutionshomeimprovement.com/onlinesales.html This is the code I think you will need - I got it from a demo php script that I have modified. As I said I don't have much clue what I'm doing so I just posted it exactly how it looks - if I over did it I apologize... :oops: 68.// Validate email field. 69. 70.if(isset($_REQUEST['email']) && !empty($_REQUEST['email'])) 71.{ 72. 73.if(preg_match("/(%0A|%0D|\n+|\r+|:)/i",$_REQUEST['email'])){$errors[] = "Email address may not contain a new line or 74.a colon";} 75. 76.$_REQUEST['email'] = trim($_REQUEST['email']); 77. 78.if(substr_count($_REQUEST['email'],"@") != 1 || stristr($_REQUEST['email']," ")){$errors[] = "Email address is invalid";}else{$exploded_email = explode("@",$_REQUEST['email']);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] = "Email address is invalid";}else{if(substr_count($exploded_email[1],".") == 0){$errors[] = "Email address is invalid";}else{$exploded_domain = explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = "Email address is invalid";}else{foreach($exploded_domain as $value){if(strlen($value) > 63 || !preg_match('/^[a-z0-9-]+$/i',$value)){$errors[] = "Email address is invalid"; break;}}}}}} 78. 79.) 80. 81.// Check referrer is from same site. 82. 83.if(!(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']))){$errors[] = "You must enable referrer logging to use the form";} 84. 85.// Check for a blank form. 86. 87.function recursive_array_check_blank($element_value) 88.( 89. 90.global $set; 91. 92.if(!is_array($element_value)){if(!empty($element_value)){$set = 1;}} 93.else 94. 95. 96.foreach($element_value as $value){if($set){break;} recursive_array_check_blank($value);} 97. 98.) 99. 100.) 101. 102.recursive_array_check_blank($_REQUEST); 103. 104.if(!$set){$errors[] = "You cannot send a blank form";} 105. 106.unset($set); 107. 108.// Display any errors and exit if errors exist. 109. 110.if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;} 111. 112.if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" : "\n");} 113. 114.// Build message. I don't think there is anymore that is relevant? I just want to reiterate that I know nearly nothing about this stuff so if you could keep your answers simple it would help a lot - cheers! <ul> <!-- List the rest of the articles found in the category --> <?php else : ?> <li class="otherrecentmain"><span class="title"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></span> <span class="meta"></span> </li> <?php endif; ?> <?php endwhile; ?> <!-- END --> </ul> For some reason, its stuck on displaying 9 articles but I want to be able to control how many I want. I may want to choose 17 or whatever etc, not sure how to add it into the php. Please i need help on popup message when an image is clicked. Some one should help me with the code to place in my html document. Hey guys,
I have problem displaying some stuff from mysql.
Idea was that Order's have rows like - OrderID|CustomerID|OrderDesc
So when i run $checkIsHavingOrders = mysql_query("SELECT * FROM orders ORDER BY OrderID DESC limit 10 WHERE CustomerID = '$myID'");
it should print
OrderID|CustomerID|OrderDesc
1001|1|Skin
1021|1|Skin
1031|1|Skin
(I made up the numbers so you can get image of thing i am trying to do..)
Thanks for your time!
hi, i have mysql table like table1 table2 ----------------------- ------------------------ | A | B | | 1 | 2 | | C | D | | 3 | 4 | | E | F | ---------------------------- ------------------------ now i want to display them in html table cells(td)... like -------------------------------------------------------------------------------- A | B | 1 | 2 -------------------- C | D | 3 | 4 --------------------- E | F | ---------------------- ok i was trying this it in while looping but unable to do soo........... I am making a script that has a Notification/Inbox system in it. Right know it's close to being done, but I have one problem.. My problem is that if a user has >= 1 message in their inbox it shows what it should, but if the user has nothing in the inbox it shows nothing instead of the simple error "You have no message in your inbox". Code 1: $inbox_a = mysql_query("SELECT * FROM notifications WHERE recieverid='". $_SESSION['id'] ."'") or die(mysql_error()); Code 2: <?php if(!mysql_num_rows($inbox_a) <= 0) { ?> <tr class="table"> <td class="name"><a href="usercp.php?usercp=inbox&id=<?php echo $msgid; ?>"><h3><?php echo ucFirst($msgname); ?></h3></td> <td class="revision"><h3><a href="#"><?php echo $msgsendername ?></a></h3></td> <td class="votes"><h3><?php echo date('D, M d, Y h:i A', strtotime($msgdate)) ?></h3></td> </tr> <?php } else { ?> <tr class="table"> <td class="name">You have no messages in your inbox.</td> <td class="revision"></td> <td class="votes"></td> </tr> <?php } ?> I have a messaging system that I'm trying to send a notification by email to a specific person when a new message is entered. Everything is working fine except how the message is displayed in the email. Here's the problem: When the message reads: "This is a test. This should be two lines down. This is on the next line!" this is what is displayed in the email: "This is a test.\r\n\r\nThis should be two lines down.\r\nThis is on the next line!" How I'm displaying the message is by inserting it into a database first. Then I do a query to pull it back from the database on another page using the variable $message. I have tried using just $message and using nl2br("$message") and they both display as shown above. Does anyone have any ideas on how to get the message to display properly in the email? Here's the code that I'm using to send it in if it will help: Code: [Select] <?php $message2 = nl2br("$message"); $sendto2 = "$email"; $emailsubject2 = "New Message"; $emailmessage2 = "<html> <body> <table width=\"500\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td> $prefix $lname, <p> This message is to notify you that a new message has been sent. A copy of the message has been included below.<br> <hr width=\"500\"><br> <strong>Subject: \"$subject\"</strong> <p>$message2</p> Thank you! </td> </tr> </table> </body> </html>"; // To send HTML mail, the Content-type header must be set $headers2 = 'MIME-Version: 1.0' . "\r\n"; $headers2 .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers2 .= 'From: Admin <support@domain.us>' . "\r\n"; // Mail it mail($sendto2, $emailsubject2, $emailmessage2, $headers2); ?> I'm trying to simply display the contents of an entire database for the purpose of building an administrative super-user into the back-end to remove login credentials without having to resort to having to manually interact with Mariadb or PHPmyadmin. However, the code is only returning the last row that was entered into the database. I can't seem to figure out why it's not working as intended. The code is intended to simply display the entire contents of the database into an html table. The code i'm using: <?php $link = mysqli_connect("127.0.0.1", "database user", "password", "login"); if (!$link) { echo "Error: Unable to connect to MySQL." . PHP_EOL; echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL; echo "Debugging error: " . mysqli_connect_error() . PHP_EOL; exit; } if ($result = mysqli_query($link, "SELECT * FROM accounts", MYSQLI_STORE_RESULT)) { while ($row = $result->fetch_assoc()) { $id = $row["id"]; $username = $row["username"]; $pass = $row["password"]; $email = $row["email"]; $su = $row["su"]; } } mysqli_close($link); ?> <!DOCTYPE html> <html> <head> </head> <body> <table> <tr> <th>id</th><th><th>user name</th><th>password</th><th>email</th><th>elevated privlege</th></tr> <tr> <td> <?php echo $id; ?> </td> <td> <?php echo $username; ?> </td> <td> <?php echo $pass; ?> </td> <td> <?php echo $email; ?> </td> <td> <?php echo $su; ?> </td> </tr> </table> </body> </html> Edited August 31, 2020 by bakertaylor28 correction of the code used. |