PHP - Limit Php Functionality
Similar TutorialsUnless 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 gents, This will be an easy one for you all! I have a sql select statement and everything functions fine as is, BUT I would like to give users more freedom. Using this sql statement the results only return if the user types the Botanical Name or Common Name of a particular plant exactly as it is spelled in the database: $sql = mysql_query("SELECT PlantID, CommonName FROM plants WHERE BotanicalName='$BotanicalName' OR CommonName='$CommonName' OR Use1='$Use' OR Use2='$Use' OR Use3='$Use' OR Use4='$Use' OR Use5='$Use' ORDER BY CommonName"); What if the user doesn't know the species of a plant and only it's genus or the user only knows Maple tree and not which particular one they are looking for: For example: Plant in Database = Brandywine Red Maple User Search would have to be exactly that "Brandywine Red Maple" for a result to return Ideally I would like the user to be able to type in "Maple" and ALL Maples return Let me know if you need more info hello, I am running php locally on my machine but it seems that when I try to call mail () function, I get error messages. I believe that I need to set up a mail server on my machine. Is that an accurate statement? whats the easiest way to do this? Is having OUTLOOK installed on the machine sufficient? I am a newbie trying to build a quiz system. I have all of the questions and answer choices in a mysql table. My code below selects the question and answers. They appear exactly how I want them to....but I'm stuck on the form functionality. I was trying to use something like this: Code: [Select] <input type='radio' name='Q1Choice' value='$answer1' /> I need to be able to insert the choice into my table. I know how to do the insert part but not sure how to take the radio choice as the insert data. Code: [Select] <? //Connect to database mysql_connect($host, $dbusername, $password); mysql_select_db($TxQuizdb); //Retrieve Quiz Questions $qquery = mysql_query("SELECT * FROM Module_1_Quiz"); while ($m1questions = mysql_fetch_array($qquery)) { echo "<table width=600 border=1><tr><td>"; echo $m1questions['Question']; echo "</td></tr><br><tr><td>"; echo $m1questions['Choice1']; echo "<br>"; echo $m1questions['Choice2']; echo "<br>"; echo $m1questions['Choice3']; echo "</td></tr></table>"; } thanks for any help. I am working on a REST application which is intended to be used with various CMS’s (Drupal, WordPress, etc). Each CMS installation passes a unique GUID in the header to identify the organization so that the organization's individual data is utilized. I’ve since realized I need some basic way to identify the individual user for at least two reasons: The API provides a help desk where individual users can ask questions and get responses (not real time). There is some need for user access/privileges (I suppose this could be CMS side if necessary).Instead of inputting users both into the API as well as the CMS, the organization should be responsible for entry only through the CMS. They will add users as appropriate for the given CMS and then another page on the CMS will list all the CMS users and provide a way to set whether they are authorized to access the API as well as their access level. The remaining of this post is kind of what I am thinking, but I am open to change. When the CMS gives a user access to the API for the first time, a cURL request is made to the API and a unique key is returned and the CMS will save it as being associated with the given user. Note sure if this should be an incrementing number on a per organization basis or another GUID, and if a GUID whether it should be passed along with the organization’s GUID or replace it. Also, not positive, but thinking that user data (name, email, etc) should not be given to the API as it might be difficult to keep them synchronized. If a user’s access level is changed on the CMS or their access is removed, the user’s GUID is passed to the API and the work is done on the API. If the user is removed, they are not deleted from the API’s database but just tagged as deleted. Before performing step 1, the CMS should first perform a query requesting all users who are tagged as deleted and is responsible to determine whether a new user should be added or an existing user should be reinstated. Alternatively, I can make the API responsible for doing so, but then it would need to have stored various data to identify whether the user was previously instated which might result in the synchronization issue I described in step 1.Any comments, potential pitfalls, or recommendations would be appreciated. My code about filterable audio searching, here how can i add Add-To-Cart functionality?
code : <?php //index.php include('database_connection.php'); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="description" content=""> <meta name="author" content=""> <title>Voice Repository</title> <script src="js/jquery-1.10.2.min.js"></script> <script src="js/jquery-ui.js"></script> <script src="js/bootstrap.min.js"></script> <link rel="stylesheet" href="css/bootstrap.min.css"> <link href = "css/jquery-ui.css" rel = "stylesheet"> <!-- Custom CSS --> <link href="css/style.css" rel="stylesheet"> </head> <body> <!-- Page Content --> <div class="container"> <div class="row"> <br /> <div class="col-md-12"> <h2 align="center">Voice Repository Bank</h2> </div> <div class="col-md-3"> <!-- Price --> <!-- <div class="list-group"> <h3>Price</h3> <input type="hidden" id="hidden_minimum_price" value="0" /> <input type="hidden" id="hidden_maximum_price" value="65000" /> <p id="price_show">1000 - 65000</p> <div id="price_range"></div> </div> --> <!-- Languages --> <div class="list-group"> <h3>Languages</h3> <?php $query = " SELECT DISTINCT(voice_languages) FROM voice_bank_data WHERE voice_status = '1' ORDER BY voice_languages DESC "; $statement = $connect->prepare($query); $statement->execute(); $result = $statement->fetchAll(); foreach($result as $row) { ?> <div class="list-group-item checkbox"> <label><input type="checkbox" class="common_selector languages" value="<?php echo $row['voice_languages']; ?>" > <?php echo $row['voice_languages']; ?> </label> </div> <?php } ?> </div> <!-- Genres --> <div class="list-group"> <h3>Genres</h3> <?php $query = " SELECT DISTINCT(voice_genres) FROM voice_bank_data WHERE voice_status = '1' ORDER BY voice_genres DESC "; $statement = $connect->prepare($query); $statement->execute(); $result = $statement->fetchAll(); foreach($result as $row) { ?> <div class="list-group-item checkbox"> <label><input type="checkbox" class="common_selector genres" value="<?php echo $row['voice_genres']; ?>" > <?php echo $row['voice_genres']; ?> </label> </div> <?php } ?> </div> <!-- Voice Modulation --> <div class="list-group"> <h3>Voice Modulation</h3> <?php $query = " SELECT DISTINCT(voice_voice_modulation) FROM voice_bank_data WHERE voice_status = '1' ORDER BY voice_voice_modulation DESC "; $statement = $connect->prepare($query); $statement->execute(); $result = $statement->fetchAll(); foreach($result as $row) { ?> <div class="list-group-item checkbox"> <label><input type="checkbox" class="common_selector voice_modulation" value="<?php echo $row['voice_voice_modulation']; ?>" > <?php echo $row['voice_voice_modulation']; ?> </label> </div> <?php } ?> </div> <!-- Gender --> <div class="list-group"> <h3>Gender</h3> <div style="height: 180px; overflow-y: auto; overflow-x: hidden;"> <?php $query = "SELECT DISTINCT(voice_gender) FROM voice_bank_data WHERE voice_status = '1' ORDER BY voice_id DESC"; $statement = $connect->prepare($query); $statement->execute(); $result = $statement->fetchAll(); foreach($result as $row) { ?> <div class="list-group-item checkbox"> <label><input type="checkbox" class="common_selector gender" value="<?php echo $row['voice_gender']; ?>" > <?php echo $row['voice_gender']; ?></label> </div> <?php } ?> </div> </div> <!-- Jingle Moods --> <div class="list-group"> <h3>Jingle Moods</h3> <?php $query = " SELECT DISTINCT(voice_jingle_moods) FROM voice_bank_data WHERE voice_status = '1' ORDER BY voice_jingle_moods DESC "; $statement = $connect->prepare($query); $statement->execute(); $result = $statement->fetchAll(); foreach($result as $row) { ?> <div class="list-group-item checkbox"> <label><input type="checkbox" class="common_selector jingle_moods" value="<?php echo $row['voice_jingle_moods']; ?>" > <?php echo $row['voice_jingle_moods']; ?> </label> </div> <?php } ?> </div> <!-- IVR --> <div class="list-group"> <h3>Ivr</h3> <?php $query = " SELECT DISTINCT(voice_ivr) FROM voice_bank_data WHERE voice_status = '1' ORDER BY voice_ivr DESC "; $statement = $connect->prepare($query); $statement->execute(); $result = $statement->fetchAll(); foreach($result as $row) { ?> <div class="list-group-item checkbox"> <label><input type="checkbox" class="common_selector ivr" value="<?php echo $row['voice_ivr']; ?>" > <?php echo $row['voice_ivr']; ?> </label> </div> <?php } ?> </div> </div> <div class="col-md-9"> <br /> <div class="row filter_data"> </div> </div> </div> </div> <style> #loading { text-align:center; background: url('loader.gif') no-repeat center; height: 150px; } </style> <script> $(document).ready(function(){ filter_data(); function filter_data() { $('.filter_data').html('<div id="loading" style="" ></div>'); var action = 'fetch_data'; // var minimum_price = $('#hidden_minimum_price').val(); // var maximum_price = $('#hidden_maximum_price').val(); var gender = get_filter('gender'); var genres = get_filter('genres'); var voice_modulation = get_filter('voice_modulation'); var languages = get_filter('languages'); var jingle_moods = get_filter('jingle_moods'); var ivr = get_filter('ivr'); $.ajax({ url:"fetch_data.php", method:"POST", data: { action:action, // minimum_price:minimum_price, // maximum_price:maximum_price, gender:gender, genres:genres, voice_modulation:voice_modulation, languages:languages, jingle_moods:jingle_moods, ivr:ivr }, success:function(data) { $('.filter_data').html(data); } }); } function get_filter(class_name) { var filter = []; $('.'+class_name+':checked').each(function(){ filter.push($(this).val()); }); return filter; } $('.common_selector').click(function(){ filter_data(); }); // $('#price_range').slider({ // range:true, // min:1000, // max:65000, // values:[1000, 65000], // step:500, // stop:function(event, ui) // { // $('#price_show').html(ui.values[0] + ' - ' + ui.values[1]); // $('#hidden_minimum_price').val(ui.values[0]); // $('#hidden_maximum_price').val(ui.values[1]); // filter_data(); // } // }); }); </script> </body> </html>
and my
<?php //fetch_data.php include('database_connection.php'); if(isset($_POST["action"])) { $query = " SELECT * FROM voice_bank_data WHERE voice_status = '1' "; // if(isset($_POST["minimum_price"], $_POST["maximum_price"]) && !empty($_POST["minimum_price"]) && !empty($_POST["maximum_price"])) // { // $query .= " // AND product_price BETWEEN '".$_POST["minimum_price"]."' AND '".$_POST["maximum_price"]."' // "; // } // Gender if(isset($_POST["gender"])) { $gender_filter = implode("','", $_POST["gender"]); $query .= " AND voice_gender IN('".$gender_filter."') "; } // Genres if(isset($_POST["genres"])) { $genres_filter = implode("','", $_POST["genres"]); $query .= " AND voice_genres IN('".$genres_filter."') "; } // Voice Modulation if(isset($_POST["voice_modulation"])) { $voice_modulation_filter = implode("','", $_POST["voice_modulation"]); $query .= " AND voice_voice_modulation IN('".$voice_modulation_filter."') "; } // Languages if(isset($_POST["languages"])) { $languages_filter = implode("','", $_POST["languages"]); $query .= " AND voice_languages IN('".$languages_filter."') "; } // Jingle Moods if(isset($_POST["jingle_moods"])) { $jingle_moods_filter = implode("','", $_POST["jingle_moods"]); $query .= " AND voice_jingle_moods IN('".$jingle_moods_filter."') "; } // IVR if(isset($_POST["ivr"])) { $ivr_filter = implode("','", $_POST["ivr"]); $query .= " AND voice_ivr IN('".$ivr_filter."') "; } $statement = $connect->prepare($query); $statement->execute(); $result = $statement->fetchAll(); $total_row = $statement->rowCount(); $output = ''; if($total_row > 0) { foreach($result as $row) { $output .= ' <div class="col-sm-3 col-lg-4 col-md-3"> <div style="border:1px solid #ccc; border-radius:5px; padding:10px; margin-bottom:16px; height:300px;"> <audio controls controlsList="nodownload" style="padding: 10px 10px 10px 10px;margin-left: -21px;"> <source src="audio_sample/'. $row['voice_audio_file'] .'" alt="" class="img-responsive"> </audio> <p align="center"><strong> '. $row['voice_name'] .'</strong></p> <p style="font-size: 12px;"> Gender : '. $row['voice_gender'].' <br /> Genres : '. $row['voice_genres'].' <br /> Voice Modulation : '. $row['voice_voice_modulation'].' <br /> Languages : '. $row['voice_languages'].' <br /> Jingle Moods : '. $row['voice_jingle_moods'].' <br /> Ivr : '. $row['voice_ivr'].' <br /> </p> <button class="btn btn-primary" type="submit" style="padding: 5px 83px 5px 83px;"> Add to PlayList </button> </div> </div> '; } } else { $output = '<h3>No Data Found</h3>'; } echo $output; } ?>
How can i add add-to-cart functionality? https://snag.gy/xQ8TXP.jpg Edited June 10, 2019 by aveevaHello all, My question is about a custom-coded latest-news plugin written by someone else. I don't know if it is generic, a copy of something else or what. It works good! but when I go to add a new news item to the list under Settings, it adds the item to the bottom of the list. The news is displayed on my homepage in short form and in full format on the primary news page. I need new items to be added to the TOP of the list instead or in reverse, so that in all the containers where it resides, the latest news item added is always at the top of the list. I know nothing about php but I am looking to learn. I plan on taking some basic classes on css and php to upgrade my archaic html skills, but I'm currently studying other subjects. Regardless, if this has a simple fix, I would be very interested in knowing what is needed and where/why. Here is the core of the php that I am finding in the plugin: There are three php files, This one says active, the other two say inactive so I get the impression they are not in use. Let me know if I should post their contents as well. Appreciate any help with this! My sincere thanks in advance. Labeled active: latest_news.php */ob_start();register_activation_hook(__file__, latest_news_install);function latest_news_install() { global $wpdb; $table_name = $wpdb->prefix . "latest_news"; if ($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) { $sql = "CREATE TABLE IF NOT EXISTS " . $table_name . " ( `id` int(10) NOT NULL AUTO_INCREMENT, `title` varchar(255) NOT NULL, `description` text NOT NULL, `date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id) );"; mysql_query($sql) or die(mysql_error()); }}if( !function_exists('wp_latest_news_init') ) { function wp_latest_news_init() { add_shortcode( 'wp_latest_news', 'shortcode_latest_news'); }}if( !function_exists('shortcode_latest_news') ) { function shortcode_latest_news() { // extract(shortcode_atts(array('limit' => '5', ), $atts)); global $wpdb; $user_count = $wpdb->get_results("SELECT * FROM wp_latest_news ORDER BY date ASC LIMIT 4"); foreach ($user_count as $output) { $htmlOutput[] = "<li><b><a href='". get_permalink(287)."?news_id=".$output->id."'>" . $output->title . "</a></b></li>"; } //echo $htmlOutput; //echo "<pre>"; print_r($user_count); echo "</pre>"; foreach ($htmlOutput as $out) { echo $out; } return $htmlOutput; }}/* add_action('init', 'wp_latest_news_init' ) is used for call init function for create shortcode */add_action('init', 'wp_latest_news_init' );add_action('admin_menu', 'wp_latestnews_links' );function wp_latestnews_links() { add_submenu_page( 'options-general.php', __( 'Latest News ' ), __( 'Latest News ' ), 5 , 'latest_news_settings', 'latest_news_settings' );}// function latest_news_settings() {// global $wpdb;// if (isset($_POST["submit"])) {// $sql="INSERT INTO ".$wpdb->prefix . "latest_news(`title`,`description`) VALUES ('".$_POST['news_title']."','".$_POST['description']."') ";// //$sql=$wpdb->insert( $wpdb->latest_news, array( 'title' => $_POST['news_title'] ,'description' => $_POST['description'] ) );// mysql_query($sql) or die(mysql_error());// }// include 'Latest_news_setting.php';function latest_news_settings() { global $wpdb; $action = $_REQUEST["action"]; $id = $_REQUEST['id']; $sql = "SELECT * from ".$wpdb->prefix."latest_news "; $results = $wpdb->get_results($sql); //echo "<pre>";print_r($results); //$post_arr = query_posts(""); //echo "<pre>";print_r($post_arr);exit; switch ($action) { case 'add' : include('news_form.php'); break; case 'save' : if(isset($_POST['cancel'])) { include('latest_news_list.php'); } else if(isset($_POST['add'])) { $wpdb->query("insert into ".$wpdb->prefix."latest_news (`title`,`description`) VALUES ('".$_REQUEST['news_title']."','".$_REQUEST['description']."')"); //header("Location: http://localhost:81/Bravo/wp-admin/edit.php?page=slider_images"); header("location:?page=latest_news_settings"); } break; case 'edit' : $sql = "SELECT * from ".$wpdb->prefix."latest_news where id = '".$id."' "; $results_arr = $wpdb->get_results($sql); //echo "<pre>";print_r($results_arr); include('news_form.php'); break; case 'update' : if(isset($_POST['cancel'])) { include('news_form.php'); } else if(isset($_POST['edit'])) { //echo $id; $wpdb->query("update ".$wpdb->prefix."latest_news set title = '".$_REQUEST['news_title']."', description = '".$_REQUEST['description']."' where id='".$id."'"); header("location:?page=latest_news_settings"); } break; case 'delete' : $wpdb->query("delete from ".$wpdb->prefix."latest_news where id='".$id."'"); header("location:?page=latest_news_settings"); break; default: include('latest_news_list.php'); break; }}?>() I have Win 7 home premium, Apache 2.2 (installed using the .msi) and PHP 5.2.14 (downloaded as "php-5.2.14-Win32-VC6-x86.zip", installed manually, it works) on both machines. The other is 32-bit and the other is 64-bit, both Windows 7 Home Premium. When I run the exactly same script on one machine, it does what it is supposed to (32-bit), but on the 64-bit it does not. Basically this appears in two situations (so far): I have a script that reads a (xml) file into a simplexml object, and if this is not successful, it prints an error message. On the 32-bit machine I can import (read) another xml file at once once the first one is processed (into a sqlite database), but on the 64-bit machine it gives me an error originating from the fact that the script did not manage to create the simplexml object. The other situation is when I want to open a specific PDF - file in a browser window (Firefox, the newest one, on the 32-bit machine, IE something newish on the 64-bit). The file exists, the path to the folder is in the Path environment variable, I can open it normally etc on the 64-bit machine, but when I click on a link that is supposed to open the file in a browser window I only get an error message saying that the file does not start with "%PDF.... Needless to say, the precisely same script works just fine on the 32 bit machine. $path_to_image="D:\\path_to_folder\\"; $file_name=$_GET['file_name']; header("Content-disposition: inline; filename=".$path_to_image.$file_name); header("Content-type: application/pdf"); readfile($path_to_image.$file_name); The above code is from the part that receives the file name from a form (other file). Anyone noticed anything like this? Any suggestions? Have been trying to figure this out for days, now... Oh, forgot: In both cases the thing is accessed as/from "localhost". Hi all. I'm using a cron job to pull the XML feed of my last five tweets, and using simplexml to parse and display the feed on my website. Here's the PHP I'm using--it works just fine, and displays exactly as I want it to: <?php $xml = simplexml_load_file('crontwitter.xml'); foreach ($xml->status as $status) { print "<p><span class=\"twittertext\">{$status->text}</span><br />"; print "<a class=\"twittertime\" href=\"http://twitter.com/#!/eaners/status/{$status->id}\" target=\"_blank\">"; echo date("j M Y, g:i A",strtotime($status->created_at)); print "</a></span></p>"; } ?> I'd like to add a touch more "intelligence" to this script, though. Namely, there are three things I'd also like to have this script do: I'd like to append "I" to any tweets that include the #fb hashtag, so that things display correctly (e.g., "I did such and such today" instead of just "did such and such today") I'd like to link to any other Twitter users mentioned (they would always be mentioned using the @username format) I'd like to link to a search for any other hash tag mentioned aside from #fb (they would always be included using the #tag format) I guess I'm not sure how exactly to further parse the XML file. I'll admit to being a relative newbie when it comes to PHP, so any assistance would be greatly appreciated! Hi There I am trying to create a page that edit mysql database from a php page. I can get the edit page to show the orginal information but it wont update the data in the mysql database. I am sure I have entered everything right. If anyone could help with this I would greatly appreciated <?php include("dbconnect.php"); if(isset($_POST['submit'])) { // Set global variables to easier names // and prevent sql injection and apostrophe to break the db. $ProductName = mysql_escape_string($_POST['ProductName']); $ProductText = mysql_escape_string($_POST['ProductText']); $ProductImage = mysql_escape_string($_POST['ProductImage']); $ProductPrice = mysql_escape_string($_POST['ProductPrice']); $result = mysql_query("UPDATE Product SET ProductName='$ProductName', ProductText='$ProductText', ProductImage='$ProductImage', ProductPrice='$ProductPrice' WHERE ID='$ID' ",$dbconnect); echo "<b>Thank you! Product UPDATED Successfully!<br>You'll be redirected to View Page after (2) Seconds"; echo "<meta http-equiv=Refresh content=2;url=view.php>"; echo "$ProductName <br> $ProductText <br> $ProductImage <br> $ProductPrice"; } elseif(isset($_GET['ID'])) { $result = mysql_query("SELECT * FROM Product WHERE ID='$_GET[ID]' ",$dbconnect); while($myrow = mysql_fetch_assoc($result)) { $ProductName = $myrow["ProductName"]; $ProductText= $myrow["ProductText"]; $ProductImage = $myrow["ProductImage"]; $ProductPrice = $myrow["ProductPrice"]; ?> <br> <h3>::Edit Product</h3> <form method="post" action="<?php echo $PHP_SELF ?>"> <input type="hidden" name="ID" value="<? echo $myrow['ID']?>"> Product Name: <input name="ProductName" size="40" maxlength="255" value="<? echo $ProductName; ?>"><br> Product Text: <textarea name="ProductText" rows="7" cols="30"><? echo $ProductText; ?></textarea><br> Product Image: <textarea name="ProductImage" rows="7" cols="30"><? echo $ProductImage; ?></textarea><br> Product Price: <textarea name="ProductPrice" rows="7" cols="30"><? echo $ProductPrice; ?></textarea><br> <input type="submit" name="submit" value="Update Product"> </form> <? }//end of while loop }//end else ?> I am trying to make a login which works perfectly until I try and add remember me functionality into the User class. Hello Freaks, I am currently working on a status report web application. A user inputs what they are planning on accomplishing that week. Afterwords realizes that they made a mistake and need to correct it. The way I want to go about this is sql the database and return * where the username and report date are current. With the results of this query I insert them into the form as the value. This yields a populated form. From here I want the user to be able to change any line and submit the whole form. However, the post array is only populated with one row of data. I thought this might have to do with the names of the inputs all being the same so i tried to index those through the while loop with no luck. Any help would be appreciated! here's the code Code: [Select] <? // renaming sess var $UAID = $_SESSION['UAID']; $WEND = $_SESSION['WEEK_ENDING2']; //have we submitted our changes? if($EDIT == TRUE){ //how many task are there this week $results = mysql_query("Select COUNT(UAID) FROM `WPFTW` where UAID ='$UAID' and Rend = '$WEND'"); $row = mysql_fetch_row($results); //clean $_POST print_r($_POST); unset($_POST['Report']); echo "<br>"; print_r($_POST); } //what do we plan on editing $results = mysql_query("Select * FROM `WPFTW` where UAID ='$UAID' and Rend = '$WEND'"); //while there are results while($row = mysql_fetch_array($results)){ //increment for input name $k = 1; //date formatting list($year,$month,$day) = explode("-",$row['Target']); $row['Target'] = $month."-".$day."-".$year; //empty string to uncheck checkboxes $checked = ""; //populate checkboxes if($row['MS'] == "on"){ $checked = "yes"; } //select the correct drop down menu option if(isset($row['Status'])){ if($row['Status'] == " "){ $selected = "selected"; $selected1 = ""; $selected2 = ""; $selected3 = ""; } elseif($row['Status'] == "P"){ $selected = ""; $selected1 = "selected"; $selected2 = ""; $selected3 = ""; } elseif($row['Status'] == "C"){ $selected = ""; $selected1 = ""; $selected2 = "selected"; $selected3 = ""; } elseif($row['Status'] == "CL"){ $selected = ""; $selected1 = ""; $selected2 = ""; $selected3 = "selected"; } } //select the correct drop down menu option if(isset($row['OT'])){ if($row['OT'] == "Y"){ $selected4 = "selected"; $selected5 = ""; } elseif($row['OT'] == "N"){ $selected4 = ""; $selected5 = "selected"; } } //var to send form to self $cani = htmlentities($_SERVER['PHP_SELF']); //concatenate html & php for form $test = "<form id =\"2bigform\" action=$cani method = \"post\">" . "<tr>" . "<td><input id=\"hidden\" name=\"UAID$k\" type=\"hidden\" value=" . $_SESSION['UAID'] ."></td>". "<td width=\"7%\"> <input id=\"SR\#$k\" name=\"SR#\" type=\"text\" size=\"10%\" maxlength=\"10\" value=" . $row['SRNUM'] . "></td>" . "<td width=\"63%\"> <input id=\"Task$k\" name=\"Task\" type=\"textarea\" size=\"63%\" value=" . $row['Task'] . "></td>" . "<td width=\"7%\"> <select id=\"Status$k\" name=\"Status\">". " <option value=\" \" $selected></option>". " <option value=\"P\" $selected1>P</option>". " <option value=\"C\" $selected2>C</option>". " <option value=\"CL\" $selected3>CL</option>". "</select></td>". "<td width=\"7%\"> <input id=\"MS$k\" name=\"MS\" type=\"checkbox\" size=\"7%\" value=" . $row['MS'] . " checked = $checked></td>". "<td width=\"7%\"> <select id=\"OT$k\" name=\"OT\">". " <option value=\"Y\" $selected4>Y</option>". " <option value=\"N\" $selected5>N</option>". "</select></td>". "<td width=\"9%\"> <input id=\"Target$k\" name=\"Target\" type=\"text\" size=\"9%\" value=" . $row['Target'] . "></td>". "<input id=\"hidden\" name=\"RDate$k\" type=\"hidden\" value=" . $_SESSION['WEEK_ENDING'] ."></td></tr>"; echo $test; $k++; echo $k; } echo "</table>". "<input id=\"Sub\" type= \"Submit\" name=\"Report\" value= \"Submit\"/>". "</form>". "</body>". "</html>"; //<td width="7%"> <input id="SR#" name="SR#" type="text" size="10%" maxlength="10"/></td> //<td width="63%"> <input id="Task" name="Task" type="textarea" size= "63%"/></td> } ?> Hi All, The Problem: I'm trying to learn how to take records from the NAME row of one table (i.e. Tom, Jim, Chris, Mike) and put them into a SELECT (drop down menu) box, then select a name and save it to a DIFFERENT table where the row is also called NAME, and THEN have that selection I just saved show in the SELECT box as SELECTED when the page refreshes. I have found a hundred websites showing how to bind a SELECT box to a table and put them into a SELECT box via $key => $val and even how to save it to ANOTHER textbox on the page, which is a lot easier, but never a step further as described in the first paragraph above. Seems unbelievable to me since it's so common. Maybe I'm just not using the proper search terms/keywords. Here's an example: Let's say you wanted to notify 3 people of your birthday. So, on the notification page, you would enter three names of people you would want notified all in separate input textboxes with [keys]. So, you enter John, Chris, and Tom into three text boxes and save the page. Done. Now, on another page, I have -- say .... five select boxes. For arguments sake, let's just say I click on all of them one at a time. In each of them, I would only see three names (John, Chris, and Tom). Now, in the first SELECT box I click on John. In the second select box I click on Chris, and on the third I click on Tom. Then save the form. I would like to see John, Chris, and Tom in the first three boxes after refreshing and I would like to see SELECT A NAME on the last two Select boxes that we never did anything with. Remember, there are NO default names in the first table with row called NAMES. They are populated by the user and saved to the row. I'm attaching an image of what the page looks like that I want to see the names and be able to select them. Does anyone have a link to a site that shows how to do this... or maybe have something very basic that would show me the process? Or, if not too difficult, maybe you could show me? Thanks in advance for any help! Attached Files Untitled.jpg 24.97KB 0 downloads I am using the dragdrop functionality on a page which also updates the database.Drag and drop is working fine But i am having difficulty to determine which events to use to update the database. Here is my code
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery UI Sortable - Portlets</title> <link rel="stylesheet" href="//code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css"> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="//code.jquery.com/ui/1.11.1/jquery-ui.js"></script> <!--<link rel="stylesheet" href="/resources/demos/style.css">--> <style> body { min-width: 520px; } .interview-questions-column { width: 400px; float: left; padding-bottom: 100px; } .question-bank { width: 500px; float: left; padding-bottom: 100px; } .portlet { margin: 0 1em 1em 0; padding: 0.3em; } .portlet-header { padding: 0.2em 0.3em; margin-bottom: 0.5em; position: relative; } .portlet-toggle { position: absolute; top: 50%; right: 0; margin-top: -8px; } .portlet-content { padding: 0.4em; } .portlet-placeholder { border: 1px dotted black; margin: 0 1em 1em 0; height: 50px; } .sortable { border: 1px solid #eee; width: 95%; min-height: 20px; list-style-type: none; margin: 0; padding: 5px 0 0 0; float: left; margin-right: 10px; } .sortable li { margin: 0 5px 5px 5px; padding: 5px; font-size: 1.2em; width: 95%; } .bank-quertion-sotrable { border: 1px solid #eee; width: 150px; min-height: 20px; list-style-type: none; margin: 0; padding: 5px 0 0 0; float: left; margin-right: 10px; } .bank-quertion-sotrable li{ margin: 0 5px 5px 5px; padding: 5px; font-size: 1.2em; width: 200px; } .ui-state-default { height: 1.5em; line-height: 1.2em; } </style> <script> $(function() { $( ".interview-questions-column" ).sortable({ connectWith: ".interview-questions-column", handle: ".portlet-header", cancel: ".portlet-toggle", placeholder: "portlet-placeholder ui-corner-all" }); $( ".portlet" ) .addClass( "ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" ) .find( ".portlet-header" ) .addClass( "ui-widget-header ui-corner-all" ) .prepend( "<span class='ui-icon ui-icon-minusthick portlet-toggle'></span>"); $( ".portlet-toggle" ).click(function() { var icon = $( this ); icon.toggleClass( "ui-icon-minusthick ui-icon-plusthick" ); icon.closest( ".portlet" ).find( ".portlet-content" ).toggle(); }); }); $(function() { $( ".sortable" ).sortable({ placeholder: "ui-state-default", connectWith: ".connectedSortable", /*receive: function(event, ui) { // only perform for sub drop downs if($(this).hasClass('question_bank')) { // if the item doesn't have the matching sub class if (!$(this).hasClass($(ui.item).attr('class'))) { // cancel the sortable $(ui.sender).sortable('cancel'); } } alert('receive'); alert(ui.sender.attr("dataid")); alert(ui.sender.toSource()); // alert("[" + this.id + "] received [" + ui.item.attr("id") + "] from [" + ui.sender.attr("id") + "]"); },*/ update: function (event, ui) { //serial = $('#sortableF').sortable('serialize'); var data = $(this).sortable('serialize'); alert(data); //alert('update sortable'); //alert("[" + this.id + "] received [" + ui.item.attr("id") + "] from [" + ui.sender.attr("id") + "]"); // POST to server using $.post or $.ajax /*$.ajax({ data: 'test', type: 'POST', url: '/your/url/here' });*/ } }).disableSelection(); }); $(function() { $( ".draggable" ).draggable({ connectToSortable: ".sortable", helper: "clone", /*revert: function(valid) { if(valid) { alert("drop is valid"); //Dropped in a valid location } else { alert("drop is invalid"); //Dropped in an invalid location } // return !valid; return false; }*/ stop: function( event, ui ) { // alert(ui); // alert("[" + this.id + "] received [" + ui.item.attr("id") + "] from [" + ui.sender.attr("id") + "]"); } }); }); $( "ul, li" ).disableSelection(); </script> </head> <body> <div class="interview-questions-column"> <div class="portlet"> <div class="portlet-header">Feeds</div> <div class="portlet-content"> <ul id="sortableF" class="connectedSortable sortable"> <li class="ui-state-default" id="item-1">Item 1</li> <li class="ui-state-default" id="item-2">Item 2</li> <li class="ui-state-default" id="item-3">Item 3</li> <li class="ui-state-default" id="item-4">Item 4</li> <li class="ui-state-default" id="item-5">Item 5</li> </ul> </div> </div> <div class="portlet"> <div class="portlet-header">News</div> <div class="portlet-content"> <ul id="sortableS" class="connectedSortable sortable"> <li class="ui-state-default" id="item-6">Item 1</li> <li class="ui-state-default" id="item-7">Item 2</li> <li class="ui-state-default" id="item-8">Item 3</li> <li class="ui-state-default" id="item-9">Item 4</li> <li class="ui-state-default" id="item-10">Item 5</li> </ul> </div> </div> <div class="portlet"> <div class="portlet-header">Shopping</div> <div class="portlet-content"> <ul id="sortableS" class="connectedSortable sortable"> <li class="ui-state-default" id="item-11">Item 1</li> <li class="ui-state-default" id="item-12">Item 2</li> <li class="ui-state-default" id="item-13">Item 3</li> <li class="ui-state-default" id="item-14">Item 4</li> <li class="ui-state-default" id="item-15">Item 5</li> </ul> </div> </div> <div class="portlet"> <div class="portlet-header">Links</div> <div class="portlet-content"> <ul id="sortableS" class="connectedSortable sortable"> <li class="ui-state-default" id="item-16">Item 1</li> <li class="ui-state-default" id="item-17">Item 2</li> <li class="ui-state-default" id="item-18">Item 3</li> <li class="ui-state-default" id="item-19">Item 4</li> <li class="ui-state-default" id="item-20">Item 5</li> </ul> </div> </div> <div class="portlet"> <div class="portlet-header">Images</div> <div class="portlet-content"> <ul id="sortableS" class="connectedSortable sortable"> <li class="ui-state-default" id="item-21">Item 1</li> <li class="ui-state-default" id="item-22">Item 2</li> <li class="ui-state-default" id="item-23">Item 3</li> <li class="ui-state-default" id="item-24">Item 4</li> <li class="ui-state-default" id="item-25">Item 5</li> </ul> </div> </div> </div> <div class="question-bank"> <div class="portlet"> <div class="portlet-header">Question bank</div> <div class="portlet-content"> <ul id="question_back" class="connectedSortable bank-quertion-sotrable"> <li class="ui-state-default draggable" id="item-26">Item 1</li> <li class="ui-state-default draggable" id="item-27">Item 2</li> <li class="ui-state-default draggable" id="item-28">Item 3</li> <li class="ui-state-default draggable" id="item-29">Item 4</li> <li class="ui-state-default draggable" id="item-30">Item 5</li> </ul> </div> </div> </div> </body> </html>Basically above code will form few boxes with items(which are actually questions) in it. There is one box on the right side with heading "Question Bank". From the "Question Bank" we can drag the questions to other boxes but can't do the reverse(this is also working). Also we can sort the questions within the box or drag the questions from one box to another. Box heading are the categories and items are questions associated to that categories. What i need is : Event that updates the database when we drag the questions from "Question Bank" to any box on the left side. Please note Questions in the "Question Bank" are pre created coming from database. Event that updates the database when we sort the questions within the box. Event that updates the database when we drag the question from one box to another box. it should also do the sorting for that two boxes. Event that updates the database when we sort the boxes. Here is the JS Fiddle link jsfiddle.net/6o30rrzx Question Bank is comming on the bottom of the page instead of on the right side any advice and suggestions will be greatly appreciated Thank you for reading this post. 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 Hi to all gurus, Here is a small program in flash which calls values from PHP and displays them correctly. path = "http://localhost/xampp/nwjv/php/"; //declare path to php files lvOut = new LoadVars(); //create lv object sending variables OUT to php lvIn = new LoadVars(); //create lv object receiving variables IN from php lvIn.onLoad = function (success) { if(success) { //PHP variable value to textbox InVal = lvIn.returnVal; InTxt = lvIn.retVal; output.text = InVal; output1.text = InTxt; /* output1.text = "No Value"; if(InTxt == 'lo' ) { output1.text = "Low Value"; } if(InTxt == 'hi') { output1.text = "High Value"; } */ }else{ //...or notify of failure output.text = "fail"; } } myBtn.onRelease = function(){ //assign user-input value to lv property called years lvOut.years = years.text; //send to a blank window // lvOut.send(path + "dogyears_new1.php",lvIn,"GET"); lvOut.sendAndLoad(path + "dogyears_new1.php",lvIn,"GET"); }; Im wondering if someone can shed some light on possibly the best way to do this. I currently have a website which recieves 26000-37000 visits a month. The host got on my case about to many MySql connections and with help from someone here decided a cache system was best. the cache system is now in place and only updates if the cached file is older than 5 days. I am still recieving high connections to my database and wonder if it is spam as i have a search box. the search box once filled in redirects to a page which queries the database for the keyword and displays results and because it was just selecting and not inserting into database i didnt go for the captcha. this is why i suspect spam, I have thought about limiting the amount of search queries per time limit by ip but I am unsure of how to tackle this and if it will help against spam bots? a google search has only found an answer which stores every visitors ip in a database and keeps count there which I cant see the benefit as it is creating more work for the DB. I have thought maybe creating a session variable that increments with every search and when searching checks this value but I am not to sure if this would help as it would be down to cookie settings. can anyone shed some light on a possible solution to this. I am not expecting you to write this for me but for now just to help with the best way to tackle the problem. Thank you for your time. Alright so I have some code for pagination... the problem is on the middle pages it will display double the number of results... (IE if its supposed to display 5, it displays 10) Code: [Select] // Number of messages per page: $user_message_number = 5; $page = $_GET['page']; if($page <= 1){ $low = 0; $high = $user_message_number; } else { $low = ($page - 1) * $user_message_number; $high = $page * $user_message_number; } $messages = mysql_query("SELECT * FROM messages WHERE recipient='$user_id' ORDER BY id DESC LIMIT $low, $high") or die(mysql_error()); while($pull_messages = mysql_fetch_array($messages)) { // Displays content } That's all of the code that would directly effect the outcome... Any thoughts/comments/suggestions are greatly appreciated. |