PHP - Add A Extra Word In Links
Hello
I was wondering if anyone could help me. I have bought a script that are encoded is something that i cant change or read, and i have ask the owner how to put a {user} at the end of every hyperlink so are going to a other site, but he said you need a external script to do that. So was wondering if anyone could help me. Im using a database where all the user are etc But If i go to google.com and login as Bobmartin I will be at google.com/home Then i click on a hyperlink inside google.com/home that will bring me to a other side Lets say the hyperlink (other site) is www.phpfreaks.com/profile/ So when i begining to redirect to www.phpfreaks.com/profile/ the script will add {user} from the database So at the end i will be redirect to www.phpfreaks.com/profile/Bobmartin The hyperlink is generated in a unique code so i cant just add {user} it must be a external script i need to use. So to say it fast I want to add /{user} for every hyperlink that is redirect to another site without add {user} direct to the hyperlink for example www.google.com/{user}, the hyperlink must me www.google.com Well i hope you guys understand this, im not the best person to explain things so Also my english suck so dont judge me Similar TutorialsI've got a page with pagination set up, but I can't figure out where I went wrong with the links at the bottom. When I do a search, it generates the proper number of links, but clicking on the links goes to a page with a whole row of 20 links at the bottom and no results on the page. (my search should show 3 pages with 2 records on each page) I've looked through the tutorial here and one in a book on pagination. Not seeing what's wrong. I'd narrow this down if I knew where it was causing the problem. pagination links are at the very bottom of the code. Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html><head> <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"><title>search.html</title></head> <body> <center> <p>The results of your search:</p> <br> </center> require ('databaseconnect.php'); $select = mysql_select_db($db, $con); if(!$select){ die(mysql_error()); } $display = 2; if (isset($_GET['np'])) { $num_pages = $_GET['np']; } else { $data = "SELECT COUNT(*) FROM descriptors LEFT JOIN plantae ON (descriptors.plant_id = plantae.plant_name) WHERE `leaf_shape` LIKE '%$select1%' AND `leaf_venation` LIKE '%$select3%' AND `leaf_margin` LIKE '%$select4%'"; $result = mysql_query ($data); if (!$result) { die("Oops, my query failed. The query is: <br>$data<br>The error is:<br>".mysql_error()); } $row = mysql_fetch_array($result, MYSQL_NUM); // row 41 $num_records = $row[0]; if ($num_records > $display) { $num_pages = ceil ($num_records/$display); } else { $num_pages = 1; } } if (isset($_GET['s'])) { $start = $_GET['s']; } else { $start = 0; } if(isset($_POST[submitted])) { // Now collect all info into $item variable $shape = $_POST['select1']; $color = $_POST['select2']; $vein = $_POST['select3']; $margin = $_POST['select4']; // This will take all info from database where row tutorial is $item and collects it into $data variable row 55 $data = mysql_query("SELECT `descriptors`.* ,`plantae`.* FROM `descriptors` LEFT JOIN `plantae` ON (`descriptors`.`plant_id` = `plantae`.`plant_name`) WHERE `leaf_shape` LIKE '%$select1%' AND `leaf_venation` LIKE '%$select3%' AND `leaf_margin` LIKE '%$select4%' ORDER BY `plantae`.`scientific_name` ASC LIMIT $start, $display"); //chs added this in... row 72 echo '<table align="center" cellspacing="0" cellpading-"5"> <tr> <td align="left"><b></b></td> <td align="left"><b></b></td> <td align="left"><b>Leaf margin</b></td> <td align="left"><b>Leaf venation</b></td> </tr> '; // This creates a loop which will repeat itself until there are no more rows to select from the database. We getting the field names and storing them in the $row variable. This makes it easier to echo each field. while($row = mysql_fetch_array($data)){ echo '<tr> <td align="left"> <a href="link.php">View plant</a> </td> <td align="left"> <a href="link.php">unknown link</a> </td> <td align="left">' . $row['scientific_name'] . '</td> <td align="left">' . $row['common_name'] . '</td> <td align="left">' . $row['leaf_shape'] . '</td> </tr>'; } echo '</table>'; } if ($num_pages > 1) { echo '<br /><p>'; $current_page = ($start/$display) + 1; // row 100 if ($current_page != 1) { echo '<a href="leafsearch2a.php?s=' . ($start - $display) . '&np=;' . $num_pages . '">Previous</a> '; } for ($i = 1; $i <= $num_pages; $i++) { if($i != $current_page) { echo '<a href="leafsearch2a.php?s=' . (($display * ($i - 1))) . '$np=' . $num_pages . '">' . $i . '</a>'; } else { echo $i . ' '; } } if ($current_page != $num_pages) { echo '<a href="leafsearch2a.php?s=' . ($start + $display) . '$np=' . " " . $num_pages . '"> Next</a>'; } } ?> </body></html> <html> <?php $id = $_GET['id']; $dbusername="web148-matt"; $dbpassword="matt"; $dbdatabase="web148-matt"; mysql_connect(localhost,$dbusername,$dbpassword); @mysql_select_db($dbdatabase) or die( "Unable to select database"); mysql_query("UPDATE count SET clicks=clicks+1 WHERE id='$id'"); $sql = mysql_query("SELECT link FROM count WHERE id='$id'"); $fetch = mysql_fetch_row($sql); $result = mysql_query("SELECT * FROM count"); while($row = mysql_fetch_array($result)) { echo "<a href=" .$row['link']. ">Link</a>"; } ?> <a href='http://www.google.com'>Google</a> <a href='/index.php?id=2'>link2</a> </html> I have several lines of text formatted as such: Code: [Select] title text – some more text blah blah blah How do I delete everything after title text from every line ( the and ndash and after)? Thanks! Hi there I followed this post http://www.phpfreaks.com/forums/index.php?topic=95426.0 to get a multi-column layout of search results. All's well but I seem to have an extra blank row at the bottom of the table. This is my code for the table Code: [Select] echo '<table width="800px" class="center" border="1">'; echo '<td>'; if($result && mysql_num_rows($result) > 0) { $i = 0; $max_columns = 3; while ($list = mysql_fetch_array($result)) { // make the variables easy to deal with extract($list); // open row if counter is zero if($i == 0) echo "<tr>"; echo '<td><a href="word.php?w=' . $list['word'] . '">' . $list['word'] . '</a></td>'; // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } // end while } // end if results // clean up table - makes your code valid! if($i < $max_columns) { for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; } echo '</tr>'; echo '</table>'; Any ideas on how not to have it there? Thanks in advance. for($i=1; $i<=$round; $i++){ print "<tr><td align='left' valign='top'><input type='text' name='number$i' maxlength='2' size='2' /></td>\n "; print "<td align='left' valign='top'><input type='text' name='score$i' maxlength='1' size='1' /></td>\n "; print "<td align='left' valign='top'><select name='team$i'>\n"; print "<option value='-'>-<option>\n"; print "<option value='Home'>Home<option>\n"; print "<option value='Away'>Away<option>\n"; print "</select></td></tr>"; }What I'm having trouble with is that for every option tag there is an empty option tag added. How do I get rid of those empty option tags? Thankful for any help. I have an email form that I use to generate email messages to a club distribution list. I add the body of the message from a form that sends that message to a php script. The emails are a mix of html directly from the script as well as what is sent to the script from the web page form. Example: $mailmessage = '<html><body>header of message' . $MessageFromForm . 'footer of message </body></html>'; **where $MessageFromForm is requested from the form and is the body of the email message. The html header and footer of the message look fine, but the code that came from my html form does not work properly. That code replaces a ' with \', and the html tags do not work. I do have the following included in my headers: $headers = "MIME-Version: 1.0" . "\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\n"; Any ideas on what could cause this? Hello PHPFreaks! I have a question for somebody to answer Code: [Select] <?php //This is the directory where images will be saved $target = "gallery/"; $target = $target . basename( $_FILES['photo']['name']); //This gets all the other information from the form $username=$_POST['username']; $photo=($_FILES['photo']['name']); $caption=$_POST['caption']; $ip=$_POST['ip']; //Writes the information to the database mysql_query("INSERT INTO `photo` (username, photo, caption, ip) VALUES ('$username', '$photo', '$caption', '$ip')") ; //Writes the photo to the server if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { //Tells you if its all ok echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your caption has been added to the directory"; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } ?> When pictures are uploaded; they upload the name they have named them. Is it possible to add to the script $username somewhere to the file name? For example; DSC_0077_SOLAR.JPG Thanks for your time! Hi i've recently moved hosting servers as I had severe lag issues with my shared hosting. Since i've brought a dedicated linux server with apache and php. Since the move i get extra chars with the following code Code: [Select] <?PHP define( "MESSAGE", "Testing Testing 123" ); if(isset($_GET['message'])) { die(MESSAGE); } ?> My application SHOULD receive back "Testing Testing 123" like it used to with my old shared hosting. Instead now it receives the following: Code: [Select] 2f Testing Testing 123 0 And i cannot figure this out for the life of me. I'm expecting something silly to be the cause but would appreciate some guidance on this. Thanks So I'm generating an XML response for Google Maps and this is how my method looks:
/* * Generate XML for google maps * @param results Database results array */ public function generate_xml(array $results) { // Start XML file, create parent node $dom = new DOMDocument("1.0"); $node = $dom->createElement("markers"); $parnode = $dom->appendChild($node); header("Content-type: text/xml"); /* * Iterate through the rows, adding XML nodes for each * Have to do it the ugly way so results aren't pulled twice * (xml and php can't be passed within same array because headers are changed) */ foreach ($results as $row){ $node = $dom->createElement("marker"); $newnode = $parnode->appendChild($node); $newnode->setAttribute('id', $row['id']); $newnode->setAttribute('logo', $row['logo']); $newnode->setAttribute("name", $row['name']); $newnode->setAttribute("address", $row['address']); $newnode->setAttribute('city', $row['city']); $newnode->setAttribute('state', $row['state']); $newnode->setAttribute('zip', $row['zip']); $newnode->setAttribute('phone', $row['phone']); $newnode->setAttribute('email', $row['email']); $newnode->setAttribute('web_link', $row['web_link']); $newnode->setAttribute("lat", $row['lat']); $newnode->setAttribute("lng", $row['lng']); $newnode->setAttribute("distance", $row['distance']); } return $dom->saveXML(); }However, I'm getting this error: This page contains the following errors: error on line 2 at column 1: Extra content at the end of the document So I have been working on my website for a while which all is php&mysql based, now working on the social networking part building in similar functions like Facebook has. I encountered a difficulty with getting information back from a link. I've checked several sources how it is possible, with title 'Facebook Like URL data Extract Using jQuery PHP and Ajax' was the most popular answer, I get the scripts but all of these scripts work with html links only. My site all with php extensions and copy&paste my site links into these demos do not return anything . I checked the code and all of them using file_get_contents(), parsing through the html file so if i pass 'filename.php' it returns nothing supposing that php has not processed yet and the function gets the content of the php script with no data of course. So my question is that how it is possible to extract data from a link with php extension (on Facebook it works) or how to get php file executed for file_get_contents() to get back the html?
here is the link with code&demo iamusing: http://www.sanwebe.c...-php-and-jquery
thanks in advance.
Here is the issue: I am creating an input form which would allow someone to check multiple boxes. These checkboxes are populated from a table called reasonforcare. Here is my code: Quote <?php $rows = mysql_num_rows($reasonforcare); for ($i=0; $i < $rows; ++$i) { $row = mysql_fetch_row($reasonforcare); echo "<input name='reasonforcare' type='checkbox' value='" . $row[0] . "'/>"; echo $row[1]; } ?> I get all the checkboxes to show up, but at the end of the last database entry there is an extra checkbox! Can someone help me figure out why this is happening? Hi, thanks for reading this! I need some help with my pagination, maybe the answer is very simple but I've tried a lot of coding including work with tables but it didn't work It's about my page (in Dutch) where I show images of collections. A page looks like this: http://www.verzamelaars.net/mobach/index.php Now I want the name of the collector under the image, but every time I get this: http://www.verzamelaars.net/mobach/index2.php The code I use now is: <?php while($row = mysql_fetch_array($result)) { echo "<table><tr><td><a href='{$row['mijnlink']}'><img src={$row['thumb']} hspace=1 vspace=4></a></td></tr>"; echo "<tr><td><a href='{$row['verzamelaarlink']}'>{$row['verzamelaar']}</a></td></tr></table>"; } ?> I've been playing with the table but so far no good, hope you can help me with this! Kind regards, Arjen van Dorsten Can anyone tell me what's making this code put an extra entry in the database?Whatever the number of looped students being added, it adds another row with nothing but the registrationid entered. Code: [Select] <?php // connect to database include("databaseconn.php"); // store all posted intemnos and descriptions in local arrays $fname = $_POST['fname']; $lname = $_POST['lname']; $phone = $_POST['phone']; $email = $_POST['email']; $bdate = $_POST['bdate']; $bdate2 = $_POST['bdate2']; $bdate3 = $_POST['bdate3']; $wid = $_POST['wid']; $rid = $_POST['reg_id']; $reg_alone = $_POST['reg_alone']; $_SESSION['workshops']=$wid; ?> <? if(sizeof($_POST['fname'])) { // loop through array $number = count($fname); for ($i=0; $i<=$number; $i++) { // store a single item number and description in local variables $fnames = $fname[$i]; $lnames = $lname[$i]; $phones = $phone[$i]; $emails = $email[$i]; $bdates = $bdate[$i]; $bdates2 = $bdate2[$i]; $bdates3 = $bdate3[$i]; $wids = $wid[$i]; $rids = $rid[$i]; echo "echod ".$bdates2."and<br>"; print_r($bdates2); $query_insertItemWorkshop = "INSERT INTO tbl_attendees (attendee_fname, attendee_lname, attendee_registrationid, workshop_id, attendee_email, attendee_telephone, attendee_bday, attendee_bmonth, attendee_byear) VALUES ('$fnames', '$lnames', '$reg_alone', '$wids', '$emails', '$phones', '$bdates', '$bdates2', '$bdates3')"; echo "query: ".$query_insertItemWorkshop; $dberror = ""; $ret = mysql_query($query_insertItemWorkshop); } } ?> I shouldn't even be posting this but I"m tired and want to get this last part done by the end of the night. This script works however with the echoed "sortorder" its getting in the way of what's echoed for the submitmenuitem because its showing up as say 1good after form submission and not sure how to get it to not show up like that after form submission because that sortorder is getting echoed on document is ready. <?php // Include the database page require ('../inc/dbconfig.php'); if ( isset( $_POST['menuid'] ) ) { $menuid = (int)$_POST['menuid']; $query = "SELECT COUNT(sortorder) AS numOrder FROM `menuitems` WHERE `menu_id` = '".$menuid."'"; $result = mysqli_query ($dbc, $query); $row = mysqli_fetch_array( $result, MYSQL_ASSOC ); $sortorder = $row[ 'numOrder' ] + 1; echo $sortorder; } if (isset($_POST['submitmenuitem'])) { $menuid = mysqli_real_escape_string($dbc, $_POST['menuid']); $itemname = mysqli_real_escape_string($dbc, $_POST['itemname']); $itemurl = mysqli_real_escape_string($dbc, $_POST['itemurl']); $sortorder = mysqli_real_escape_string($dbc, $_POST['sortorder']); $contentpage = mysqli_real_escape_string($dbc, $_POST['contentpage']); $newscategory = mysqli_real_escape_string($dbc, $_POST['newscategory']); $application = mysqli_real_escape_string($dbc, $_POST['application']); $query = "SELECT * FROM `menuitems` WHERE (`itemname` = '".$itemname."') OR (`itemurl` = '".$itemurl."') OR (`contentpage_id` = '".$contentpage."') OR (`application_id` = '".$application."') OR (`newscategory_id` = '".$newscategory."')"; $result = mysqli_query ( $dbc, $query ); // Run The Query $rows = mysqli_num_rows($result); if ($rows == 0) { $query = "INSERT INTO `menuitems` (menu_id, itemname, itemurl, sortorder, contentpage_id, newscategory_id, application_id, creator_id, datecreated, enabled) VALUES ('".$menuid."','".$itemname."','".$itemurl."','".$sortorder."','".$contentpage."', '".$newscategory."', '".$application."', 1, NOW(), 0)"; mysqli_query($dbc, $query); echo "good"; } else { $row = mysqli_fetch_array($result); if (($row['itemname'] == $itemname) && ($row['itemurl'] == $itemurl) && ($row['contentpage_id'] == $contentpage) && ($row['application_id'] == $application) && ($row['newscategory_id'] == $newcategory)) echo 'bad6'; elseif ($row['newscategory_id'] == $newscategory) echo 'bad5'; elseif ($row['application_id'] == $application) echo 'bad4'; elseif ($row['contentpage_id'] == $contentpage) echo 'bad3'; elseif ($row['itemurl'] == $itemurl) echo 'bad2'; elseif ($row['itemname'] == $itemname) echo 'bad1'; } } EDIT. When starting this post, I thought it was causing the browser to make an extra request to the server. I've since found this wasn't the case, however, didn't change the title of this post, and can't seem to change it to something like "Critique of file caching script"
I am trying to cache a file, and put together the following script. I put the following in the browser:
https://test.sites.example.com/administrator/index.php?cid=2&controller=sell&id=643341356... and Apache will rewrite as: https://test.sites.example.com/index.php?admin=administrator&cid=2&controller=sell&id=643341356index.php includes the following line: <script src="/lib/js/clientConstants.php?b=1" type="text/javascript"> Hey guys! I have the following doubt, I have a Date value and I want to add to that date 30 seconds plus. Example: Code: [Select] $last_time = date('D M j H:i:s \G\M\TO Y'); //echo: Thu Mar 10 18:33:48 GMT-0300 2011 I need the following date: Thu Mar 10 18:33:48 GMT-0300 2011 to become: Thu Mar 10 18:34:18 GMT-0300 2011 This means that the retrieved Date now has 30 more seconds... Any ideas?? Looking forward to any help, Thanks a lot in advance, Cheers! Hey Guys, I've got a small script that displays latest news. It is supposed to show just the title of the news item in a list, however it shows the content at the bottom of the code... This is my page <ul> <?php $args= array( 'news_items' => 500, 'title' => TRUE, 'content' => FALSE, 'before_title' => '<li>', 'after_title' => '</li>' ); jep_latest_news_loop($args); echo '</ul>'; ?> <br>TEST<br> But this is the output Quote * February 2011 Newsletter * January 2011 Newsletter * December 2010 Newsletter * November 2010 Newsletter * October 2010 Newsletter * New Website Launched TEST February 2011 Newsletter January 2011 Newsletter December 2010 Newsletter November 2010 Newsletter October 2010 Newsletter XXX XXXXX are pleased to announce the launch their new website today. We hope you find it easy to use and informative. Please feel free to contact us with any queries. This is the code generator page <?php add_action('init', 'jep_latest_news_init'); function jep_latest_news_init() { // Create new Latest-News custom post type $labels = array( 'name' => _x('Latest News', 'post type general name'), 'singular_name' => _x('Latest News', 'post type singular name'), 'add_new' => _x('Add New', 'Latest News'), 'add_new_item' => __('Add New Latest News'), 'edit_item' => __('Edit Latest News'), 'new_item' => __('New Latest News'), 'view_item' => __('View Latest News'), 'search_items' => __('Search Latest News'), 'not_found' => __('No Latest News found'), 'not_found_in_trash' => __('No Latest News found in Trash'), '_builtin' => false, 'parent_item_colon' => '' ); $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'exclude_from_search' => false, 'show_ui' => true, 'query_var' => true, 'rewrite' => true, 'capability_type' => 'post', 'hierarchical' => false, 'menu_position' => 20, 'supports' => array('title','editor','author','thumbnail','excerpt','comments'), 'taxonomies' => array('category', 'post_tag') ); register_post_type('latest-news',$args); } /* Template function to output the latest news stories */ function jep_latest_news_loop($args = null) { $defaults = array( 'news_items' => 500, 'title' => TRUE, 'content' => FALSE, 'before_title' => '<li class="h3">', 'after_title' => '</li>', ); global $paged; $r = wp_parse_args( $args, $defaults ); $qargs=array( 'post_type'=>'latest-news', //'posts_per_page' => $r[news_items], //'paged' => $paged ); query_posts($qargs); while ( have_posts() ) : the_post(); ?> <?php echo($r[before_title]);?> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <?php echo($r[after_title]);?> <?php endwhile; } ?> Any ideas what is dumping the extra code? I am building a login script to help myself learn php. I currently have the script posting any registration form errors to the registration page. I am trying to make sure whatever the user has typed into the form will redisplay once they receive the error to prevent them from having to fill out the registration form again. I got it working, but there is an extra character "/" after what was entered by the user. Here is an example: Note: "1234" has been entered into username field on reg form. Code: [Select] <tr><td>Username: </td><td><input size="20" type="text" name="username" <?php if ($_POST){ echo "value =" . $_POST['username'] ;}?> /></td></tr> I get this output Code: [Select] 1234/ I do not know where the "/" is coming from. It should only be putting "1234" back into the username field. Any help would be great. Hi everyone, I used to know the function, but it was a very long time ago, for when you need to just extract a single value from a query... instead of having to use mysql_fetch_assoc in a while loop to build an array... e.g. Code: [Select] $TheResultingFieldValue = mysql_fetch_SOMETHING(mysql_query("SELECT aField FROM aTable WHERE anotherField = 'aCondition'"));
Sometimes my 3 column .csv file has commas within quotes: When I use this code, I need the data count to stay the same "3" for each row: while (($data = fgetcsv($handle,2000,',')) !== FALSE) { print count($data); // prints "3" ... then prints "4" .... then prints "3" }
Thank you. Edited April 15, 2020 by StevenOliver |