PHP - Code To Display Box Instead Of Posting?
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. Similar TutorialsJust a heads up, my OOP skills are in development so sorry for the roughness of things...(any tips always appreciated!) I'm basically making my own little repository site that will have snippets (for quick copy paste anywhere) (I know there are other services, but mine is a little different and needs to be private). I'll try to just post the necessary code: HTML trying to pass: Code: [Select] <p><br /><span class="something">Hey buddy</span></p> Javascript/JQuery: Code: [Select] //send info $.ajaxFileUpload({ url:'./upload_zip.php', secureuri:false, fileElementId:'form_zip', dataType: 'json', data: {... 'description': htmlEntities($('#modularContent form textarea[name="description"]').val())...}, success:function(data, status){ var html = ... html+= ...'<div class="description"><p>'+data.description+'<br /><br />';... $('#list').append(html); ... $('#modularOverlay,#modularContent').remove(); }, error:function(data, status, e){ alert(e); } ... function htmlEntities(str) { return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); } //found via: http://css-tricks.com/snippets/javascript/htmlentities-for-javascript/ PHP: Code: [Select] <?php //Start object and modify initial values public function __construct($title,$description,$url,$snippet){ ... if($this->snippet == 'yes'){ $this->handle_snippet(); } } public function handle_snippet(){ $code = htmlentities($this->description, ENT_QUOTES | ENT_IGNORE, 'UTF-8',false); $this->description = $code; } //returning value public function getJSON($action){ //temp fix for js breaking if remove_tag_ids is empty/null if(empty($this->remove_tag_ids)){ $this->remove_tag_ids = 'null'; } if($this->snippet == 'yes'){ $this->description = stripslashes($this->description); } switch($action){ case 'delete': //not important default: $json = array(...'description'=>$this->description...); break; return $json; } ?> POST Value: (via firebug) Code: [Select] description: <p><br /><span class="something">Hey buddy</span></p> JSON Return value: (via firebug) Code: [Select] description: <p><br /><span class="something">Hey buddy</span></p> DB value: Code: [Select] <p><br /><span class=\"something\">Hey buddy</span></p> As far as error, I have no idea what the error is haha. It does not get through to the error code cause the plugin tosses an error b4 that (using an ajaxUpload plugin http://www.phpletter.com/Our-Projects/AjaxFileUpload/, (this does not affect the upload, it uploads just fine, but it tosses an error for some reason)). Anyone have any insights/ideas? Thanks for any and all help, Justin I 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 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) 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. 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 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. 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. 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? 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. 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: 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, 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! 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. <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. 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! i'm doing a form that posts values to XML, and i don't know how. can someone help me with a quick lesson in passing variables/XML data? i don't even know what question to ask, actually - the XML format i've been given is: Code: [Select] <?xml version="1.0" encoding="UTF-8"?> <lead> <innerNode></innerNode> <last_name>Smith</last_name> <first_name>John</first_name> </lead> and what i've come up with so far is this, but i don't even know if i'm on the right track: Code: [Select] $last_name = $_REQUEST['l_name']; $first_name = $_REQUEST['f_name']; $url = "http://url.com/leads"; $post_string = '<?xml version="1.0" encoding="UTF-8"?> <lead> <innerNode></innerNode> <last_name>'.$last_name.'</last_name> <first_name>'.$first_name.'</first_name> </lead>'; $header = "POST HTTP/1.0 \r\n"; $header .= "Content-type: text/xml \r\n"; $header .= "Content-length: ".strlen($post_string)." \r\n"; $header .= "Content-transfer-encoding: text \r\n"; $header .= "Connection: close \r\n\r\n"; $header = $post_string; $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 4); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header); $data = curl_exec($ch); if(curl_errno($ch)) { print curl_error($ch); } else { echo "yay"; curl_close($ch); } i'm being told "should return a response.xml with either a success or failure post status." which is confusing me can someone help a bit? thanks very much... GN TWO questions: I haven't actually CONNECTED and POSTED. My form has two input fields that combine in a TOTAL field. I notice that the address bar is carrying TOTAL=input1+input2 when it TRIES to connect. Do I need to include the TOTAL field in the database if the info is NOT relavant data? the strg and chick TOTALS? Will the database accept PARTIAL data from a form that has 25 field with only 6 being populated for testing? Hi, i have written a form that uses 3 dropdown boxes, one of them being populated from a database. The form code is as follows; Code: [Select] <form id="pointsForm" name="pointsForm" method="post" action="points-engine.php"> <select name="car" id="car"> <?php // result of car name collection $result = mysql_query ($query); //Array stored in $cars while($cars=mysql_fetch_array($result)){ //option values added by looping through array echo "<option value=$cars[id]>$cars[carName]</option>"; } ?> </select> <select name="season" id="season"> <option value="low">Low season</option> <option value="mid">Mid season</option> <option value="high">High season</option> <option value="peak">Peak season</option> </select> <select name="period" id="period"> <option value="day">One day</option> <option value="weekend">Weekend</option> <option value="week">One week</option> </select> <input type="submit" name="Submit" value="Submit" /> </form> which posts to; Code: [Select] <?php $car=$_POST['car']; echo $car; $season=$_POST['season']; echo $season; $period=$_POST['period']; echo $period; ?> The initial form code is working fine, the car field is being populated from the database. My problem is the post value for car isn't working... points-engine.php is echoing $season & $period fine but not $car can anyone tell me why? many thanks Richard How can I post this variable $healspell when I already have an echo within a php? Here's what I have: echo '<p>You cast Nature\'s Cure (Recovered <?=$healspell?>)</p>'; It's not printing anything out at the moment, obviously, and if I just put $healspell, it just echos out: $healspell. Thanks! |