PHP - Adding Limit To Code?
I had a piece of code which limited the number of items printed from a database. However, I can no longer get it to work.
Code: [Select] $query = "SELECT * FROM productfeed WHERE description like '%$description%' LIMIT 0, 3"; This is the code I am trying to limit, but I cant get it to work. Code: [Select] <?php ini_set('display_errors', 1); error_reporting(-1); $query = "SELECT * FROM productfeed"; if(isset($_GET['description']) && !empty($_GET['description'] )) { $description = $_GET['description']; $query .= " WHERE description like '%$description%'"; } if(isset($_GET['price']) && !empty($_GET['price'])) { $price = explode('-', $_GET['price']); $lowPrice = (int)$price[0]; $highPrice = (int)$price[1]; $query .= " AND price BETWEEN $lowPrice AND $highPrice"; } $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { $id = $row['id']; $image = $row['awImage']; $link = $row['link']; $description = $row['description']; $fulldescription = $row['fulldescription']; $price = $row['price']; echo "<div class='productdisplayshell'> <div class='productdisplayoutline'> <div class='productborder'><center> <a href='$link' target='_blank'><img src='$image' width=\"95%\" /></a> </center> </div></div> <div class='productdescriptionoutline'> <div class='productdescriptionbox'> <a href='$link' target='_blank' >$description</a> </div> <div class='productfulldescriptionbox'>$fulldescription</div> </div> <div class='productpriceoutline'> <div class='productpricebox'> <center>&#163; $price</center> </div> <div class='productbuybutton'> <center><a href='$link' target='_blank' ><img src=/images/buybutton.png /></a></center> </div> </div> </div>"; } if ($_GET['description'] == $description ) { echo 'Sorry, this product is not available. Please visit our <a href="http://www.ukhomefurniture.co.uk">Homepage</a>.'; } ?> <?php function sanitizeString($description) { $description = mysql_real_escape_string($description); $description = stripslashes($description); $description = htmlentities($description); return $var; $price = mysql_real_escape_string($price); $price = stripslashes($price); $price = htmlentities($price); return $var; } ?> Similar TutorialsI'm trying to add a file size limit to my upload form-code (below) I want to limit this tag to 25 characters when file runs, now it can be anywhere from 7-40 characters $teams = explode(" v ",$hie->Name);
foreach ($xml->xpath("//Competition[@id='NBA' and @sprtyp='BK']/Match") as $hie) { Hey guys, Im getting an undefined index limit in the whole code. This is my code: <?php session_start(); $_SESSION['prev_page'] = $_SERVER['REQUEST_URI']; if (!session_is_registered('username')) { header("location:login.php"); } ?> <hr> <style type="text/css"> table.gridtable { color:#333333; border-width: 1px; border-color: #666666; border-collapse: collapse; width: 100%; } table.gridtable th { border-width: 1px; padding: 1px; border-style: solid; border-color: #666666; background-color: #dedede; } table.gridtable td { border-width: 1px; padding: 1px; border-style: solid; border-color: #666666; } .valid { border-width: 1px; padding: 1px; border-style: solid; border-color: #666666; background-color: transparent; } </style> </div> <div class="newsJustify"> <script type="text/javascript"> function checkall(delchk) { for (i = 0; i < delchk.length; i++) delchk[i].checked = true; } </script> <script type="text/javascript"> function uncheckall(delchk) { for (i = 0; i < delchk.length; i++) delchk.checked = false; } </script> <script language="JavaScript"> function loadPage(list) { location.href=list.options[list.selectedIndex].value } </script> <?php mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("chat") or die(mysql_error()); if (isset($_POST['del'])) { for ($count = 0; $count < count($_POST["delchk"]); $count++) { $delete = $_POST["delchk"][$count]; $query = "DELETE FROM members_shouts WHERE id = '$delete'"; $result = mysql_query($query); if (!$result) { die("Error deleting accounts! Query: $query<br />Error: " . mysql_error()); } } } $data = mysql_query("SELECT * FROM `members_shouts`") or die(mysql_error()); $rows = mysql_num_rows($data); $page_rows = $_GET["limit"]; if ($page_rows == '') { // no double quotes (int) $page_rows = 5; } elseif ($page_rows == 'all') { $page_rows = $rows; } else { $page_rows = $_GET['limit']; /* validate this */ } if (!isset($_GET['pagenum'])) { $page = 1; } else { $page = (int) $_GET['pagenum']; } ?> <?php $max_pages = ceil($rows / $page_rows); $last = ceil($rows / $page_rows); $pagenum = ($page && $page > 0 && $page <= $last) ? $page : 1; $max = 'limit ' . ($pagenum - 1) * $page_rows . ',' . $page_rows; $data_p = mysql_query("SELECT * FROM members_shouts $max") or die(mysql_error()); ?> <?php $result = mysql_query("SELECT * FROM members_shouts"); if (mysql_num_rows($result) > 0) { ?> <span style="float: left;margin-left: 2px;"> <form> <select name="file" size="1" onchange="loadPage(this.form.elements[0])" target="_parent._top"> <option value="" <?php if ($_GET['limit'] == 0) { echo 'selected'; } ?>>Select Limit</option> <option value="?limit=9" <?php if ($_GET['limit'] == 9) { echo 'selected'; } ?>>9</option> <option value="?limit=15" <?php if ($_GET['limit'] == 15) { echo 'selected'; } ?>>15</option> <option value="?limit=30" <?php if ($_GET['limit'] == 30) { echo 'selected'; } ?>>30</option> <option value="?limit=all" <?php if ($_GET['limit'] == 'all') { echo 'selected'; } ?>>All</option> </select> </form> </span> <span style="float: right;margin-top: 2px;margin-right: 2px;"> <center> <?php if ($pagenum == 1) { } else { echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1&limit={$_GET['limit']}'>First</a> "; echo " | "; echo " "; $previous = $pagenum - 1; $current = $pagenum; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous&limit={$_GET['limit']}'>$previous</a> "; echo " | "; } echo "$pagenum"; if ($pagenum == $last || $last == 0) { } else { $next = $pagenum + 1; echo " | "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next&limit={$_GET['limit']}'>$next</a> "; echo " "; echo " | "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last&limit={$_GET['limit']}'>Last</a> "; } ?> </center> </span> <style type="text/css"> .clear2 { clear:both; height:0px; overflow:hidden; } </style> <div class="clear2"></div> <hr> <?php echo "<table class=\"gridtable\"> <thead> <tr> <th align=\"center\" scope=\"col\">user</th> <th align=\"center\" scope=\"col\">message</th> <th align=\"center\" scope=\"col\">when</th> <th align=\"center\" scope=\"col\">Delete?</th> </tr> </thead> <tbody>"; echo "<form name = 'myform' action='' method='post'>"; ?> <?php while ($info = mysql_fetch_array($data_p)) { echo "<tr align=\"center\">"; echo "<td class=\"valid\" >" . $info['user'] . "</td>"; echo "<td class=\"valid\" >" . $info['message'] . "</td>"; echo "<td>" . $info['when'] . "</td>"; echo '<td><input type="checkbox" id="delchk" name="delchk[]" value="' . $info['id'] . '" /></td>'; echo "</tr>"; } echo "</tbody>"; echo "</table>"; echo "<hr>"; echo "<input type='submit' name = 'del' value='Delete Selected'></form>"; echo "<input type='button' onclick='checkall(document.myform[\"delchk\"]);' value='Select All'>"; echo "<input type='button' onclick='uncheckall(document.myform[\"delchk\"]);' value='Deselect All'>"; echo "<hr>"; ?> <?php } else { // No rows were found ... echo '<center>No logged accounts.</center><hr>'; } ?> </hr> Im getting these errors and cant figure out at all how to fix them. the reason is, is that you can set the limit of rows to show on one page, and that is set by the variable limit it is used in 'localhost/admin?limit=5' That is 5 rows per page. There is also one called 'localhost/admin?limit=all' that is to show all the rows in one page. Im getting the errors: Code: [Select] Notice: Undefined index: limit in C:\Program Files (x86)\EasyPHP5.2.10\www\admin.php on line 176 Notice: Undefined index: limit in C:\Program Files (x86)\EasyPHP5.2.10\www\admin.php on line 179 Notice: Undefined index: limit in C:\Program Files (x86)\EasyPHP5.2.10\www\admin.php on line 90 Notice: Undefined index: limit in C:\Program Files (x86)\EasyPHP5.2.10\www\admin.php on line 130 Notice: Undefined index: limit in C:\Program Files (x86)\EasyPHP5.2.10\www\admin.php on line 135 Notice: Undefined index: limit in C:\Program Files (x86)\EasyPHP5.2.10\www\admin.php on line 140 Notice: Undefined index: limit in C:\Program Files (x86)\EasyPHP5.2.10\www\admin.php on line 145 Notice: Undefined index: limit in C:\Program Files (x86)\EasyPHP5.2.10\www\admin.php on line 150 I would be glad if someone could help me out by showing me how to set the limit when there is no GET used in the url.[/i] Unless buffer overflows or breaking out of code to perform a new command are problems that have been solved.... I am trying to figure out the proper PHP method for setting a boundary on a variable within a script. I have this variable $name which is fed a value from $_POST['name'] from a form field. Now this form field is limited in the HTML to accept only 20 characters, but someone could easily edit the form or outgoing post data. So I want to know how to limit the variable size in the script. In other languages it could be something like this: var name(20). So how do I do that in PHP? Hi, I have some code which displays my blog post in a foreach loop, and I want to add some social sharing code(FB like button, share on Twitter etc.), but the problem is the way I have my code now, creates 3 instances of the sharing buttons, but if you like one post, all three are liked and any thing you do affects all of the blog post. How can I fix this? <?php include ("includes/includes.php"); $blogPosts = GetBlogPosts(); foreach ($blogPosts as $post) { echo "<div class='post'>"; echo "<h2>" . $post->title . "</h2>"; echo "<p class='postnote'>" . $post->post . "</p"; echo "<span class='footer'>Posted By: " . $post->author . "</span>"; echo "<span class='footer'>Posted On: " . $post->datePosted . "</span>"; echo "<span class='footer'>Tags: " . $post->tags . "</span>"; echo ' <div class="addthis_toolbox addthis_default_style "> <a class="addthis_button_facebook_like" fb:like:layout="button_count"></a> <a class="addthis_button_tweet"></a> <a class="addthis_counter addthis_pill_style"></a> </div> <script type="text/javascript">var addthis_config = {"data_track_clickback":true};</script> <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=webguync"></script>'; echo "</div>"; } ?> i dont get whats wrong i does not add to the db Code: [Select] <?php if($_POST['submitbtn']){ require "scripts/connect.php"; $title = mysql_real_escape_string($_POST['title']); $by = mysql_real_escape_string($_POST['by']); $body = mysql_real_escape_string($_POST['body']); if ($title && $by && $body){ $query = mysql_query("INSERT INTO news (title, by, body)VALUES('$title', '$by', '$body')"); echo "ADD SUCCESFULLY!"; }else $msg = "<font color=red>YOU DID NOT FILL ALL OF THEM IN!</font>"; } ?> Hi, Is it possible to add PHP code into a TPL file? Ive tried adding my code in as standard PHP and also tried it with the {php}.....{/php} tags but it still doesnt work. Any help appreciated! Thanks Tom Hi, I am using Mouseflow analytics in a phpbb forum. In my specific application, I need to add their application's javascript code inside php code. How do I properly add Javascript code inside a php code. Thanks This is how I would add it to an html file <script type="text/javascript"> var _mfq = _mfq || []; (function () { var mf = document.createElement("script"); mf.type = "text/javascript"; mf.async = true; mf.src = "//cdn.mouseflow.com/projects/b22343cd9-0049-4443-8326-954444462d6515.js"; document.getElementsByTagName("head")[0].appendChild(mf); })(); </script> This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=354302.0 Hello, Below is my existing code for my web site visitor to fill out the form... they see a thank you html page.... and I get the info inserted into my database.... and I get an e-mail with all their details, even their date of registration. From what I have seen so far, EVERYTHING WORKS SUCCESSFULLY. HOWEVER, I would like to have the web site visitors details that they filled out ALSO SENT BACK to the web site visitor as a confirmation... say that this is a confirmation of the form they previously filled out. How do I accomplish this based off of my existing code here? I also would like my thank you.html code at the bottom of my current php code to be called in from a SEPARATE REDIRECT thankyou.php page after a successful form entry. I know that ALL headers must be IMMEDIATELY taken cared of upon entering any php page. This is what i used ***** header("Location: thankyou.php");******* Now I know that this is the correct code to make this happen but i do not know how to get this to work with my present code here. How do put the header location: thank you.php code in my EXISTING PHP page to make this all work right? thanks mrjap1 Code: [Select] ====================== HTML ========================== <?php require_once("db_connection.php");?> <!DOCTYPE HTML> <html lang="en"> <head> <meta charset="UTF-8"> <title>HTML form for insert users</title> <style type="text/css"> p { margin:0; padding:0; font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#633; font-weight:bold; } legend { font-family:Arial, Helvetica, sans-serif; font-size:15px; color:#3F6; font-weight:bold; } #form_container { background:#F7F; margin: 50px auto 50px auto; border: 1px solid #F00; padding:10px; width:285px; height:150px; } input { margin-bottom:5px; } body { background-color: #033; } </style> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <?php if (isset($_POST['submit'])) { // Handle the form. $message = NULL; // Create an empty new variable. // Check for a first name. if (empty($_POST['first_name'])) { $first_name = FALSE; $message .= '<p>You forgot to enter your first name... its Required!</p>'; } else { $first_name = ($_POST['first_name']); } // Check for a last name. if (empty($_POST['last_name'])) { $last_name = FALSE; $message .= '<p>You forgot to enter your last name... its Required!</p>'; } else { $last_name = ($_POST['last_name']); } // Check for an email address. if (empty($_POST['email'])) { $email = FALSE; $message .= '<p>You forgot to enter your email address... its Required!</p>'; } else { $email = ($_POST['email']); } } ?> <div id="form_container"> <form action="form_proceessed201XXX.php" method="post"> <input type="hidden" name="submit" value="true" /> <fieldset> <legend>My Data Feilds</legend> <!-- ### FIRST NAME ### --> <p> <label>First Name:</label><input name="first_name" type="text" value="<?php if(isset($_POST['first_name'])) echo $_POST['first_name']; ?>" id="first_name" size="15" maxlength="30"> </p> <!-- ### LAST NAME ### --> <p> <label>Last Name:</label><input name="last_name" type="text" value="<?php if(isset($_POST['last_name'])) echo $_POST['last_name']; ?>" id="last_name" size="15" maxlength="30"> </p> <!-- ### EMAIL ### --> <p> <label>E-mail:</label><input name="email" type="text" value="<?php if(isset($_POST['email'])) echo $_POST['email']; ?>" id="email" size="15" maxlength="30"> </p> <!-- ### SUBMIT BUTTON ### --> <p style="text-align:center"> <input type="submit" name="submit" value="SEND MY INFO PLEASE" /> </p> </fieldset> </form> </div> </body> </html> ====================== PHP ========================== <?php // ALL THE SUBJECT and EMAIL VARIABLES $emailSubject = 'MY TEST EMAIL SCRIPTING!!! '; $webMaster = 'myemail@gmail.com'; // GATHERING the FORM DATA VARIABLES $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $email = $_POST['email']; $registration_date = $_POST['registration_date']; $date = date ("l, F jS, Y"); $time = date ("h:i A"); $body = <<<EOD <br /><hr><br /> <strong>First Name:</strong> $first_name <br /> <strong>Last Name: </strong>$last_name <br /> <strong>Email:</strong> $email <br /> <strong>Registration Date:</strong> $date at $time <br /> EOD; // THIS SHOW ALL E-MAILED DATA, ONCE IN THE E-MAILBOX AS READABLE HTML $headers = "From: $email\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); // THE RESULTS OF THE FORM RENDERED AS PURE HTML $theResults = <<<EOD <!DOCTYPE HTML> <html lang="en"> <head> <style type="text/css"> body { font-family:Arial, Helvetica, sans-serif; font-size:11px; font-weight:bold; } #thankyou_block { width: 400px; height: 250px; text-align:center; border: 1px solid #666; padding: 5px; background-color: #0CF; border-radius:8px; -webkit-border-radius:8px; -moz-border-radius:8px; -opera-border-radius:8px; -khtml-border-radius:8px; box-shadow:0px 0px 10px #000; -webkit-box-shadow: 0px 0px 10px #000; -moz-box-shadow: 0px 0px 10px #000; -o-box-shadow: 0px 0px 10px #000; margin: 25px auto; } p { font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 18px; letter-spacing:1px; color: #333; } </style> <meta charset="UTF-8"> <title>THANK YOU!!!</title> </head> <body> <div id="thankyou_block"> <br><br><br> <h1>CONGRATULATIONS!!</h1> <h2>YOUR FORM HAS BEEN PROCESSED!!!</h2> <p>You are now registered in our Database...<br> we will get back to you very shortly.<br> Please have a very wondeful day.</p> </div> </body> </html> EOD; echo "$theResults"; ?> I have a field gmap the data would be a variation of this, the gmap data to place the map on the site. The rest of the string is in my code because I want to size the iframe etc. Whean I use an input form to update this field using Null data and using a simple text line like yellow, the script works, when I try and add data as below I get a 403 error, how can I resolve this? https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3573.197380400117!2d28.465316315605516!3d-26.41710627907957!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x1e94d9c942963de9%3A0xc560ec1cd5d52b74!2sArrie%20Nel%20Nigel%20Pharmacy!5e0!3m2!1sen!2sza!4v1603786030983!5m2!1sen!2sza>
Code Hi. I currently have php java to get my database results and limit the amount of data shown by a given value. The js includes buttons to go forward or backward in the database. Everything is all fine and dandy except I'm trying to add a very simple search for the user as well. I want the user to be able to select either "firstname" or "lastname" to search through the database and display the resulting rows based of the first three characters entered into the search criteria. I'm not sure where to start on this... Do I have to add something the js (I'm not very familiar with js), or should I add mysql_query's in the php linked file? Current Page Code: Link To Current Page Test Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Ness Physiotherapy and Sports Injury Clinic Web site - Site Map</title> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <meta name="description" content="Ness Physiotherapy and Sports Injury Clinic Our mission is to provide quality, evidenced based service in a safe, friendly, professional environment." /> <meta name="keywords" content="pain,rehabilitation,rehab,exercise,manipulation,musculoskeletal,pain,management,massage therapy,physiotherapy,sports injury,injury,injured,chronic pain,quality care,quality life,muscle balance,spinal fitness assessment, BMR PT, CAFCI, RMT" /> <!--Ness Physiotherapy and Sports Injury Clinic is owned by Sean Springer, Tamara Silvari and Charles Dirks. --> <meta name="language" content="EN" /> <meta name="copyright" content="Ness Physiotherapy and Sports Injury Clinic" /> <meta name="robots" content="ALL" /> <meta name="document-classification" content="Health" /> <meta name="document-classification" content="Health" /> <meta name="document-rights" content="Copyrighted Work" /> <meta name="document-type" content="Public" /> <meta name="document-rating" content="General" /> <meta name="document-distribution" content="Global" /> <link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" /> <script type="text/javascript" src="../scripts/preloadimages.js"></script> <script type="text/javascript" src="../scripts/p7exp.js"></script> <script type="text/javascript" src="../scripts/formajax.js"></script> <!--[if lte IE 7]> <style> #menuwrapper, #p7menubar ul a {height: 1%;} a:active {width: auto;} </style> <![endif]--> <!--[if IE 5]> <style type="text/css"> /* place css box model fixes for IE 5* in this conditional comment */ .twoColFixRtHdr #sidebar1 { width: 220px; } </style> <![endif][if IE]> <style type="text/css"> /* place css fixes for all versions of IE in this conditional comment */ .twoColFixRtHdr #sidebar1 { padding-top: 30px; } .twoColFixRtHdr #mainContent { zoom: 1; } /* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */ </style> <![endif]--> <link href="../css/p7exp.css" rel="stylesheet" type="text/css" /> <link href="../css/basiclayout.css" rel="stylesheet" type="text/css" /> <link href="../css/general.css" rel="stylesheet" type="text/css" /> <link rel="stylesheet" type="text/css" href="../css/form_member_admin.css"/> </head> <body class="twoColFixRtHdr" onload="ajaxFunction('fw')"> <div id="container2"> <!-- Header Secion edit header.php if needed--> <?php require("../header.php"); ?> <div id="BasCon"> <form id="myForm" action="ajaxFunction(this.form); return false"> <div> <input type="hidden" name="st" value="0" > </input> </div> <table id="tbl_search"> <tr> <td colspan="5"><b>MEMBER LIST</b></td> </tr> <tr> <td><input type="button" id="back" value="Prev" onclick="ajaxFunction('bk'); return false" /></td> <td align="right"><input type="button" value="Next" id="fwd" onclick="ajaxFunction('fw'); return false" /></td> </tr> <tr> <td colspan="2"><div id="txtHint"><b>Records will be displayed here</b></div></td> </tr> </table> <div class="formdiv"> <label for="searchby">Search By:</label> <?php //get databast access file require "../dbConfigtest.php"; $query = "SELECT firstname,lastname FROM $usertable"; $result = mysql_query($query) or die(mysql_error()); ?> <select size="1" name="searchby" class="searchby"> <?php $i = 0; while ($i < mysql_num_fields($result)){ $fieldname = mysql_field_name($result, $i); echo '<option value="'.$fieldname.'">'.$fieldname.'</option>'; $i++; } ?> </select> <label for="newsearch">Search Value:</label> <input name='newsearch' type='text' value='' maxlength="32" /> <p> </p> <input class="button" type="submit" value="Search" name="search" /> </div><!--End Div formdiv--> <p> </p> <p> </p> </form> </div> <!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --> <br class="clearfloat" /> <div id="footer_abv_2"></div> <!-- end #footer abv --> <!-- Footer Secion edit footer.php if needed--> <?php require("../footer.php"); ?> </div> <!-- end #container2 --> </body> </html> PHP Code from "pagelisting.php" which is called from the java. <? //get databast access file include "../dbConfigtest.php"; //////////////////////////////// Main Code sarts ///////////////////////////////////////////// $endrecord=$_GET['endrecord'];// To take care global variable if OFF if(strlen($endrecord) > 0 and !is_numeric($endrecord)){ echo "Data Error"; exit; } $limit=25;// Number of records per page $nume=mysql_num_rows(mysql_query("select * from $usertable")); //echo "endrecord=$endrecord limit=$limit "; if($endrecord < $limit) {$endrecord = 0;} switch($_GET['direction']) { case "fw": $eu = $endrecord ; break; case "bk": $eu = $endrecord - 2*$limit; break; default: echo "Data Error"; exit; break; } if($eu < 0){$eu=0;} $endrecord =$eu+$limit; $t=mysql_query("select * from $usertable limit $eu,$limit"); $str= "{ \"data\" : ["; while($nt=mysql_fetch_array($t)){ $str=$str."{\"id\" : \"$nt[id]\", \"firstname\" : \"$nt[firstname]\", \"lastname\" : \"$nt[lastname]\", \"email\" : \"$nt[email]\", \"enewsletter\" : \"$nt[enewsletter]\"},"; //$str=$str."{\"myclass\" : \"$nt[class]\"},"; } $str=substr($str,0,(strLen($str)-1)); if(($endrecord) < $nume ){$end="yes";} else{$end="no";} if(($endrecord) > $limit ){$startrecord="yes";} else{$startrecord="no";} $str=$str."],\"value\" : [{\"endrecord\" : $endrecord,\"limit\" : $limit,\"end\" : \"$end\",\"startrecord\" : \"$startrecord\"}]}"; echo $str; //echo json_encode($str); ///////////////////////////////////////////////////////////////////////////////////////////// ?> Current js Code: Code: [Select] function ajaxFunction(val) { //document.writeln(val) var httpxml; try { // Firefox, Opera 8.0+, Safari httpxml=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { httpxml=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { httpxml=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("Your browser does not support AJAX!"); return false; } } } function stateChanged() { if(httpxml.readyState==4) { var myObject = eval('(' + httpxml.responseText + ')'); var str="<table><tr><th>LINK</th><th>ID</th><th>FirstName</th><th>LastName</th><th>Email</th></tr>"; for(i=0;i<myObject.data.length;i++) { //var sPath = window.location.pathname; //var sPath = sPath.substring(sPath.lastIndexOf('/') + 1); var sPath = "testing/member_update_test.php"; var site_link = "www.nessphysiotherapy.com/"; var urlLink = site_link + sPath + "?id=" + myObject.data[i].id; var site_title = "EDIT"; str = str + "<tr><td>" + "<a href=\"http:\/\/" + urlLink + "\" title=\"site_title\">" +site_title + "<\/a>" + "<td>" + myObject.data[i].id + "</td><td>" + myObject.data[i].firstname + "</td><td>" + myObject.data[i].lastname + "</td><td>" + myObject.data[i].email + "</td></tr>" } var endrecord=myObject.value[0].endrecord document.forms.myForm.st.value=endrecord; if(myObject.value[0].end =="yes"){ document.getElementById("fwd").style.display='inline'; }else{document.getElementById("fwd").style.display='none';} if(myObject.value[0].startrecord =="yes"){ document.getElementById("back").style.display='inline'; }else{document.getElementById("back").style.display='none';} str = str + "</table>" document.getElementById("txtHint").innerHTML=str; } } var url="../scripts/pagelisting.php"; var myendrecord=document.forms.myForm.st.value; url=url+"?endrecord="+myendrecord; url=url+"&direction="+val; url=url+"&sid="+Math.random(); //alert(url) httpxml.onreadystatechange=stateChanged; httpxml.open("GET",url,true); httpxml.send(null); document.getElementById("txtHint").innerHTML="Please Wait...."; } Hi There, I want to add a picture to an existing user. The sql looks like: CREATE TABLE `klanten` ( `id` int(4) unsigned NOT NULL auto_increment, `username` varchar(32) NOT NULL, `password` varchar(32) NOT NULL, `level` int(4) default '1', `filename` varchar(255) not null, `mime_type` varchar(255) not null, `file_size` int not null, `file_data` mediumblob not null, primary key (id), index (filename) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; id, username, password and level are allready filled in. Now i need some code to go with <form method="post" action="process.php" enctype="multipart/form-data"> <div> <input type="file" name="image" /> <input type="submit" value="Upload Image" /> </div> </form> process.php: <?php require_once 'database.php'; function assertValidUpload($code) { if ($code == UPLOAD_ERR_OK) { return; } switch ($code) { case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: $msg = 'Image is too large'; break; case UPLOAD_ERR_PARTIAL: $msg = 'Image was only partially uploaded'; break; case UPLOAD_ERR_NO_FILE: $msg = 'No image was uploaded'; break; case UPLOAD_ERR_NO_TMP_DIR: $msg = 'Upload folder not found'; break; case UPLOAD_ERR_CANT_WRITE: $msg = 'Unable to write uploaded file'; break; case UPLOAD_ERR_EXTENSION: $msg = 'Upload failed due to extension'; break; default: $msg = 'Unknown error'; } throw new Exception($msg); } $errors = array(); try { if (!array_key_exists('image', $_FILES)) { throw new Exception('Image not found in uploaded data'); } $image = $_FILES['image']; // ensure the file was successfully uploaded assertValidUpload($image['error']); if (!is_uploaded_file($image['tmp_name'])) { throw new Exception('File is not an uploaded file'); } $info = getImageSize($image['tmp_name']); if (!$info) { throw new Exception('File is not an image'); } } catch (Exception $ex) { $errors[] = $ex->getMessage(); } if (count($errors) == 0) { // no errors, so insert the image $query = sprintf( "insert into klanten (filename, mime_type, file_size, file_data) values ('%s', '%s', %d, '%s')", mysql_real_escape_string($image['name']), mysql_real_escape_string($info['mime']), $image['size'], mysql_real_escape_string( file_get_contents($image['tmp_name']) ) ); mysql_query($query, $con); $id = (int) mysql_insert_id($con); // finally, redirect the user to view the new image header('Location: view.php?id=' . $id); exit; } ?> <html> <head> <title>Error</title> </head> <body> <div> <p> The following errors occurred: </p> <ul> <?php foreach ($errors as $error) { ?> <li> <?php echo htmlSpecialChars($error) ?> </li> <?php } ?> </ul> <p> <a href="upload.php">Try again</a> </p> </div> </body> </html> to add to an existing user. Can somebody help me here? Best regards, Martijn When I asked about adding a watermark to a video, this was suggested: "when scaling it, I'd do h/5:w/5 (of the source video), then position would be w/20 (5% from the left) and h-h/3 (75% of the way down) When I asked about adding a watermark to a video, this was suggested: "when scaling it, I'd do h/5:w/5 (of the source video), then position would be w/20 (5% from the left) and h-h/3 (75% of the way down)" I'd like to try that, but I don't know how to integrate that into my existing working code: $ffmpegCommand =''.$ffmpeg_b.' -y -i '.$video_file_full_path.' -i '.$watermark_image_full_path.' -filter_complex "scale=426:-2, overlay=10:10, " -vcodec libx264 -preset '.$pt->config->convert_speed.' -crf 26 '.$video_output_full_path_240.' 2>&1'; I've looked at the ffmpeg documentation, but need additional assistance. any help is appreciated
Hi Guy's, I've recoded allot with 3 scripts i had to my disposal. I've fixed 95% and i'm proud allready, but stuck at the following code. It does'nt execute any errors and refreshes the page without uploading the picture to the desired folder. Also folders are'nt created. I've turned on error reporting at level -1, but those errors i fixed. Can you please help me out? note: this is a partial code of a tiny usermanagement 'cms'. Code: [Select] <?php //action: add picture for user ----------------------------------------------------------------------------- if (isset($_GET['editpic']) && isset($_GET['id'])) { $id = (int) $_GET['id']; if ($id == 0) { die("Invalid ID provided."); } $sql = "SELECT username FROM `users` WHERE `id`='".$_GET['id']."'"; $res = mysql_query($sql) or die(mysql_error()); //execution when completed the add picture form and pressed submit button --------------------- if (isset($_POST['addPic'])) { $row = mysql_fetch_assoc($res); $title = protect($_POST['title']); if(!$title) { echo "<script language=\"Javascript\" type=\"text/javascript\"> alert(\"You must choose a title for your picture!\") document.location.href='profilecp.php'</script>"; } $target = $row['username']; if(!is_dir($target)) @mkdir($target); $target = $target . '/pics'; if(!is_dir($target)) @mkdir($target); $target = $target."/".basename($_FILES['pics']['name']) ; $size = $_FILES['pics']['size']; $pic = $_FILES['pics']['name']; $type = $_FILES['pics']['type']; $sql2= "INSERT INTO `user_photos` (`profile_id`,`title`,`size`,`type`,`reference`) VALUES ('".$_GET['id']."','$title','$size','$type','$pic'); "; $res2 = mysql_query($sql2) or die(mysql_error()); if(move_uploaded_file($_FILES['pics']['tmp_name'], $target)) { echo "<script language=\"Javascript\" type=\"text/javascript\"> alert(\"Your picture has been uploaded\") document.location.href='profilecp.php'</script>"; } else { echo "<script language=\"Javascript\" type=\"text/javascript\"> alert(\"There was an error, try again\") document.location.href='profilecp.php'</script>"; } $target2 = $row['username']; $target2 = $target2 . '/pics'; $target2 = $target2 . '/thumbs'; if(!is_dir($target2)) @mkdir($target2); $target2 = $target2."/".basename($_FILES['pics']['name']) ; createthumb($target,$target2,150,150); } <!-----------------------ADD PICTURES-----------------------//--> <div class="dividerp"> <form enctype="multipart/form-data" method="POST" action="administrator.php?editpic&id=<?php echo $id;?>"><br/> <strong>Upload Pictures</strong><br/><br/> <div class="formElm"> <label for="title">Title</label> <input id="title" type="text" name="title" maxlength="32"><br/> </div> <div class="formElm"> <label for="file">File</label> <input id="file" type="file" name="pics" maxlength="255"><br/> </div> <input type="submit" name="picAdd" value="Add"> </form> </div> </div> </body> </html> }?> and the mysql tables: Code: [Select] CREATE TABLE `users` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , `first` VARCHAR( 32 ) NOT NULL , `last` VARCHAR( 32 ) NOT NULL , `username` VARCHAR(32) NOT NULL, `password` VARCHAR(255) NOT NULL, `email` VARCHAR(255) NOT NULL, `about` TEXT NOT NULL, `level` int(4) default '1' ) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=latin1; Code: [Select] CREATE TABLE `user_photos` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `profile_id` INT NOT NULL , `title` VARCHAR( 128 ) NOT NULL , `size` INT NOT NULL , `type` VARCHAR( 128 ) NOT NULL , `reference` VARCHAR( 255 ) NOT NULL ) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=latin1; Best regards, Martijn Hi, I'm trying to add encryption to a signup for a college assignment, but find that after adding the sha1 and salt encryption the code does not work. The code worked before adding the encryption. Since adding the encryption I've also adding the corresponding fields for username and password into the sql database and double checked, and triple checked all the php, html form and MySQL tables and fields, but don't see any thing wrong. Can anybody else see any immediate problems with the code snippet below? If so, can you please let me know? session_start(); $salt = 'The sky is blue and all the trees are green'; $data = array_map('mysql_escape_string', $_POST); $password = sha1($data['password'].$salt); $query = " INSERT INTO customers ( first_name, last_name, address, mobile, email, username, password ) VALUES ( '{$data['first_name']}', '{$data['last_name']}', '{$data['address']}', '{$data['mobile']}', '{$data['email']}' '{$data['username']}', '$password' ) "; if(mysql_query($query)) { echo 'Your login details have been saved.'; } else { echo 'Your login details have not been saved.<br>'; echo 'Please try again later.'; } Thanks. All I am trying to do is add a record on a page without the page refreshing. For that ajax is used. Here is the code.
It does not add the record to mysql table. Can anyone tell me what I am doing wrong?
record.php
<!DOCTYPE HTML> <html lang="en"> <head> <script type="text/javascript" src="js/jquery-1.11.0.min.js"></script> <script type="text/javascript" > $(function() { $(".submit_button").click(function() { var textcontent = $("#content").val(); var name = $("#name").val(); var dataString = 'content='+ textcontent + '&name='+name; if(textcontent=='') { alert("Enter some text.."); $("#content").focus(); } else { $("#flash").show(); $("#flash").fadeIn(400).html('<span class="load">Loading..</span>'); $.ajax({ type: "POST", url: "action.php", data: dataString, cache: true, success: function(html){ $("#show").after(html); document.getElementById('content').value=''; $("#flash").hide(); $("#content").focus(); } }); } return false; }); }); </script> </head> <body> <?php $record_id = $_GET['id']; // getting ID of current page record ?> <form action="" method="post" enctype="multipart/form-data"> <div class="field"> <label for="title">Name *</label> <input type="text" name="name" id="name" value="" maxlength="20" placeholder="Your name"> </div> <div class="field"> <label for="content">content *</label> <textarea id="content" name="content" maxlength="500" placeholder="Details..."></textarea> </div> <input type="submit" name="submit" value="submit" class="submit_button"> </form> <div id="flash"></div> <div id="show"></div> </body> </html>action.php if(isset($_POST['submit'])) { if(empty($_POST['name']) || empty($_POST['content'])) { $error = 'Please fill in the required fields!'; } else { try { $name = trim($_POST['name']); $content = trim($_POST['content']); $stmt = $db->prepare("INSERT INTO records(record_id, name, content) VALUES(:recordid, :name, :content"); $stmt->execute(array( 'recordid' => $record_id, 'name' => $name, 'content' => $content )); if(!$stmt){ $error = 'Please fill in the required fields.'; } else { $success = 'Your post has been submitted.'; } } catch(Exception $e) { die($e->getMessage()); } } } im using the floowing code to pull all alerts from the database. as you can see i have 3 types of alertsd. Profile alerts, forum alerts and topic alerts. They are sorted and placed on the screen under their respective header. However i want to limit it so it only displays 4 of each type of alert. I cant use LIMIT in the query because that would limit all alerts meaning only 4 alerts in total would show up and i just need to limit each alert type. any ideas? $alert_query = $link->query("SELECT a.a_aid, a.a_alert_type, a.a_time_alerted, a.a_fid, a.a_poster, a_alert_read, a.a_tid, c.f_name as cat_name, f.f_fid, f.f_name, t.t_name, u.u_avatar, u.u_avatar_cropped FROM ".TBL_PREFIX."alerts as a LEFT JOIN ".TBL_PREFIX."forums as f ON (f.f_fid = a.a_fid) LEFT JOIN ".TBL_PREFIX."topics as t ON (t.t_tid = a.a_tid) LEFT JOIN ".TBL_PREFIX."forums as c ON (c.f_fid = f.p_id) LEFT JOIN ".TBL_PREFIX."users as u ON (u.u_username = a.a_poster) WHERE a.a_user_name = '$user_name' ORDER BY a_time_alerted ") or die(print_link_error()); $alert_info = $alert_query->fetchAll(); $pm_alert_list = ''; $num_pm_alerts = 0; $num_forum_alerts = 0; $num_topic_alerts = 0; foreach($alert_info as $key => $val) { $alert_info[$key]['a_alert_read'] == 0 ? $color = '#f5dfaf' : $color = '#f4f4f4'; // if alert is a profile message alert if($alert_info[$key]['a_alert_type'] == 1) { $pm_alert_list .= '<dd style="background:'.$color.';" class="alert" id="alert-'.$alert_info[$key]['a_aid'].'"><p class="alert_intro">'; $pm_alert_list .= '<input type="checkbox" class="pm_checkbox" id="pm_checkbox-'.$alert_info[$key]['a_aid'].'" />'.profile_link($alert_info[$key]['a_poster']).' posted on your wall</p>'; $pm_alert_list .= '<p class="alert_time"> on '.asf_date($alert_info[$key]['a_time_alerted'],'full').'</p>'; $pm_alert_list .= '</dd>'; $num_pm_alerts++; } if($alert_info[$key]['a_alert_type'] == 2) { $forum_alert_list .= '<dd style="background:'.$color.';" class="alert" id="alert-'.$alert_info[$key]['a_aid'].'"><p class="alert_intro">'; $forum_alert_list .= '<input type="checkbox" class="pm_checkbox" id="pm_checkbox-'.$alert_info[$key]['a_aid'].'" /><strong><a href="'.$config['asf_root'].'category/'.create_url($alert_info[$key]['cat_name']).'/forum/'.create_url($alert_info[$key]['f_name']).'">'.$alert_info[$key]['f_name'].'</a></strong> has a new topic</p>'; $forum_alert_list .= '<p class="alert_time"> '.asf_date($alert_info[$key]['a_time_alerted'],'full').'</p>'; $forum_alert_list .= '</dd>'; $num_forum_alerts++; } if($alert_info[$key]['a_alert_type'] == 3) { $topic_alert_list .= '<dd style="background:'.$color.';" class="alert" id="alert-'.$alert_info[$key]['a_aid'].'"><p class="alert_intro">'; $topic_alert_list .= '<input type="checkbox" class="pm_checkbox" id="pm_checkbox-'.$alert_info[$key]['a_aid'].'" /><strong><a href="'.$config['asf_root'].'category/'.create_url($alert_info[$key]['cat_name']).'/forum/'.create_url($alert_info[$key]['f_name']).'/topic/'.create_url($alert_info[$key]['t_name']).'">'.$alert_info[$key]['t_name'].'</a></strong> has a new post</p>'; $topic_alert_list .= '<p class="alert_time"> '.asf_date($alert_info[$key]['a_time_alerted'],'full').'</p>'; $topic_alert_list .= '</dd>'; $num_topic_alerts++; } } This code works fine without the LIMIT 5, but it lists all the results. With the LIMIT Code: [Select] $query = 'SELECT * FROM wp_playerRank WHERE year="2011" LIMIT 5 ORDER BY rankClass ASC'; $results = mysql_query($query); while($line = mysql_fetch_assoc($results)) { Here is the error I'm getting: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/jwrbloom/public_html/resources/players/rank2011_top5.php on line 26 Hello friends, if i've database table (mytable) has the following ids 1 2 3 4 5 6 and i want to get it with limit the first (1 to 3 ) only Code: [Select] $sql ="select * from mytable LIMIT 3"; this will show the first 3 (1,2,3) how then i write code that shows which is after 3 so it shows me 4 5 6 and if there any way i can say Code: [Select] $sql ="select * from mytable LIMIT (first half of ids)"; and (shows 1,2,3..ect till half) Code: [Select] $sql ="select * from mytable LIMIT (second half of ids)"; will (shows 4,5,6...ect till end) thank you |