Jump to content

bluebyyou

Members
  • Posts

    234
  • Joined

  • Last visited

    Never

Everything posted by bluebyyou

  1. <?php $str = "Some {sample|example|variable} text. More {text|things|stuff} text."; $pattern ="/\{.*\}/is"; preg_match_all($pattern, $str, $matches); foreach ($matches as $val) { print_r($val); } ?> It outputs: Array ( [0] => {sample|example|variable} text. More {text|things|stuff} ) ------------- What I want the output to be is each string between the {}'s to be parsed out individually, I just am having a hell of a time writing the proper regular expression. Can someone point me in the right direction?
  2. thorpe, I did not need that, it was my attempt at a solution that did not work. Dragen, that did the trick, thanks.
  3. I have my rewrite rules working how I want them, however my links that I am dynamically creating are not for example my link is: www.website.com/article/1/1. when i click a link on that page it becomes: www.website.com/article/1/1/article/1/1 and if i click it a third time it becomes: www.website.com/article/1/1/article/1/1/article/1/1 and so on... the current path repeats it self over everytime I click it Here are my rewrite rules... RewriteEngine On RewriteRule ^article/([0-9]+)/([0-9]+)$ article.php?categoryID=$1&articleID=$2 [NC] RewriteRule ^article/([0-9]+)$ article.php?categoryID=$1 [NC,L] here is a sample of me creating a link echo "<h3><a href='../article/".$display_category['category_id']."'>".$display_category['category_title']."</a></h3>\n"; //Show Category Title also i tried using ../../ etc in front of the links, but then the more you click the the link the farther back in the directory it goes. so that didnt work either.
  4. I finally figured it out, all I had to do was set the LIMIT on the preg_replace function to replace one image tag at a time. Here is the code if anyone is interested. What it does is parse text, like a content management system might, and also replaces a number tags from an array of image names. <?php function code_format ($str,$images) { //remove html tags $str = htmlentities($str); $tag_identifiers = array( '/\[b\](.*?)\[\/b\]/is' => '<strong>$1</strong>', '/\[i\](.*?)\[\/i\]/is' => '<em>$1</em>', '/\[u\](.*?)\[\/u\]/is' => '<u>$1</u>', //'/\[url\=(.*?)\](.*?)\[\/url\]/is' => <a href="$1">$2</a>', //'/\[url\](.*?)\[\/url\]/is' => '<a href="$1">$1</a>, //'/\[align\=(left|center|right)\](.*?)\[\/align\]/is' => '<div style="text-align: $1;">$2</div>', //'/\[img\](.*?)\[\/img\]/is' => '<img src="$1" />', //'/\[mail\=(.*?)\](.*?)\[\/mail\]/is' => '<a href="mailto:$1">$2</a>', //'/\[mail\](.*?)\[\/mail\]/is' => '<a href="mailto:$1">$1</a>', //'/\[font\=(.*?)\](.*?)\[\/font\]/is' => '<span style="font-family: $1;">$2</span>', //'/\[size\=(.*?)\](.*?)\[\/size\]/is' => '<span style="font-size: $1;">$2</span>', //'/\[color\=(.*?)\](.*?)\[\/color\]/is' => '<span style="color: $1;">$2</span>', //'/\[img\]/is' => '%s', '/\[ret\]/is' => '<br /><br />', ); // Do simple tag replacements $str = preg_replace (array_keys($tag_identifiers), array_values($tag_identifiers), $str); // Do image replacements foreach ($images as $key => $value) { $str = preg_replace ('/\[img\]/is', "<img src='".$value."' />" , $str, 1); } echo $str; } $images = array('1.jpg','2.jpg','3.jpg','4.jpg','5.jpg'); $text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin sit amet risus enim. Nunc urna libero, porta eu tristique vel, porta vel est. Phasellus imperdiet commodo mauris sit amet eleifend. Fuscemi sem, suscipit sed rhoncus a, egestas sed nisl. Phasellus cursus eleifend congue. Vestibulum sit amet ante blandit massa aliquam porta. [img] Nulla lacinia purus non justo iaculis ultrices. Nunc sollicitudin odio sed ligula hendrerit vel euismod turpis porttitor. [b]Pellentesque suscipit[/b], tellus quis gravida blandit, quam tellus posuere ante, ut egestas odio erat nec augue. Praesent hendrerit mi sed metus suscipit hendrerit. Sed non ullamcorper ante. Phasellus nibh mauris, placerat at sodales non, tempus id dolor. In ullamcorper urna purus.[ret]\n\n". "Duis suscipit leo eget eros accumsan in auctor dui placerat. Quisque id dui quam, porttitor varius nisi. Maecenas vestibulum sagittis neque vitae blandit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed tortor mi, sodales vitae fringilla commodo, pellentesque sit amet nisl. Proin aliquam metus in velit blandit at molestie sapien dapibus. Ut sollicitudin lectus id massa suscipit lacinia. Sed ante felis, ultrices et iaculis nec, tristique at sem. Donec a augue et orci convallis semper. [img] Vestibulum mi neque, accumsan vel suscipit quis, cursus quis lacus. Vivamus vulputate cursus odio, eget cursus urna consequat vitae. Cras laoreet iaculis quam commodo malesuada. [i]Praesent scelerisque laoreet nisl, eu tempor diam gravida et. Ut dictum sodales nisi[/i]. Morbi viverra ornare porttitor. Ut pretium urna sed arcu venenatis et ultricies elit aliquam. Ut ut sollicitudin neque. Praesent orci magna, convallis et cursus vitae, ornare eget erat. Integer id est nec odio pulvinar tincidunt.[ret]\n\n". "Praesent id sapien libero, sit amet tincidunt lorem. Quisque volutpat nisi a tortor fringilla et scelerisque enim dignissim. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Suspendisse non mollis nunc. Duis vel molestie magna. Praesent nisi elit, posuere vel convallis id, mollis vitae dui. Vivamus aliquet semper dapibus. In ultricies molestie convallis. Vivamus hendrerit tellus venenatis lorem vulputate at interdum sapien dictum. Sed urna neque, facilisis et posuere nec, sodales rutrum nisi. [img] Suspendisse potenti. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; [u]In id mi eros, a iaculis arcu[/u]. Maecenas consequat consequat congue. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Etiam blandit, nunc vitae sodales rutrum, nisi neque viverra massa, vulputate venenatis elit lacus vitae arcu. Curabitur at ante ipsum. Quisque sodales mauris a arcu sodales nec fringilla lacus interdum. In in lobortis dui. In malesuada, diam ac auctor interdum, massa nibh scelerisque augue, et tincidunt lectus purus eget lectus.[ret]\n\n". "Aliquam adipiscing tincidunt posuere. Suspendisse non purus nisl, at dapibus sapien. Maecenas posuere urna ac nibh scelerisque malesuada. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Phasellus sed nibh tortor, ac porta orci. Mauris ac turpis vitae libero vehicula pellentesque. Quisque vel urna sed magna pellentesque varius a et ligula. Proin ultricies magna at nibh auctor imperdiet. Nullam sed erat mauris, id laoreet augue. Pellentesque enim est, accumsan varius mattis ac, convallis sit amet velit. Cras nulla risus, laoreet ac consectetur ut, tristique ac lorem. Curabitur scelerisque elit eget nunc eleifend eu fringilla nibh porttitor. [img] Sed ullamcorper vestibulum orci, vel interdum turpis semper non. Quisque id malesuada velit. Praesent a est nulla, ut dignissim nulla. Aenean eget tellus vel libero venenatis vestibulum. Maecenas magna sapien, mattis at pharetra eu, iaculis sed magna. \n\n"; code_format($text, $images); ?>
  5. I'm still looking for a solution if anyone else has some fresh eyes to lend me please?
  6. $_SERVER['HTTP_REFERER'] it is not very reliable though
  7. The php way would be something like this <?php if ($_POST['action'] == 1) { /* DO SOMETHING */} else { /* DO SOMETHING ELSE */ } ?> <form name="form1" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <input name="action" type="hidden" value = "1"> <input="submit" name="submit" value="submit"> </form> <form name="form2" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <input name="action" type="hidden" value = "2"> <input="submit" name="submit" value="submit"> </form>
  8. What you are hoping for will require some javascript. PHP is executed on the server, javascript is executed in the browser. Or you can have the form's action point the the same page...then have a hidden input on each form. the hidden input will give an if statement or a switch to choose a peice of code to execute
  9. has anyone used joomla or mambo? you have a list of images..then you place a tag in your article...the list of images will go in order of those tags you place in your text. thats what I am trying to accomplish if that helps.
  10. I have tried to replace each tag one at a time, but it replaces them all with the same image. foreach ($images as $key => $value) { $str = preg_replace ('/\[img\]/is', $value , $str); echo $key."|".$value."<br />\n\n"; } I don't know what else to try?
  11. for the resizing portion of your problem you can start with imagecopyresized(). the manual has good documentation on how to use it.
  12. Here is the output of what I have...It works fine, I accomplished my goal... My bbcode tags are replaced with html tags, including the image tags... Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin sit amet risus enim. Nunc urna libero, porta eu tristique vel, porta vel est. Phasellus imperdiet commodo mauris sit amet eleifend. Fuscemi sem, suscipit sed rhoncus a, egestas sed nisl. Phasellus cursus eleifend congue. Vestibulum sit amet ante blandit massa aliquam porta. <img src='1.jpg' /> Nulla lacinia purus non justo iaculis ultrices. Nunc sollicitudin odio sed ligula hendrerit vel euismod turpis porttitor. <strong>Pellentesque suscipit</strong>, tellus quis gravida blandit, quam tellus posuere ante, ut egestas odio erat nec augue. Praesent hendrerit mi sed metus suscipit hendrerit. Sed non ullamcorper ante. Phasellus nibh mauris, placerat at sodales non, tempus id dolor. In ullamcorper urna purus.<br /><br /> Duis suscipit leo eget eros accumsan in auctor dui placerat. Quisque id dui quam, porttitor varius nisi. Maecenas vestibulum sagittis neque vitae blandit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed tortor mi, sodales vitae fringilla commodo, pellentesque sit amet nisl. Proin aliquam metus in velit blandit at molestie sapien dapibus. Ut sollicitudin lectus id massa suscipit lacinia. Sed ante felis, ultrices et iaculis nec, tristique at sem. Donec a augue et orci convallis semper. <img src='2.jpg' /> Vestibulum mi neque, accumsan vel suscipit quis, cursus quis lacus. Vivamus vulputate cursus odio, eget cursus urna consequat vitae. Cras laoreet iaculis quam commodo malesuada. <em>Praesent scelerisque laoreet nisl, eu tempor diam gravida et. Ut dictum sodales nisi</em>. Morbi viverra ornare porttitor. Ut pretium urna sed arcu venenatis et ultricies elit aliquam. Ut ut sollicitudin neque. Praesent orci magna, convallis et cursus vitae, ornare eget erat. Integer id est nec odio pulvinar tincidunt.<br /><br /> Praesent id sapien libero, sit amet tincidunt lorem. Quisque volutpat nisi a tortor fringilla et scelerisque enim dignissim. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Suspendisse non mollis nunc. Duis vel molestie magna. Praesent nisi elit, posuere vel convallis id, mollis vitae dui. Vivamus aliquet semper dapibus. In ultricies molestie convallis. Vivamus hendrerit tellus venenatis lorem vulputate at interdum sapien dictum. Sed urna neque, facilisis et posuere nec, sodales rutrum nisi. <img src='3.jpg' /> Suspendisse potenti. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; <u>In id mi eros, a iaculis arcu</u>. Maecenas consequat consequat congue. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Etiam blandit, nunc vitae sodales rutrum, nisi neque viverra massa, vulputate venenatis elit lacus vitae arcu. Curabitur at ante ipsum. Quisque sodales mauris a arcu sodales nec fringilla lacus interdum. In in lobortis dui. In malesuada, diam ac auctor interdum, massa nibh scelerisque augue, et tincidunt lectus purus eget lectus.<br /><br /> Aliquam adipiscing tincidunt posuere. Suspendisse non purus nisl, at dapibus sapien. Maecenas posuere urna ac nibh scelerisque malesuada. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Phasellus sed nibh tortor, ac porta orci. Mauris ac turpis vitae libero vehicula pellentesque. Quisque vel urna sed magna pellentesque varius a et ligula. Proin ultricies magna at nibh auctor imperdiet. Nullam sed erat mauris, id laoreet augue. Pellentesque enim est, accumsan varius mattis ac, convallis sit amet velit. Cras nulla risus, laoreet ac consectetur ut, tristique ac lorem. Curabitur scelerisque elit eget nunc eleifend eu fringilla nibh porttitor. <img src='4.jpg' /> Sed ullamcorper vestibulum orci, vel interdum turpis semper non. Quisque id malesuada velit. Praesent a est nulla, ut dignissim nulla. Aenean eget tellus vel libero venenatis vestibulum. Maecenas magna sapien, mattis at pharetra eu, iaculis sed magna. however... I am trying to figure out how to automatically insert these jpg's from the images array without hard coding them using their keys. $str = sprintf($str,$a.$images[0].$b,$a.$images[1].$b,$a.$images[2].$b,$a.$images[3].$b);
  13. I'm working on developing my on CMS. I have the bbcode part working. Now I am trying to replace image tags in my content from an array. I can't quite wrap my head around how to finish this. So far i use my code replacement scrpit to replace with %s so that I can use the sprintf() function to relpace those with images. Right now I have just manually coded the images from the array, but I am trying to figure out how to get the image names out of the array automatically. Any advice? this first bit of code is the bbcode replacement function and my attempt at insterting images. I named this file code_format.php <?php function code_format ($str,$images) { //remove html tags $str = htmlentities($str); $code_search = array( '/\[b\](.*?)\[\/b\]/is' => '<strong>$1</strong>', '/\[i\](.*?)\[\/i\]/is' => '<em>$1</em>', '/\[u\](.*?)\[\/u\]/is' => '<u>$1</u>', //'/\[url\=(.*?)\](.*?)\[\/url\]/is' => <a href="$1">$2</a>', //'/\[url\](.*?)\[\/url\]/is' => '<a href="$1">$1</a>, //'/\[align\=(left|center|right)\](.*?)\[\/align\]/is' => '<div style="text-align: $1;">$2</div>', //'/\[img\](.*?)\[\/img\]/is' => '<img src="$1" />', //'/\[mail\=(.*?)\](.*?)\[\/mail\]/is' => '<a href="mailto:$1">$2</a>', //'/\[mail\](.*?)\[\/mail\]/is' => '<a href="mailto:$1">$1</a>', //'/\[font\=(.*?)\](.*?)\[\/font\]/is' => '<span style="font-family: $1;">$2</span>', //'/\[size\=(.*?)\](.*?)\[\/size\]/is' => '<span style="font-size: $1;">$2</span>', //'/\[color\=(.*?)\](.*?)\[\/color\]/is' => '<span style="color: $1;">$2</span>', '/\[img\]/is' => '%s', '/\[ret\]/is' => '<br /><br />', ); // Do simple code replacements $str = preg_replace (array_keys($code_search), array_values($code_search), $str); // Do image replacements $a ="<img src='"; $b = "' />"; $str = sprintf($str,$a.$images[0].$b,$a.$images[1].$b,$a.$images[2].$b,$a.$images[3].$b); echo $str; } ?> the second bit of code is my image array and my example text. <?php include ("code_format.php"); $images = array('1.jpg','2.jpg','3.jpg','4.jpg'); $text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin sit amet risus enim. Nunc urna libero, porta eu tristique vel, porta vel est. Phasellus imperdiet commodo mauris sit amet eleifend. Fuscemi sem, suscipit sed rhoncus a, egestas sed nisl. Phasellus cursus eleifend congue. Vestibulum sit amet ante blandit massa aliquam porta. [img] Nulla lacinia purus non justo iaculis ultrices. Nunc sollicitudin odio sed ligula hendrerit vel euismod turpis porttitor. [b]Pellentesque suscipit[/b], tellus quis gravida blandit, quam tellus posuere ante, ut egestas odio erat nec augue. Praesent hendrerit mi sed metus suscipit hendrerit. Sed non ullamcorper ante. Phasellus nibh mauris, placerat at sodales non, tempus id dolor. In ullamcorper urna purus.[ret]\n\n". "Duis suscipit leo eget eros accumsan in auctor dui placerat. Quisque id dui quam, porttitor varius nisi. Maecenas vestibulum sagittis neque vitae blandit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed tortor mi, sodales vitae fringilla commodo, pellentesque sit amet nisl. Proin aliquam metus in velit blandit at molestie sapien dapibus. Ut sollicitudin lectus id massa suscipit lacinia. Sed ante felis, ultrices et iaculis nec, tristique at sem. Donec a augue et orci convallis semper. [img] Vestibulum mi neque, accumsan vel suscipit quis, cursus quis lacus. Vivamus vulputate cursus odio, eget cursus urna consequat vitae. Cras laoreet iaculis quam commodo malesuada. [i]Praesent scelerisque laoreet nisl, eu tempor diam gravida et. Ut dictum sodales nisi[/i]. Morbi viverra ornare porttitor. Ut pretium urna sed arcu venenatis et ultricies elit aliquam. Ut ut sollicitudin neque. Praesent orci magna, convallis et cursus vitae, ornare eget erat. Integer id est nec odio pulvinar tincidunt.[ret]\n\n". "Praesent id sapien libero, sit amet tincidunt lorem. Quisque volutpat nisi a tortor fringilla et scelerisque enim dignissim. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Suspendisse non mollis nunc. Duis vel molestie magna. Praesent nisi elit, posuere vel convallis id, mollis vitae dui. Vivamus aliquet semper dapibus. In ultricies molestie convallis. Vivamus hendrerit tellus venenatis lorem vulputate at interdum sapien dictum. Sed urna neque, facilisis et posuere nec, sodales rutrum nisi. [img] Suspendisse potenti. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; [u]In id mi eros, a iaculis arcu[/u]. Maecenas consequat consequat congue. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Etiam blandit, nunc vitae sodales rutrum, nisi neque viverra massa, vulputate venenatis elit lacus vitae arcu. Curabitur at ante ipsum. Quisque sodales mauris a arcu sodales nec fringilla lacus interdum. In in lobortis dui. In malesuada, diam ac auctor interdum, massa nibh scelerisque augue, et tincidunt lectus purus eget lectus.[ret]\n\n". "Aliquam adipiscing tincidunt posuere. Suspendisse non purus nisl, at dapibus sapien. Maecenas posuere urna ac nibh scelerisque malesuada. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Phasellus sed nibh tortor, ac porta orci. Mauris ac turpis vitae libero vehicula pellentesque. Quisque vel urna sed magna pellentesque varius a et ligula. Proin ultricies magna at nibh auctor imperdiet. Nullam sed erat mauris, id laoreet augue. Pellentesque enim est, accumsan varius mattis ac, convallis sit amet velit. Cras nulla risus, laoreet ac consectetur ut, tristique ac lorem. Curabitur scelerisque elit eget nunc eleifend eu fringilla nibh porttitor. [img] Sed ullamcorper vestibulum orci, vel interdum turpis semper non. Quisque id malesuada velit. Praesent a est nulla, ut dignissim nulla. Aenean eget tellus vel libero venenatis vestibulum. Maecenas magna sapien, mattis at pharetra eu, iaculis sed magna. \n\n"; code_format($text, $images); ?>
  14. I'm working on a site for a fireman calendar. I'm trying to set it up so that the guys at the firehouse can go in and add the bio's and photos of the new fireman with out me every year. I have a script that works to upload an image, as long as the only field in my form is the file field. However now that I am mixing all these other form fields the file info seems to be getting lost somewhere when it is submitted. As you can see in my code im doing print_r($_POST) and print_r($_FILES) to see whats happening, but I still can figure what is happening to all the file info when the form is submitted. The first half of the script is the form, the second half is the stuff to insert it into the DB. My upload script is in another file, I havent included it here yet until I can figure out what is happening to the file info. Does anyone have any ideas, or advice? <?php session_start(); if ($_SESSION['auth'] == "admin") { include("db_connect.php"); if ($_POST['action'] == "addfiremen") { echo "<h1>Add Firemen for ".$_POST['year']."</h1>"; echo "<form name='add_firemen' action='".$_SERVER['PHP_SELF']."' method='post'>"; echo "<input name='action' type='hidden' value='add' />"; echo "<input name='number' type='hidden' value='".$_POST['number']."' />"; for ( $counter = 1; $counter <= $_POST['number']; $counter += 1) { echo "<table><tr><td>"; echo "<input name='".$counter."[counter]' type='hidden' value='".$counter."' />"; echo "<input name='".$counter."[year]' type='hidden' value='".$_POST['year']."' />"; echo "First Name:<input name='".$counter."[first_name]' size='16' type='text' /><br /><br /> "; echo "Last Name:<input name='".$counter."[last_name]' size='16' type='text' /><br /><br />"; echo "Job:<input name='".$counter."[job]' size='40' type='text' /><br /><br />"; echo "Picture:<input name='".$counter."[picture]' type='file'><br /><br />"; echo "Thumbnail:<input name='".$counter."[thumbnail]' type='file'><br /><br />"; echo "</td>"; echo "<td>"; echo "Story: <br />"; echo "<textarea name='".$counter."[info]' cols='60' rows='15'></textarea><br><br>"; echo "</td></tr><tr><td colspan='2'><hr /></td></tr></table>"; } echo "<input name='submit' type='submit' value='Submit'>"; echo "</form>"; } else if ($_POST['action'] == 'add') { include("upload_action.php"); print_r($_POST); echo "<br />"; print_r($_FILES); echo "<br />"; for ( $counter = 1; $counter <= $_POST['number']; $counter += 1) { $calendar_year = addslashes(strip_tags($_POST[$counter]['year'])); $calendar_fname = addslashes(strip_tags($_POST[$counter]['first_name'])); $calendar_lname = addslashes(strip_tags($_POST[$counter]['last_name'])); $calendar_job = addslashes(strip_tags($_POST[$counter]['job'])); $calendar_info = addslashes(strip_tags($_POST[$counter]['info'])); $insert_query = "INSERT INTO calendar (`calendar_year`, `calendar_fname`,`calendar_lname`,`calendar_job`,`calendar_info`) VALUES ('$calendar_year','$calendar_fname','$calendar_lname','$calendar_job','$calendar_info')"; //$insert_result = mysql_query($insert_query) or die(mysql_error()); echo $insert_query."<br />"; } header ('location:index.php?page=calendars'); } } else { include("log_form.php"); } ?>
  15. Thanks GregL83, exactly what I needed!
  16. Lets say I have a table with two fields, name and type. Every item in name is unique. There are 3 types like animal, vegetable, mineral. Like this: Name | Type ----------------- blah | animal foo | vetable bar | mineral baz | animal foobar | animal I want to run a query where the output gives me just the main types, but not every row. Does anyone know what I am trying to say?
  17. Thanks for pointing that out, that worked.
  18. I have a basic form to add, edit, delete my websites news from my database. For some when I access the info in my edit form, everything after apostrophes in my title gets lost. It does not happen in the content field. I am doing addslashes() on info going in, and stripslashes() on everything coming out. I'm posting this here because I don think its a mysql problem. Any Ideas? Here is the edit stuff.. $slashed_content = addslashes($_POST['content']); $slashed_title = addslashes($_POST['title']); $query = "UPDATE news SET news_title = '$slashed_title', news_content = '$slashed_content', news_active = '$_POST[active]' WHERE news_id = '$_POST[id]'"; $update_result = mysql_query($query); Here is where I grab it form the DB $slashed_content = addslashes($_POST['content']); $slashed_title = addslashes($_POST['title']); $query = "UPDATE news SET news_title = '$slashed_title', news_content = '$slashed_content', news_active = '$_POST[active]' WHERE news_id = '$_POST[id]'"; $update_result = mysql_query($query); header ('location:index.php'); } else { $news_id = $_GET['id']; $query = "SELECT * FROM news WHERE news_id = $news_id"; $news_result = mysql_query($query); function edit_news($news_result) { $row = mysql_fetch_array($news_result, MYSQL_ASSOC); $print_date = date('F j, Y', strtotime($row['news_date'])); echo "<h2>Edit News</h2>"; echo "<form action='$_SERVER[php_SELF]' method='post'>" ; echo "<input type='hidden' name='action' value='edit'>"; echo "<input type='hidden' name='id' value='".$row['news_id']."'>"; echo $print_date." <input name='title' type='text' value='".stripslashes($row['news_title'])."'> &nbsp"; echo "<input name='active' type='radio' value='0'"; if ($row['news_active'] == 0) {echo "checked";} echo "/>Hidden"; echo "<input name='active' type='radio' value='1'"; if ($row['news_active'] == 1) {echo "checked";} echo "/>Active<br /><br />"; echo "<textarea cols='80' rows='10' name='content'>".stripslashes($row['news_content'])."</textarea><br /><br />"; echo "<input name='edit' type='submit' value='Edit'> <a href='index.php'>Cancel</a>"; echo "</form>"; }
  19. Lets say for arguments sake that your user has uploaded a file and it is called 1234.jpg and you want it to be 15px wide and 25px tall... the script below will open that file and resize it without having to make a new copy of it: <?php //Name this file thumb.php $image = imagecreatefromjpeg("uploads/$_GET[src]"); // Uploaded file location $image_width=imagesx($image); // Original Photo width $image_height=imagesy($image); // Original Photo height $thumbnail_width = $_GET['width']; $thumbnail_height = $_GET['height']; $thumbnail_quality = 100; $thumbnail = imagecreatetruecolor($thumbnail_width,$thumbnail_height); imagecopyresized($thumbnail,$image,0,0,0,0,$thumbnail_width,$thumbnail_height,$image_width,$image_height); imagejpeg($thumbnail,NULL,$thumbnail_quality); imagedestroy($thumbnail) ?> Now in whatever page you want the thumbnail: <img src="thumb.php?src=1234.jpg&width=15&height=25"> Note, I did not test this, and you will need some other code to get the image to fit into certain dimensions proportionally, but its a start. I found this method in a tutorial somewhere, and I think it is a pretty elegant solution.
  20. I figured it out as soon as I submitted that reply...I should have been putting if ($blanks == 0){} instead of: if ($blanks > 0){} I was having my code execute if there was blanks, instead of executing if there were no blanks, thanks for your help and sorry for the waste of time.
  21. yeah i even did the print_r($_POST) to check, I have no idea what is happening.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.