PHP - Php Only Lets Me Edit 1st Line From Query
I have a search that the user can use and pulls up the records from the database. I made it to where you can click on an image and it will let you edit that record, problem is, it won't let me edit the 1st record that is populated, the rest work fine. Can you find what I am doing wrong?
while ($row = mysql_fetch_array($result)) { $rid=$row['timeslip_id']; $rint=$row['Initials']; $rident=$row['Identifier']; $rtype=$row['Type']; $rterms=$row['Terms']; $rmemo=$row['Memo']; $rdate=$row['Date']; $rcost=$row['Cost']; ?> <tr> <td valign="top"></td> <td valign="top"> <form action="editslip.php" name="<?=$rid?>" method="post"> <input type="hidden" name="edata" value="<?=$rid?>"> </form> <a href="#" onclick="document['<?=$rid?>'].submit()"><img src="images/pencil.png" height="24px" width="24px"/></a></td> <td valign="top" align="left"><?=$rint?></td> <td valign="top" align="left"><?=$rident?></td> <td valign="top" align="left"><?=$rtype?></td> <td valign="top" align="left"><?=$rterms?></td> <td valign="top" align="left"> <?php $convdate = date('m/d/Y', strtotime($rdate));?> <?=$convdate?></td> <td valign="top"><?=$rcost?></td> <td valign="top"> <?php echo substr($rmemo,0,100);?></td> <td align="center"><input type="checkbox" name="del[]" id="del" value="<?=$row['timeslip_id']?>"></td> </tr> Similar TutorialsHey Guys.....I would really appreciate all if you guys could help me on this.. i am developing a work order aka business ticketing system where i have to search the tickets based on the given criteria of: ticket no or department name or project name or the status of the ticket or severity of the ticket... i have written the query as $qry = "SELECT * FROM tickets WHERE ((ticket_id='$var1') OR ('$var1' IS NULL)) and ((dept_id='$var2') OR ('$var2' IS NULL)) and ((proj_id='$var3') OR ('$var3' IS NULL)) and ((status='$var4') oR ('$var4' IS NULL)) and ((severity='$var5') oR ('$var5' IS NULL))"; 1. if i have a value for var1==15 inserted and the values of var2 to var5 are null, the whole query gives zero rows 2 If I have values for var1 till var4 but one null for the var5 still query result is zeros I need to make the condition work only where value is not null otherwise condition should be avoided Is there any way - please write the query for me - EDIT - I am working in PHP I'm working with a Wordpress plugin that uses that google maps api to map multiple markers depending on search terms and proximity. You can set an option so that, regardless of the default proximity when the page loads, ALL markers will first appear. In order to help with performance, the authors decided to limit that option to 250 markers. I need to lift that limit to 5,000 (though I currently only have about 500, I don't want to deal with limits as my markers grow).
Based on a comment made in one of the php files it appears the authors enforce the limit in the query itself so I'm pasting the code for the php file that performs the query. Please let me know if there is something else I should do, if this forum is the wrong place or if I should be posting on pastebin and linking rather than dumping the entire file between code tags. Thanks in advance!
<?php if ( !class_exists( 'SM_XML_Search' ) ){ class SM_XML_Search{ // Register hook to perform the search function sm_xml_search() { add_action( 'template_redirect', array( &$this, 'init_search' ) ); } // Inits the search process. Collects default options, search options, and queries DB function init_search() { if ( isset( $_GET['sm-xml-search'] ) ) { global $wpdb, $simple_map; remove_filter( 'the_title', 'at_title_check' ); $defaults = array( 'lat' => false, 'lng' => false, 'radius' => false, 'namequery' => false, 'query_type' => 'distance', 'address' => false, 'city' => false, 'state' => false, 'zip' => false, 'onlyzip' => false, 'country' => false, 'limit' => false, 'pid' => 0, ); $input = array_filter( array_intersect_key( $_GET, $defaults ) ) + $defaults; $smtaxes = array(); if ( $taxonomies = get_object_taxonomies( 'sm-location' ) ) { foreach ( $taxonomies as $key => $tax ) { $phpsafe = str_replace( '-', '_', $tax ); $_GET += array( $phpsafe => '' ); $smtaxes[$tax] = $_GET[$phpsafe]; } } // Define my empty strings $distance_select = $distance_having = $distance_order = ''; // We're going to do a hard limit to 500 for now. if ( !$input['limit'] || $input['limit'] > 500 ) $limit = "LIMIT 500"; else $limit = 'LIMIT ' . absint( $input['limit'] ); $limit = apply_filters( 'sm-xml-search-limit', $limit ); // Locations within specific distance or just get them all? $distance_select = $wpdb->prepare( "( 3959 * ACOS( COS( RADIANS(%s) ) * COS( RADIANS( lat_tbl.meta_value ) ) * COS( RADIANS( lng_tbl.meta_value ) - RADIANS(%s) ) + SIN( RADIANS(%s) ) * SIN( RADIANS( lat_tbl.meta_value ) ) ) ) AS distance", $input['lat'], $input['lng'], $input['lat'] ) . ', '; $distance_order = 'distance, '; if ( $input['radius'] ) { $input['radius'] = ( $input['radius'] < 1 ) ? 1 : $input['radius']; $distance_having = $wpdb->prepare( "HAVING distance < %d", $input['radius'] ); } $i = 1; $taxonomy_join = ''; foreach ( array_filter( $smtaxes ) as $taxonomy => $tax_value ) { $term_ids = explode( ',', $tax_value ); if ( $term_ids[0] == 'OR' ) { unset( $term_ids[0] ); if ( empty( $term_ids ) ) { continue; } $search_values = array( "IN (" . vsprintf( '%d' . str_repeat( ',%d', count( $term_ids ) - 1 ), $term_ids ) . ")" ); } else { $search_values = array(); foreach ( $term_ids as $term_id ) { $search_values[] = sprintf( '= %d', $term_id ); } } foreach ( $search_values as $search_value ) { $taxonomy_join .= " INNER JOIN $wpdb->term_relationships AS term_rel_$i ON posts.ID = term_rel_$i.object_id INNER JOIN $wpdb->term_taxonomy AS tax_$i ON term_rel_$i.term_taxonomy_id = tax_$i.term_taxonomy_id AND tax_$i.taxonomy = '$taxonomy' AND tax_$i.term_id $search_value "; $i++; } } $sql = "SELECT lat_tbl.meta_value AS lat, lng_tbl.meta_value AS lng, $distance_select posts.ID, posts.post_content, posts.post_title FROM $wpdb->posts AS posts INNER JOIN $wpdb->postmeta lat_tbl ON lat_tbl.post_id = posts.ID AND lat_tbl.meta_key = 'location_lat' INNER JOIN $wpdb->postmeta lng_tbl ON lng_tbl.post_id = posts.ID AND lng_tbl.meta_key = 'location_lng' $taxonomy_join WHERE posts.post_type = 'sm-location' AND posts.post_status = 'publish' GROUP BY posts.ID $distance_having ORDER BY " . apply_filters( 'sm-location-sort-order', $distance_order . ' posts.post_name ASC', $input ) . " " . $limit; $sql = apply_filters( 'sm-xml-search-locations-sql', $sql ); // TODO: Consider using this to generate the marker node attributes in print_xml(). $location_field_map = array( 'location_address' => 'address', 'location_address2' => 'address2', 'location_city' => 'city', 'location_state' => 'state', 'location_zip' => 'zip', 'location_country' => 'country', 'location_phone' => 'phone', 'location_fax' => 'fax', 'location_email' => 'email', 'location_url' => 'url', 'location_special' => 'special', ); $options = $simple_map->get_options(); $show_permalink = !empty( $options['enable_permalinks'] ); if ( $locations = $wpdb->get_results( $sql ) ) { // Start looping through all locations i found in the radius foreach ( $locations as $key => $value ) { // Add postmeta data to location $custom_fields = get_post_custom( $value->ID ); foreach ( $location_field_map as $key => $field ) { if ( isset( $custom_fields[$key][0] ) ) { $value->$field = $custom_fields[$key][0]; } else { $value->$field = ''; } } $value->postid = $value->ID; $value->name = apply_filters( 'the_title', $value->post_title ); $the_content = trim( $value->post_content ); if ( !empty( $the_content ) ) { $the_content = apply_filters( 'the_content', $the_content ); } $value->description = $the_content; $value->permalink = ''; if ( $show_permalink ) { $value->permalink = get_permalink( $value->ID ); $value->permalink = apply_filters( 'the_permalink', $value->permalink ); } // List all terms for all taxonomies for this post $value->taxes = array(); foreach ( $smtaxes as $taxonomy => $tax_value ) { $phpsafe_tax = str_replace( '-', '_', $taxonomy ); $local_tax_names = ''; // Get all taxes for this post if ( $local_taxes = wp_get_object_terms( $value->ID, $taxonomy, array( 'fields' => 'names' ) ) ) { $local_tax_names = implode( ', ', $local_taxes ); } $value->taxes[$phpsafe_tax] = $local_tax_names; } } } else { // Print empty XML $locations = array(); } $locations = apply_filters( 'sm-xml-search-locations', $locations ); $this->print_json( $locations, $smtaxes ); } } // Prints the JSON output function print_json( $dataset, $smtaxes ) { header( 'Status: 200 OK', false, 200 ); header( 'Content-type: application/json' ); do_action( 'sm-xml-search-headers' ); do_action( 'sm-print-json', $dataset, $smtaxes ); echo json_encode( $dataset ); die(); } } } I thought to relax a bit and while i saw something and an idea came to my mind, lets play noobs, it will be fun... we ask noob questions here lolzzz
so my question is
Hello,
I have seen that there are always 3 users /* I know these are bots */ Google, Yahoo and Bing always online and we cannot see their profiles. They must be very professional hackers who have known how to hide their identities.. right??
I have two scripts. One uses a drop down list to populate a forum while the other makes you enter in a value and populates the forum below with all the data in that table where the input matches the requested number. So lets get down to it shall we? 1st up we have a movies list. <?php include('CheckLogin.php'); include ('databaseconfig.php'); $query = mysql_query("select title from movies"); if (isset($_POST['submitSearch'])) { $query2 = mysql_query("select * from movies where title = ". $_POST['list']); } ?> <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Home </title> <script type="text/javascript" src="javaScript/jquery-min.js"></script> <script type="text/javascript" src="javaScript/corners.js"></script> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <link href="style.css" rel="stylesheet" type="text/css"> </head> <body> <div id="wrapper"> <header> <div id="header"> <h1 id="logo">RAY AND CARLS </h1> <p class="description"><?php echo check();?><br/> </p> </div> </header> <nav> <ul id="nav"> <li> <a href="index.php">Home </a> </li> <li> <a href="#">Customer Registration </a> </li> <li> <a href="#">View Movies </a> </li> <li> <a href="#">View Games </a> </li> <li> <a href="#">Rent </a> </li> <li> <a href="#">Login </a> </li> <li> <a href="#">Admin </a> </li> </ul> </nav> <article> <section> <div class="cornerBox cBox3"> <div class="cornerBox-content"> <div class="List"> <form class="cmxform" id="commentForm" action="action" method="post"> <p> <select name="list"> <?php while ($row = mysql_fetch_array($query)) { echo "<option>$row[title]</option>\n"; } ?> </select> </p> <p><input name="submitSearch" type="button" value="submit"></p> </form> <p> </p> <form class="cmxform" id="commentForm" action="action" method="post"> <h2>The Movie Selected </h2> <p> <?php while ($row2 = mysql_fetch_array($query2)){?> <label for="cname">Movie ID: </label> <em>* </em> <input id="cname" name="movieid" size="4" class="required" minlength="2" value="<?php echo $row2[0];?>"> </p> <p> <label for="cemail">Rented <em> 0 for n, 1 for y</em> </label> <em>* </em> <input id="cemail" name="rented" size="2" class="required email" value="<?php echo $row2[1];?>"> </p> <p> <label for="curl">Title </label> <em>* </em> <input id="curl" name="title" size="30" class="url" value="<?php echo $row2[2];?>"> </p> <p> <label for="curl">Category </label> <em>* </em> <input id="curl" name="category" size="15" class="url" value="<?php echo $row2[3];?>"> </p> <p> <label for="curl">Director </label> <em>* </em> <input id="curl" name="director" size="15" class="url" value="<?php echo $row2[4];?>"> </p> <p> <label for="curl">Leading Actors </label> <em>* </em> <input id="curl" name="leadingactors" size="50" class="url" value="<?php echo $row2[5];?>"> </p> <p> <label for="curl">Supporting Actors </label> <em>* </em> <input id="curl" name="supportingactors" size="50" class="url" value="<?php echo $row2[6];?>"> </p> <p> <label for="curl">Run Time <em>in minutes</em> </label> <em>* </em> <input id="curl" name="runtime" size="4" class="url" value=""><?php echo $row2[7];?></input> </p> <p> <label for="curl">Rating </label> <em>* </em> <input id="curl" name="rating" size="6" class="url" value="<?php echo $row2[8];?>"> </p> <p> <label for="curl">Release Date </label> <em>* </em> <input id="curl" name="releasedate" size="10" class="url" value="<?php echo $row2[9];?>"> <?php } ?> </form> </div> </div> </div> </section> </article> <footer> <div id="footer"> <div class="footer1"> <h2> About </h2> <p> Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. </p> </div> <div class="footer2"> <h2>Other places </h2> <p> <ul> <li> <a href="#">Link 1 </a> </li> <li> <a href="#">Link 2 </a> </li> <li> <a href="#">Link 3 </a> </li> <li> <a href="#">Link 4 </a> </li> </ul> </p> </div> <div class="footer3"> <h2> Other information </h2> <p> Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. </p> </div> <p class="credits">© <a href="http://bwshome.byethost5.com/blogs">Adam Balan - BLACKANDWHITE </a> <span>• </span> Powered by <a href="http://bwshome.byethost5.com/blogs">BLACKANDWHITE </a> <span>• </span> </div> </footer> </div> </body> </html>] This script populates a list with movie names with the select statement of select * from movies; What I want to do is select a movie from this list and have the page refresh with a forum full of the details based on the movie title, hence the select * from movies where title = title statement. What it currently does is populates a drop down list with titles of movies in the data base but not the forum.... 2nd up we have the customer details The second script is similar but now we want to populate a forum based on user input of a customer id. So lets say we have an ID of 10, we enter 10 hit enter and the forum bellow should populate with all the customer info based on that id allowing me to edit and update (I haven't got to the update part yet, still trying to populate a forum) <?php session_start(); include('CheckLogin.php'); include('databaseconfig.php'); if (isset($_POST['searchSubmit'])) { $query = mysql_query("select * from customer where customer_id =".$_POST['cust_id']); } ?> <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Home </title> <script type="text/javascript" src="javaScript/jquery-min.js"></script> <script type="text/javascript" src="javaScript/corners.js"></script> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> </script> <link href="style.css" rel="stylesheet" type="text/css"> </head> <body> <div id="wrapper"> <header> <div id="header"> <h1 id="logo">RAY AND CARLS </h1> <p class="description"> <?php echo checkAdmin();?> <br/> </p> </div> </header> <nav> <ul id="nav"> <li> <a href="index.php">Home </a> </li> <li> <a href="#">Customer Registration </a> </li> <li> <a href="#">View Movies </a> </li> <li> <a href="#">View Games </a> </li> <li> <a href="#">Rent </a> </li> <li> <a href="#">Login </a> </li> <li> <a href="#">Admin </a> </li> </ul> </nav> <article> <section> <div class="cornerBox cBox3"> <div class="cornerBox-content"> <p>All updates to the Data base can be done here. Keeping in mind specific relationships with The back end data bases. </p> <p>Some common tasks are below. This page allows you to add, edit and delete customers/movies and games. </p> <div class="cornerBox2 cBox3"> <div class="cornerBox-content"> <h1>Menu </h1> <ul> <h2>Customers </h2> <li> <a href="#">edit </a> </li> <li> <a href="#">Add New </a> </li> <h2>Movies </h2> <li> <a href="#">edit </a> </li> <li> <a href="#">Add New </a> </li> <h2>Games </h2> <li> <a href="#">edit </a> </li> <li> <a href="#">Add New </a> </li> </ul> </div> </div> <div class="Forum"> <h2>Search</h2> <form class="cmxform" id="commentForm" method="post" action=""> <p> <label for="cname">Customer ID: </label> <em>* id's must be > 0 </em> <input id="cname" name="cust_id" size="25" class="required" minlength="2" /> </p> <p> <input class="submit" type="submit" value="Submit" name="searchSubmit"/> </p> </form> <h2>Edit Customer </h2> <?php $resualt = mysql_query($query); while($row = mysql_fetch_array($resualt)) { ?> <form class="cmxform" id="commentForm" method="post" action=""> <p> <label for="cname">Customer ID: </label> <em>* </em> <input id="cname" name="cust_id" size="25" class="required" minlength="2" value="<?php $row[0]?>"/> </p> <p> <label for="cemail">First Name </label> <em>* </em> <input id="cemail" name="fname" size="25" class="required email" value="<?php $row[1]?>"/> </p> <p> <label for="curl">Last Name </label> <em>* </em> <input id="curl" name="lastname" size="25" class="url" value="<?php $row[2]?>"/> </p> <p> <label for="curl">Address </label> <em>* </em> <input id="curl" name="address" size="25" class="url" value="<?php $row[3]?>"/> </p> <p> <label for="curl">Postal Code </label> <em>* </em> <input id="curl" name="postalcode" size="7" class="url" value="<?php $row[4]?>"/> </p> <p> <label for="curl">Phone Number </label> <em>* </em> <input id="curl" name="phonenumber" size="11" class="url" value="<?php $row[5]?>""/> </p> <p> <input class="submit" type="submit" value="Submit" name="submit"/> </p> </form> <?php } ?> <?php if (!mysql_query($query)) { echo("<h1>Possible Errors </h1>"); //Echo errors echo mysql_error(); echo ("<p>"); } else { echo("<h2>Customer was added</h1>"); } ?> </div> </div> </div> </section> </article> <footer> <div id="footer"> <div class="footer1"> <h2> About </h2> <p> Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. </p> </div> <div class="footer2"> <h2>Other places </h2> <p> <ul> <li> <a href="#">Link 1 </a> </li> <li> <a href="#">Link 2 </a> </li> <li> <a href="#">Link 3 </a> </li> <li> <a href="#">Link 4 </a> </li> </ul> </p> </div> <div class="footer3"> <h2> Other information </h2> <p> Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. </p> </div> <p class="credits">© <a href="http://bwshome.byethost5.com/blogs">Adam Balan - BLACKANDWHITE </a> <span>• </span> Powered by <a href="http://bwshome.byethost5.com/blogs">BLACKANDWHITE </a> <span>• </span> </div> </footer> </div> </body> </html> Now when I enter 10 into the search I get an error of: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #5' at line 1" I was told to make another thread for my question(s) and since these are in relation to each other (populating a forum and all) I thought it best to combine two into one. what im trying to do is take a youtube embed code find the URL code for that video and remove all other parts of the code keeping only the URL of the video after i get the URL by it self then replace the http://www.youtube.com/ part of the URL with http://i2.ytimg.com/vi/ to do this i know that i need something like this to get the URL of the video http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+) but how to only return just the URL is something idk how to do then use str_replace http://www.youtube.com/(?:v|cp)/" with http://i2.ytimg.com/vi/ so in the end im asking if anyone know how to remove all other codes i dont want and only keep the URL this may have to be done using "regex" im not sure as i dont know to much about regex and what it can do but does sound like it would help lol i have to read a single line from a csv, its a really big file and i only need one column.
i need the response to be a string ,i made a search and found the following code but i dont have any idea how to get a single line from a single string per run .
<?php $row = 1; //open the file if (($handle = fopen("file.csv", "r")) !== FALSE) { while (($data = fgetcsv($handle, 0, ",")) !== FALSE) { $num = count($data); echo "<p> $num fields in line $row: <br /></p>\n"; $row++; for ($c=0; $c < $num; $c++) { echo $data[$c] . "<br />\n"; } } fclose($handle); } ?> Edited by bores_escalovsk, 16 May 2014 - 06:38 PM. Dear All Good Day, i am new to PHP (a beautiful server side scripting language). i want to send a mail with line by line message i tried with different types like by placing the things in table and using <br /> but the thing is the tags are also visible in the message of the mail. Here is my code: $message1 = "Name :". $_REQUEST['name']."<br />"; $message1 .= "Surname :". $_REQUEST['surname']."<br />"; $message1 .= "Cellphone :". $_REQUEST['mobileno']."<br />"; $message1 .= "Telephone :". $_REQUEST['landno']."<br />"; $message1 .= "Fax :". $_REQUEST['fax']."<br />"; $message1 .= "Company :". $_REQUEST['company']."<br />"; $message1 .= "Email :". $_REQUEST['email']."<br />"; $message1 .= "Country :". $_REQUEST['country']."<br />"; $message1 .= "Enquity :". $_REQUEST['enquiry']."<br />"; $message1 .= "Date&Time :". $date."<br />"; For this code if try to print/echo it it is working fine it is displaying line by line, but using this variable ($message1) in the mail these <br /> are also visible. Can any one guide me to resolve(to remove these tags from the message part) this issue. Thanks in Advance. :confused: Hi. I want a simple textbox, that when submited, will replace very every new line, with the <br> tag. What will happen, when it submits, it will take the contents of a textbox, add the <br> tag where a new line is suposed to be, and save the string to a MySQL Database. I think this is the easiest way of allowing a user to edit what appears on a website when logged in, but if there is a easier way, then please tell me. What I am trying to do, is a login page, and once logged in, you enter new text into the textbox, click submit, and on the website homepage, the main text will change to what was submitted. But if there is a new line, I think the only way in HTML to make one is to put a <br> tag, so I want the PHP to but that tag wherever there is a new line. Sorry if I am confusing, I am not that advanced at PHP, but I would be very happy if you could supply me with the correct code. Time is running out... If you do not understand me, please tell me -- PHPLeader (not) How to get this echo line to display as one line? No matter what I have done it displays as two lines. I even tried <nobr></nobr> Teachers Name: John Jones $userid = mysql_real_escape_string($_GET['user_id']); $sql = "select * from users where `id`='$userid' "; $rs = mysql_query($sql); while($row = mysql_fetch_array($rs)) { echo "<h3>Teachers Name: </h3>" . $row["first_name"] . " " . $row["last_name"] ; } Thanks for your help. I have a script that reads a .gz file into an array and prints the name of each record but will not work on larger files. Is there a way to read 1 line at a time? Here is the code I have so far. Code: [Select] <?php if ($handle = opendir('.')) { print "<ol>"; while (false !== ($file = readdir($handle))) { if($file != '..' && $file!="." && $file!="start_update.php" && $file!="sharons_dbinfo.inc.php" && $file!="root.php" && $file!="read_directory.php" && $file!="read_dir.php" && $file!="new_category.php" && $file!="index.php" && $file!="file_count.php" && $file!="dir_loop2.php" && $file!="dir_loop1.php" && $file!=".htaccess" && $file!="Answer.txt" && $file!="Crucial_Technology-Crucial_US_Product_Catalog_Data_Feed.txt"){ $filename = $file; $go = filesize($filename); if($go >= 1){ $filename2 = explode("-", $filename); $filename2 = $filename2[0]; echo str_replace("_"," ",$filename2) . ' | Filesize is: ' . filesize($filename) . ' bytes<br>'; $gz = gzopen($filename, 'r'); $lines = gzfile($filename,10000); foreach ($lines as $line) { $line2 = explode(",", $line); $line2 = str_replace("," , "-" , $line2); echo "<li>".str_replace("," , "-" , $line2[4])."</li><br>"; } } } } closedir($handle); } ?> </ol> Here is my code: // Start MySQL Query for Records $query = "SELECT codes_update_no_join_1b" . "SET orig_code_1 = new_code_1, orig_code_2 = new_code_2" . "WHERE concat(orig_code_1, orig_code_2) = concat(old_code_1, old_code_2)"; $results = mysql_query($query) or die(mysql_error()); // End MySQL Query for Records This query runs perfectly fine when run direct as SQL in phpMyAdmin, but throws this error when running in my script??? Why is this??? Code: [Select] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= new_code_1, orig_code_2 = new_code_2WHERE concat(orig_code_1, orig_c' at line 1 Hello all,
Based on the suggestion of you wonderful folks here, I went away for a few days (to learn about PDO and Prepared Statements) in order to replace the MySQLi commands in my code. That's gone pretty well thus far...with me having learnt and successfully replaced most of my "bad" code with elegant, SQL-Injection-proof code (or so I hope).
The one-and-only problem I'm having (for now at least) is that I'm having trouble understanding how to execute an UPDATE query within the resultset of a SELECT query (using PDO and prepared statements, of course).
Let me explain (my scenario), and since a picture speaks a thousand words I've also inlcuded a screenshot to show you guys my setup:
In my table I have two columns (which are essentially flags i.e. Y/N), one for "items alreay purchased" and the other for "items to be purchased later". The first flag, if/when set ON (Y) will highlight row(s) in red...and the second flag will highlight row(s) in blue (when set ON).
I initially had four buttons, two each for setting the flags/columns to "Y", and another two to reverse the columns/flags to "N". That was when I had my delete functionality as a separate operation on a separate tab/list item, and that was fine.
Now that I've realized I can include both operations (update and delete) on just the one tab, I've also figured it would be better to pare down those four buttons (into just two), and set them up as a toggle feature i.e. if the value is currently "Y" then the button will set it to "N", and vice versa.
So, looking at my attached picture, if a person selects (using the checkboxes) the first four rows and clicks the first button (labeled "Toggle selected items as Purchased/Not Purchased") then the following must happen:
1. The purchased_flag for rows # 2 and 4 must be switched OFF (set to N)...so they will no longer be highlighted in red.
2. The purchased_flag for row # 3 must be switched ON (set to Y)...so that row will now be highlighted in red.
3. Nothing must be done to rows # 1 and 5 since: a) row 5 was not selected/checked to begin with, and b) row # 1 has its purchase_later_flag set ON (to Y), so it must be skipped over.
Looking at my code below, I'm guessing (and here's where I need the help) that there's something wrong in the code within the section that says "/*** loop through the results/collection of checked items ***/". I've probably made it more complex than it should be, and that's due to the fact that I have no idea what I'm doing (or rather, how I should be doing it), and this has driven me insane for the last 2 days...which prompted me to "throw in the towel" and seek the help of you very helpful and intellegent folks. BTW, I am a newbie at this, so if I could be provided the exact code, that would be most wonderful, and much highly appreciated.
Thanks to you folks, I'm feeling real good (with a great sense of achievement) after having come here and got the great advice to learn PDO and prepared statements.
Just this one nasty little hurdle is stopping me from getting to "end-of-job" on my very first WebApp. BTW, sorry about the long post...this is the best/only way I could clearly explaing my situation.
Cheers guys!
case "update-delete": if(isset($_POST['highlight-purchased'])) { // ****** Setup customized query to obtain only items that are checked ****** $sql = "SELECT * FROM shoplist WHERE"; for($i=0; $i < count($_POST['checkboxes']); $i++) { $sql=$sql . " idnumber=" . $_POST['checkboxes'][$i] . " or"; } $sql= rtrim($sql, "or"); $statement = $conn->prepare($sql); $statement->execute(); // *** fetch results for all checked items (1st query) *** // $result = $statement->fetchAll(); $statement->closeCursor(); // Setup query that will change the purchased flag to "N", if it's currently set to "Y" $sqlSetToN = "UPDATE shoplist SET purchased = 'N' WHERE purchased = 'Y'"; // Setup query that will change the purchased flag to "Y", if it's currently set to "N", "", or NULL $sqlSetToY = "UPDATE shoplist SET purchased = 'Y' WHERE purchased = 'N' OR purchased = '' OR purchased IS NULL"; $statementSetToN = $conn->prepare($sqlSetToN); $statementSetToY = $conn->prepare($sqlSetToY); /*** loop through the results/collection of checked items ***/ foreach($result as $row) { if ($row["purchased"] != "Y") { // *** fetch one row at a time pertaining to the 2nd query *** // $resultSetToY = $statementSetToY->fetch(); foreach($resultSetToY as $row) { $statementSetToY->execute(); } } else { // *** fetch one row at a time pertaining to the 2nd query *** // $resultSetToN = $statementSetToN->fetch(); foreach($resultSetToN as $row) { $statementSetToN->execute(); } } } break; }CRUD Queston.png 20.68KB 0 downloads If you also have any feedback on my code, please do tell me. I wish to improve my coding base. Basically when you fill out the register form, it will check for data, then execute the insert query. But for some reason, the query will NOT insert into the database. In the following code below, I left out the field ID. Doesn't work with it anyways, and I'm not sure it makes a difference. Code: Code: [Select] mysql_query("INSERT INTO servers (username, password, name, type, description, ip, votes, beta) VALUES ($username, $password, $name, $server_type, $description, $ip, 0, 1)"); Full code: Code: [Select] <?php include_once("includes/config.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title><? $title; ?></title> <meta http-equiv="Content-Language" content="English" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" type="text/css" href="style.css" media="screen" /> </head> <body> <div id="wrap"> <div id="header"> <h1><? $title; ?></h1> <h2><? $description; ?></h2> </div> <? include_once("includes/navigation.php"); ?> <div id="content"> <div id="right"> <h2>Create</h2> <div id="artlicles"> <?php if(!$_SESSION['user']) { $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); $name = mysql_real_escape_string($_POST['name']); $server_type = mysql_real_escape_string($_POST['type']); $description = mysql_real_escape_string($_POST['description']); if(!$username || !$password || !$server_type || !$description || !$name) { echo "Note: Descriptions allow HTML. Any abuse of this will result in an IP and account ban. No warnings!<br/>All forms are required to be filled out.<br><form action='create.php' method='POST'><table><tr><td>Username</td><td><input type='text' name='username'></td></tr><tr><td>Password</td><td><input type='password' name='password'></td></tr>"; echo "<tr><td>Sever Name</td><td><input type='text' name='name' maxlength='35'></td></tr><tr><td>Type of Server</td><td><select name='type'> <option value='Any'>Any</option> <option value='PvP'>PvP</option> <option value='Creative'>Creative</option> <option value='Survival'>Survival</option> <option value='Roleplay'>RolePlay</option> </select></td></tr> <tr><td>Description</td><td><textarea maxlength='1500' rows='18' cols='40' name='description'></textarea></td></tr>"; echo "<tr><td>Submit</td><td><input type='submit'></td></tr></table></form>"; } elseif(strlen($password) < 8) { echo "Password needs to be higher than 8 characters!"; } elseif(strlen($username) > 13) { echo "Username can't be greater than 13 characters!"; } else { $check1 = mysql_query("SELECT username,name FROM servers WHERE username = '$username' OR name = '$name' LIMIT 1"); if(mysql_num_rows($check1) < 0) { echo "Sorry, there is already an account with this username and/or server name!"; } else { $ip = $_SERVER['REMOTE_ADDR']; mysql_query("INSERT INTO servers (username, password, name, type, description, ip, votes, beta) VALUES ($username, $password, $name, $server_type, $description, $ip, 0, 1)"); echo "Server has been succesfully created!"; } } } else { echo "You are currently logged in!"; } ?> </div> </div> <div style="clear: both;"> </div> </div> <div id="footer"> <a href="http://www.templatesold.com/" target="_blank">Website Templates</a> by <a href="http://www.free-css-templates.com/" target="_blank">Free CSS Templates</a> - Site Copyright MCTop </div> </div> </body> </html> I'm using php edit function to edit an php file online. I think the portion that writing the file is below. My issue is that wherever there's a quote ("), it's automatically adding a slash (\). For example, if I had class="abc", it changes to class=\"abc\". How do I fix this? Code: [Select] <?php $file = $_GET['f']; $script = $_POST['script']; if($file&&$script) { $fp=fopen($file, "w"); fwrite($fp,$script); fclose($fp); } ?> hello mates, I am needing help on editing a line in Flat File Database. I got it to pull the data i need out by using id but not sure on how i would go about getting it to update the FFD heres what i got so far $id2 = $_REQUEST['id']; $id = array(); $username = array(); $title = array(); $date = array(); $message = array(); $lines = file('../news/news.db'); foreach($lines as $line){ if($id != $id2) { $explode = explode("||",$line); $id = $explode[0]; $username = $explode[1]; $title = $explode[2]; $date = $explode[3]; $message = $explode[4]; } } ?> <form action="edit_news2.php?id=<?php echo $id; ?>" method="post" name="editnews"> <table width="100%"> <tr><td><input name="id" value="<?php echo "$id;" ?>" type="hidden" />UserName:</td><td> <input name="userName" value="<?php echo "$username" ?>" type="text" readonly="true" /></td></tr> <tr><td>News Title:</td><td> <input name="title" type="text" value="<?php echo "$title"; ?>" /></td></tr> <tr><td>Date/Time:</td><td> <input name="datetime" value="<?php echo "$date"; ?>" type="text" readonly="true" /></td></tr> <tr><td colspan="2">Message:</td></tr> <tr><td colspan="2"><textarea name="message" cols="50" rows="15"><?php echo "$message"; ?></textarea></td></tr> <tr><td colspan="2" align="center"><input type="submit" name="submitBtn" value="Post News" /></td></tr> </table> </form> thank you Valkeri2010 I'm so sorry to ask such a "newbee question," but believe me I have been on Google for the better part of the week trying to find an answer.
I'll start with the brief question.
Then I'll give an example to show what I mean.
Then, I'll give the BESTEST "pseudo-code" I could come up with (to PROVE that I've really given it my best).
Question:
How do I make PHP loop through a big file, make the changes line by line, and to save the resultant file.
Example: I have a 100mb text file ("animals.txt") with 500,000 lines. If any lines have the word "cat" in it, I want to add "Be careful with cats!" to the end of the line:
From this:
A fish and his tank.
A cat and his toy.
A bird and her cage.
A frog and his lilly.
A cat and her friend.
To this:
A fish and his tank.
A cat and his toy. Be careful with cats!
A bird and her cage.
A frog and his lilly.
A cat and her friend. Be careful with cats!
The best "pseudo-code" I can come up with is:
<?php
$data = file_get_contents("animals.txt");
$lines = explode(PHP_EOL,$data); I'm trying to update every record where one field in a row is less than the other. The code gets each row i'm looking for and sets up the query right, I hope I combined the entire query into one string each query seperated by a ; so it's like UPDATE `table` SET field2= '1' WHERE field1= '1';UPDATE `table` SET field2= '1' WHERE field1= '2';UPDATE `table` SET field2= '1' WHERE field1= '3';UPDATE `table` SET field2= '1' WHERE field1= '4';UPDATE `table` SET field2= '1' WHERE field1= '5'; this executes properly if i run the query in phpMyAdmin, however when I run the query in PHP, it does nothing... Any advice? I was just wondering if it's possible to run a query on data that has been returned from a previous query? For example, if I do Code: [Select] $sql = 'My query'; $rs = mysql_query($sql, $mysql_conn); Is it then possible to run a second query on this data such as Code: [Select] $sql = 'My query'; $secondrs = mysql_query($sql, $rs, $mysql_conn); Thanks for any help Say I have this query: site.com?var=1 ..I have a form with 'var2' field which submits via get. Is there a way to produce: site.com?var=1&var2=formdata I was hoping there would be a quick way to affix, but can't find any info. Also, the query could sometimes be: site.com?var2=formdata&var=1 I would have to produce: site.com?var2=updatedformdata&var=1 Is my only option to further parse the query? Hi. I am working on a website that has restriction level. An admin, a staff, and ordinary user. In my admin page when I click the button "View Users" it shows all the listed users in a table, from admin to ordinary users. And on each entry is an option to either "Delete" or "Edit" the users account. Now I have a problem with editing user profile because it appears blank fields. Not like in the admin side wherein if I click "Edit" the fields are filled with the users info. How do I do this in the staff's page. Here is the view users code from the admin's page: Code: [Select] if (@$_GET['action'] == "View Users") { print "<font size=6 color=yellow><center>View User's Records</center><br></font>"; $result = mysql_query ("SELECT * FROM users order by user_lvl, lname asc"); $rows = mysql_num_rows($result); if ($rows!=0) { print "<table border=1 align=center cellspacing=10>"; print " <tr bgcolor=yellow align=center> <td>First Name</td> <td>Last Name</td> <td>Email</td> <td>Username</td> <td>Password</td> <td>Phone Number</td> <td>User Privilege</td> <td>Options</td> </tr>"; for ($i=0; $i< $rows; $i++) { $row = mysql_fetch_row ($result); print "<tr bgcolor= white align=center>"; print "<td>$row[0]</td>"; print "<td>$row[1]</td>"; print "<td>$row[2]</td>"; print "<td>$row[3]</td>"; print "<td>$row[4]</td>"; print "<td>$row[5]</td>"; print "<td>$row[6]</td>"; print "<td>[ <a href=admin_main.php?action=Delete&username=$row[3]>Delete</a> ]"; print "[ <a href=admin_main.php?action=Edit&username=$row[3]>Edit</a> ]"; print "</td>"; print "</tr>"; } print "</table>"; print "<font size=1 color=yellow>Number of entries found: $rows"; } else { print "No records found!"; } mysql_free_result ($result); } Now here is the code when I click "Edit" from the "View Users" table: Code: [Select] if (@$_GET['action'] == "Edit") { $result = mysql_query ("Select * from users where username='$_GET[username]'"); $row = mysql_fetch_row ($result); print "<font size=6 color=yellow><center>Edit Records </center></font>"; print "<form method = get> <table border = 1 align=center> <tr> <td><font color=yellow>First Name:</font></td> <td><input type=text name=fname value=$row[0] ></td></tr> <tr> <td><font color=yellow>Last Name:</font></td> <td><input type=text name=lname value=$row[1]></td></tr> <tr> <td><font color=yellow>Email Address: </font></td> <td><input type=text name=email value=$row[2] </td></tr> <tr> <td><font color=yellow>Username: </font></td> <td><input type = text name = username value=$row[3] ></td></tr> <tr> <td><font color=yellow>Password:</font></td> <td><input type=text name=password value=$row[4]></td></tr> <tr> <td><font color=yellow>Contact Number:</font></td> <td><input type = text name = phone_number value=$row[5]></td></tr> <tr> <td><font color=yellow>User Privilege:</font></td> <td><input type = txt name = user_lvl value=$row[6]></td></tr> <tr><td><input type=submit value='Update Users' Submit name=action></td></tr> </table> </form> "; } if (@$_GET['action']=="Update Users") { $result = mysql_query ("UPDATE users SET fname='$_GET[fname]', lname='$_GET[lname]', email='$_GET[email]', username='$_GET[username]', password='$_GET[password]', phone_number='$_GET[phone_number]', user_lvl='$_GET[user_lvl]' where username= '$_GET[username]'"); print "<font size=6 color=yellow><center><blink>Record of User successfully updated!</blink></center></font>"; } |