PHP - Stop Displaying Html As Text
$('input#name-submit').on('click', function() { var name = $('input#name').val(); if ($.trim(name) != '') { $.post('play2.php', {name: name}, function(data) { $('div#name-data').text(data); }); } });data contains html code but when it is displayed it is displayed as text and shows the html, how can I get the html code to function properly? thanks Similar TutorialsI have a habit of doing stuff like such: Code: [Select] <div class="portal_box"> <h2>Welcome to ZombieCraft's Highscores!</h2> <div class="portal_content"> Here you can sort the pros from the noobs, or just simply see whos on top of their game. The highscores will show the highsest scores, greatest to least. If you want to see a certain user's score, then just use the search button! <?php $username = $_SESSION['loggedin']; $extract_user_rank = mysql_query("SELECT rank FROM users WHERE username='$username'"); $grab = mysql_fetch_assoc($extract_user_rank); if($grab['rank'] > 0) { echo "</br><br/><a href='control_panel.php'>Admin Control Panel</a>"; } else { //return nothing } ?> </div> </div> I've been told a good bit of times that I need to stop using HTML and PHP in the same lines. How would one accomplish this? 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. Hello friends, if i've textarea form or even input how to prevent visitors to write html codes inside it ? thanks how can i use die but still continue with the html in the rest of code instead of stopping all codes from where die is initiated. i want to die (insert into database) but then still allow the html codes below the die function to work still. \= I've got a simple internal messaging system that I'm trying to get the text to display the way it was entered when a message was sent. The messages are inserted into the database using variables generated through this function: Code: [Select] <?php function safe($value){ return mysql_real_escape_string($value); } $staffid=form($_POST['staffid']); $from=safe($_POST["from"]); $category=form($_POST['category']); $subject=safe($_POST["subject"]); $message=safe($_POST["message"]); $grade=form($_POST['grade']); ?> when the text is inserted, there are back slashes automatically inserted behind certain punctuation marks. For example, is someone sends a message that says, "Someone's using phpfreaks forums." It would be inserted as, "Someone\'s using phpfreaks forums." How can I stop this from happening? Or how can I remove the "\" when displaying the string on the web page? Any help is greatly appreciated. I've taken this eg from php manual site for displaying txt on image wonder why it is not working Code: [Select] <?php // Create a 300x150 image $im = imagecreatetruecolor(300, 150); $black = imagecolorallocate($im, 0, 0, 0); $white = imagecolorallocate($im, 255, 255, 255); // Set the background to be white imagefilledrectangle($im, 0, 0, 299, 299, $white); // Path to our font file $font = './arial.ttf'; // First we create our bounding box for the first text $bbox = imagettfbbox(10, 45, $font, 'Powered by PHP ' . phpversion()); // This is our cordinates for X and Y $x = $bbox[0] + (imagesx($im) / 2) - ($bbox[4] / 2) - 25; $y = $bbox[1] + (imagesy($im) / 2) - ($bbox[5] / 2) - 5; // Write it imagettftext($im, 10, 45, $x, $y, $black, $font, 'Powered by PHP ' . phpversion()); // Create the next bounding box for the second text $bbox = imagettfbbox(10, 45, $font, 'and Zend Engine ' . zend_version()); // Set the cordinates so its next to the first text $x = $bbox[0] + (imagesx($im) / 2) - ($bbox[4] / 2) + 10; $y = $bbox[1] + (imagesy($im) / 2) - ($bbox[5] / 2) - 5; // Write it imagettftext($im, 10, 45, $x, $y, $black, $font, 'and Zend Engine ' . zend_version()); // Output to browser header('Content-Type: image/png'); imagepng($im); imagedestroy($im); ?> So, I'm trying to get this read my text document "news.txt" and display the contents. My code: Code: [Select] div.newscontent{ padding:0px; margin-top:60px; margin-bottom:0px; margin-left:400px; margin-right:0px; position:absolute; width:457px; height:330px; text-align:center; color:#FFFFFF; } Code: [Select] <div class='newscontent'> <?PHP $filename = "news.txt"; $arr = file($filename); foreach($arr as $line){ print $line . "<br/>"; } ?> </div> This is the output I get: Code: [Select] "; } ?> Whats wrong? When I add some text to the front end of the textarea it displays Code: [Select] bla <br/> bla <br/> bla <br/> How can I stop it from showing the html tags? Thanks. echo'<textarea id="info" style="width:80%; height:60px;">'; } echo $profile['info']; if($_SESSION['user_id'] == $id) { echo'</textarea><input type="submit" style="width:70%" value="send" onclick="updateInterests(document.getElementById(\'info\').value)" />'; I am trying to get this to work in an html page. Code: [Select] <head> <?php require_once('fn.inc.php'); $out=output_rss_tag($ret); ?> </head> <head> <title> </title> <style type="text/css"> <!-- h1 {text-align:center; font-family:Arial, Helvetica, Sans-Serif; } p {text-indent:20px; } --> </style> </head> <body bgcolor = "#ffffcc" text = "#000000"> <h1>server status!<?php echo $ret[SONGTITLE]; ?></h1> </body> </html>I cant seem to figure out why its not diplaying the results Many thanks I am retrieving data from a third party's API using AJAX method. I would like to do two things. 1. Display the data records on a page. 2. Create a pagination on the page to display records more efficiently. I am expecting to retrieve possibly hundreds of records. I can normally do this using PHP but since I am retrieving the records using AJAX, the pagination is gonna be a challenge. First things first is to display the records. Here is my AJAX code. It displays the log data fine. But it doesn't display any data in the "output" div. And it gives this error in the console. Uncaught SyntaxError: Unexpected token o in JSON at position 1 at JSON.parse (<anonymous>) at Object.success <div class="output"></div> <script> $.ajax ({ type: 'GET', url: "https://3rdpartywebsite.com/api/GetCustomers", dataType: 'json', processData: false, contentType: false, success: function(data) { console.log(data) $newData = JSON.parse(data); $.each($newData, function(i, v) { $('.output').append(v.LastName); $('.output').append(v.FirstName); }); } }); </script>
What am I doing wrong? Edited November 14, 2020 by imgroootapparently I am doing this wrong. I want my string results from a form that searches DB content to appear within HTML table, tr, td tags. I get the results fine, but the HTML part isn't appearing. How should I be doing this? <?php $string = ''; $result = mysql_query($sql); /// This is the execution if (mysql_num_rows($result) > 0){ while($row = mysql_fetch_object($result)){ echo "<table>"; echo "<tr>"; $string .= "<td>".$row->last_name."</td> "; $string .= "<td>".$row->first_name."</td>"; $string .= "<td>".$row->employee_id."</td>"; $string .= "<td>".$row->title."</b>"; $string .= "<td>".$row->territory."</td>"; $string .= "<td>".$row->district."</td>"; $string .= "<td>".$row->Phase1A_Score."</td>"; $string .= "<td>".$row->Phase1B_Score."</td>"; $string .= "<td>".$row->Phase1_Average."</td>"; $string .= "<td>".$row->Phase1A_HS_Exam."</td>"; $string .= "<td>".$row->Phase1A_HS_Exam_RT."</td>"; $string .= "<td>".$row->Phase1B_HS_Exam."</td>"; $string .= "<td>".$row->Phase1B_HS_Exam_RT."</td>"; $string .= "<td>".$row->Class_Date."</td>"; $string .= "<td>".$row->Awards."</td>"; $string .= "<br/>\n"; echo "</tr>"; echo "</table>"; } }else{ $string = "No matches found!"; } echo $string; ?> Hi everyone I just getting back to PHP after a break but have forgot how to build a HTML table row. Here is the part of the code that builds up rows for a html table... while($rows = mysql_fetch_array($qry)){ $table .= " <tr> <td><input type=\"checkbox\" name=\"C1\" value=\"ON\"></td> <td width=\"87\">$rows['ref']</td> <td width=\"178\">$rows['transactionReferenceNumber']</td> <td>$rows['totalAmountReceived']</td> <td>$rows['myItemQuantity']</td> <td>$rows['flag_1']</td> <td>$rows['flag2']</td> </tr> "; } This causes an error as you might expect. Please tell me the best way to place the html code into $table Hello So in my index.php code i include('somefile.html');. In the html file itself there is an <img src="/images/picture.jpg">. When looking at index.php on a browser, the html looks fine everything loaded fine except for the <img> There is a little broken image link displayed on the page. i checked through the browser if i mistyped the img src link but somefile.html in the browser displays the image fine. But if i try to display the img in the html file through the php file, its a broken link. Any reason why this is happening? Am I missing something here? Thanks in advance. Hi there,
I'm a bit of a noobie, and I have a class which will allow me to send an email in html.
However when I send an email with a link such as <a href="http://www.google.com">link</a> using the html() function
The email is sent and everything is displayed corrected.
However the link isn't clickable.
Here is the code for the class.
<? class eMail { var $to = array(); var $cc = array(); var $bcc = array(); var $attachment = array(); var $boundary = ""; var $header = ""; var $subject = ""; var $body = ""; function eMail($name,$mail) { $this->boundary = md5(uniqid(time())); $this->header .= "From: $name <$mail>\n"; } function to($mail) { $this->to[] = $mail; } function cc($mail) { $this->cc[] = $mail; } function bcc($mail) { $this->bcc[] = $mail; } function attachment($file) { $this->attachment[] = $file; } function subject($subject) { $this->subject = $subject; } function text($text) { $this->body = "Content-Type: text/plain; charset=ISO-8859-1\n"; $this->body .= "Content-Transfer-Encoding: 8bit\n\n"; $this->body .= $text."\n"; } function html($html) { $this->body = "Content-Type: text/html; charset=ISO-8859-1\n"; $this->body .= "Content-Transfer-Encoding: quoted-printable\n\n"; $this->body .= "<html><body>\n".$html."\n</body></html>\n"; } function send() { // CC $max = count($this->cc); if($max>0) { $this->header .= "Cc: ".$this->cc[0]; for($i=1;$i<$max;$i++) { $this->header .= ", ".$this->cc[$i]; } $this->header .= "\n"; } // BCC $max = count($this->bcc); if($max>0) { $this->header .= "Bcc: ".$this->bcc[0]; for($i=1;$i<$max;$i++) { $this->header .= ", ".$this->bcc[$i]; } $this->header .= "\n"; } $this->header .= "MIME-Version: 1.0\n"; $this->header .= "Content-Type: multipart/mixed; boundary=$this->boundary\n\n"; $this->header .= "This is a multi-part message in MIME format\n"; $this->header .= "--$this->boundary\n"; $this->header .= $this->body; // Attachment $max = count($this->attachment); if($max>0) { for($i=0;$i<$max;$i++) { $file = fread(fopen($this->attachment[$i], "r"), filesize($this->attachment[$i])); $this->header .= "--".$this->boundary."\n"; $this->header .= "Content-Type: application/x-zip-compressed; name=".$this->attachment[$i]."\n"; $this->header .= "Content-Transfer-Encoding: base64\n"; $this->header .= "Content-Disposition: attachment; filename=".$this->attachment[$i]."\n\n"; $this->header .= chunk_split(base64_encode($file))."\n"; $file = ""; } } $this->header .= "--".$this->boundary."--\n\n"; foreach($this->to as $mail) { mail($mail,$this->subject,"",$this->header); } } } ?> So I have a jobs database with the following columns: id, jobtext, jobdate, and id. This is how it looks right now: http://prahan.com/jobs/display.html.php I have another table called author. In the authorid column in need the results of this query, SELECT name FROM author WHERE id = (SELECT authorid FROM job) , to be displayed for each row. I also want to be able to customize the header title for each column. Thanks in advance! Hello I'm making a guestbook in PHP and I'm having trouble displaying the posts. The user fills a form and sends it, it goes into the database (mysql) and I can then fetch the data. So far so good. I'm then going to use HTML to display the posts to the user. It's code looking like this: Code: [Select] <p> <br /> ID: ---replaceid--- <br /><br /> Time: ---replacetime--- <br /> From: <a href="---replacehomepage---">---replacefrom---</a> <br /> Email: ---replacemail--- <br /> <br /> Comment: ---replacecomment--- <br /><hr> </p> I want to use str_replace in PHP to replace the values in HTML... like this: Code: [Select] $numquery = mysql_query("SELECT * FROM guestbook", $dbconnect); $num = mysql_num_rows($numquery); $i=1; while ($i < $num) { header('Content-type: text/html'); $html = file_get_contents("test.html"); $query = mysql_query("SELECT * FROM guestbook WHERE id='$i'", $dbconnect); $rows = mysql_fetch_row($query); echo str_replace('---replaceid---', nl2br($rows[0]), $html); echo str_replace('---replacetime---', nl2br($rows[1]), $html); echo str_replace('---replacefrom---', nl2br($rows[2]), $html); echo str_replace('---replacemail---', nl2br($rows[3]), $html); echo str_replace('---replacehomepage---', nl2br($rows[4]), $html); echo str_replace('---replacecomment---', nl2br($rows[5]), $html); $i++; } But this only replaces ---replaceid---, leaves the rest and outputs it. Then, only ---replacetime--- is replaced and so on. I hope you understand. It means that 1 guestbook entry is displayed like 6, with only 1 string replaced at each one. What do you think I should do? Worth saying is that I'm not allowed to mix PHP-code with HTML-code Not really sure how to get the images I have stored in MySQL into a html form. I can call-up the text fields from the database but it cannot seem to find the index for the images. Here is my code:- <?php session_start(); mysql_connect("localhost","root","abc") or die ("Error! Cannot connect to database"); mysql_select_db("theimageworks") or die ("Cannot find database"); $query = "SELECT * FROM jobs"; $result = mysql_query($query) or die (mysql_error()); ?> <?php //display data in html table echo "<table>"; echo "<tr><td>Username</td><td align='center'>Message</td><td>Product Image</td></tr>"; while($row = mysql_fetch_array($result)) { echo "</td><td>"; echo $row['username']; echo "</td><td>"; echo $row['message']; echo "</td></tr>"; echo $row['image']; } echo "</table>"; ?> The error message I get is "Notice: Undefined index: image in....." Thanks in advance! Hi, I'm trying to make a dynamic html table to contain the mysql data that is generated via php. I'm trying to display a user's friends in a table of two columns and however many rows, but can't seem to figure out what is needed to make this work. Here's my code as it stands: Code: [Select] <?php //Begin mysql query $sql = "SELECT * FROM friends WHERE username = '{$_GET['username']}' AND status = 'Active' ORDER BY friends_with ASC"; $result = mysql_query($sql); $count = mysql_num_rows($result); $sql_2 = "SELECT * FROM friends WHERE friends_with = '{$_GET['username']}' AND status = 'Active' ORDER BY username ASC"; $result_2 = mysql_query($sql_2); $count_2 = mysql_num_rows($result_2); while ($row = mysql_fetch_array($result)) { echo $row["friendswith"] . "<br>"; } while ($row_2 = mysql_fetch_array($result_2)) { echo $row_2["username"] . "<br>"; } ?> The above simply outputs all records of a user's friends (their usernames) in alphabetical order. The question of how I'd generate a new row each time a certain amount of columns have been met, however, is beyond me. Anyone know of any helpful resources that may solve my problem? Thanks in advance =) Aloha, I am using a simple html form and php script to send data to a SMS gateway that I have setup already. Everything works great. I fill out the form, the data is sent and instantly I get a text message on my iphone. Here's the problem. If I use an apostrophe in the message text field I get an error code. I am assuming the html text field needed to be escaped but I tried everything and I still get the error. Any ideas on what to check or do? Here's the php send code (variables coming in from html form fields): Code: [Select] <?php if (!empty($_POST)) { $name = trim($_POST["name"]); $contactnumber = trim($_POST["contactnumber"]); $message = trim($_message); if (empty($name)) { exit("Name cannot be blank."); } if (empty($contactnumber)) { exit("Please provide a contact number."); } if (empty($message)) { exit("Message cannot be blank."); } $subject = "$name . $contactnumber"; $strlen_subject = ($subject != "") ? strlen($subject) + 3 : 0; $strlen_message = strlen($message); $express = $_POST["express"]; if ($express && ($strlen_subject + $strlen_message > 160)) { exit("In case of express delivery, message length should not exceed 160 characters."); } elseif ($strlen_subject + $strlen_message > 130) { exit("In case of standard delivery, message length should not exceed 130 characters."); } $subject = urlencode($subject); $contactnumber = urlencode($contactnumber); $message = urlencode($message); $ch=curl_init('https://app.eztexting.com/api/sending'); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch,CURLOPT_POST,1); curl_setopt($ch,CURLOPT_POSTFIELDS,"user=PuaDog&pass=808cougar&phonenumber=18087211458&subject=$subject&message=$message&express=1"); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); $data = curl_exec($ch); switch($data) { case 1: header('location:message_sent.php?message1=1'); break; case -1: print("Invalid user or password"); break; case -2: print("Credit Limit Reached"); break; case -5: print("Local Opt Out"); break; case -7: print("Invalid Message"); break; case -104: print("Globally Opted Out Phone Number"); break; case -106: print("Incorrectly Formatted Phone Number"); break; case -10: print("Unknown Error"); break; } } ?> Mahalo! Tom MOD Edit: [code] . . . [/code] tags added . . . |