Jump to content

supanoob

Members
  • Posts

    342
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

supanoob's Achievements

Advanced Member

Advanced Member (4/5)

0

Reputation

  1. I have the following code, and it is not working for some reason. I have echoed the $sql and that it showing fine, then its not showing as any results etc when i echo them, any idea why it may be? if ($_GET['step'] == 'search' && $_GET['action'] == 'submit') { $search = $_POST['searchcriteria']; $searchtype = $_POST['search']; if ($search == '') { echo "No search criteria entered."; die(); } $sql="SELECT userid, firstname, secondname, day, month, year, postcode FROM users WHERE $searchtype LIKE $search"; //-run the query against the mysql query function echo "$sql"; $result=mysql_query($sql); echo "<br><br>result:$result<br>"; //-count results $numrows=mysql_num_rows($result); echo "rows found: $numrows<br>"; echo "<p>" .$numrows . " results found for " . $search . "</p>"; //-create while loop and loop through result set while($row=mysql_fetch_array($result)){ $firstname=$row['firstname']; $secondname=$row['secondname']; $userid=$row['userid']; $day=$row['day']; $month=$row['month']; $year=$row['year']; $postcode=$row['postcode']; //-display the result of the array echo "<ul>\n"; echo "<li>$firstname $secondname (DOB: $day/$month/$year) $postcode</a></li>\n"; echo "</ul>"; } } Thanks in advance.
  2. So i have a database with a list of Towns and their relevant postcode letters (DN = Doncaster, S = Sheffield etc) i want to be able to find out what town they're from, using the postcode they have submitted, but i'm unsure on how to break away the characters before the first number in the postcode..... so for example someone submits DN2 6PJ how to do break away the DN so i can return Doncaster or the same if it was S1 4QJ how would i break away the S to return sheffield?
  3. What about using a temp image? care to share a script? i cant seem to find any
  4. could someone please help me adapt the following code to make it resize the image before uploading? Any help would be appreciated, thanks <?php if($_GET['submit'] == 'yes') { $image = $_FILES['image']['name']; if ($image) { $filename = stripslashes($_FILES['image']['name']); $extension = getExtension($filename); $extension = strtolower($extension); if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { echo 'Unknown extension!'; $errors=1; } else { $size=filesize($_FILES['image']['tmp_name']); if ($size > MAX_SIZE*1024) { echo 'You have exceeded the size limit! the limit is 500KB'; $errors=1; } $rand = rand(0,9999999); $date = DATE("d.m.y"); $image_name=$date.$id.$rand.'.'.$extension; $newname="./images/$gender/".$image_name; $copied = copy($_FILES['image']['tmp_name'], $newname); if (!$copied) { echo 'Copy unsuccessfull!'; $errors=1; }}}} ?>
  5. That didnt work, the pictures are uploading, it appears to be the temp and resizing that doesnt work :/
  6. Thats the right path though :/ I have a working script, i just wanted to modify it to allow for image resizing.
  7. When i use the following script to upload and resize an image, it throws out errors (see after script) <?php $image = $_FILES['image']['name']; $uploaddir = "./images/$gender/"; $pext = getExtension($image); $pext = strtolower($pext); if (($pext != "jpg") && ($pext != "jpeg") && ($pext != "gif")) { print "<h1>ERROR</h1>Image Extension Unknown.<br>"; print "<p>Please upload only an image with the extension .jpg or .jpeg or .gif ONLY<br><br>"; print "The file you uploaded had the following extension: $pext</p>\n"; unlink($imgfile); exit(); } $imgsize = GetImageSize($image); /*== check size 0=width, 1=height ==*/ if (($imgsize[0] > 460) || ($imgsize[1] > 345)) { $tmpimg = tempnam("/tmp", "MKUP"); system("djpeg $image >$tmpimg"); system("pnmscale -xy 250 200 $tmpimg | cjpeg -smoo 10 -qual 50 >$imgfile"); unlink($tmpimg); } $rand = rand(0,9999999); $date = DATE("d.m.y"); $image_name=$date.$id.$rand.'.'.$extension; $final_filename = str_replace(" ", "_", $image_name); $newfile = $uploaddir . "/$final_filename"; if (is_uploaded_file($image)) { if (!copy($imgfile,"$newfile")) { print "Error Uploading File."; exit(); } } unlink($image); print("<img src=\"$newfile\">"); ?> errors:
  8. Just an update i have also tried using preg_replace for the \r\n etc aswell as str_replace for the same thing, nothing seems to be working , i put for example i put: Thats exactly how it would get inserted into my database, Just without any <br />'s. The field it is going into is formatted as "longtext" not sure if that makes a difference or not?
  9. Yeah im putting it into a database, but if i get rid of the nl2br it doesnt work either, nor does putting it below everything else :S someone mention it could be to do with Usi flags?
  10. I have the following code, and for some reason the nl2br() function doesnt work anymore it did until i added the pred_replace part: $topic = $_POST['topic']; $message = $_POST['message']; $board = $_POST['board']; $topic = stripslashes($topic); $message = stripslashes($message); $board = stripslashes($board); $topic = mysql_real_escape_string($topic); $message = mysql_real_escape_string($message); $board = mysql_real_escape_string($board); $message = nl2br($message); $message = preg_replace("/\[b\](.*)\[\/b\]/Usi", "<b>\\1</b>", $message); $message = preg_replace("/\[u\](.*)\[\/u\]/Usi", "<u>\\1</u>", $message); $message = preg_replace("/\[i\](.*)\[\/i\]/Usi", "<i>\\1</i>", $message); $message = preg_replace("/\[center\](.*)\[\/center\]/Usi", "<center>\\1</center>", $message); $message = preg_replace("/\[right\](.*)\[\/right\]/Usi", "<p align=right>\\1</p>", $message); $message = preg_replace("/\[url=http://(.*)\](.*)\[\/url\]/Usi", "<a href=\"\\1\">\\2</a>", $message); $message = preg_replace("/\[img=(.*)\]/Usi", "<img src=\"\\1\">", $message); $message = preg_replace("/\[profile=(.*)\](.*)\[\/profile\]/Usi", "<a href=\"index.php?step=profile&profile=\\1\">\\2</a>", $message); $message = preg_replace("/\[quote](.*)\[\/quote\]/Uis", "<div>Quote:</div><div style=\"border:solid 1px;\">\\1</div>", $message);
  11. Noone got any ideas on why?
  12. ok so i have a piece of code that is used to insert text from a button when clicked, into a textarea, it all works well apart from the fact that whenever i click a second button to insert something into the field, it is added with whatever was clicked previously for example, i click a button, and then i click it would be added like so . Here is the javascript code: var globalCursorPos; function setCursorPos() { globalCursorPos = getCursorPos(postForm.post_body); } function getCursorPos(textElement) { var sOldText = textElement.value; var objRange = document.selection.createRange(); var sOldRange = objRange.text; var sWeirdString = '#%~'; objRange.text = sOldRange + sWeirdString; objRange.moveStart('character', (0 - sOldRange.length - sWeirdString.length)); var sNewText = textElement.value; objRange.text = sOldRange; for (i=0; i <= sNewText.length; i++) { var sTemp = sNewText.substring(i, i + sWeirdString.length); if (sTemp == sWeirdString) { var cursorPos = (i - sOldRange.length); return cursorPos; } } } function insertString(stringToInsert) { var firstPart = postForm.post_body.value.substring(0, globalCursorPos); var secondPart = postForm.post_body.value.substring(globalCursorPos, postForm.post_body.value.length); postForm.post_body.value = firstPart + stringToInsert + secondPart; } and here is the html with the text field: <form id="form1" name="postForm" method="post" action=""> <table width="100%" border="0" class="post_center"> <tr> <td><center> <table width="95%" border="0"> <tr> <td colspan="2" class="post"> <input TYPE="button" VALUE="BlahBlah" ONCLICK="insertString(this.value)" class="button"> <input TYPE="button" VALUE="YeaYea" ONCLICK="insertString(this.value)" class="button"> <input TYPE="button" VALUE="YupYup" ONCLICK="insertString(this.value)" class="button"></td> </tr> <tr> <td class="post" width="25%">Topic</td> <td class="post"><label> <input type="text" name="textfield" id="textfield" /> </label></td> </tr> <tr> <td class="post">Body</td> <td class="post"><label> <textarea name="post_body" id="post_body" cols="45" rows="5"></textarea> </label></td> </tr> <tr> <td colspan="2" class="post"><label> <div align="center"> <input type="submit" name="button" id="button" value="Post" /> </div> </label></td> </tr> </table> </CENTER> </td> </tr> </table> </form> Any help would be much appreciated.
  13. so i would nl2br the text before showing it on the page? so it would be $news = nl2br($news); echo $news? and yes the textarea does have actual line breaks
  14. sure this is the form used: <form id=\"form1\" name=\"form1\" method=\"post\" action=\"index.php?step=admin&action=news&new=yes\"> <table width=\"100%\" border=\"0\"> <tr> <td>Title</td> <td><input type=\"text\" name=\"title\" id=\"textfield\" /></td> </tr> <tr> <td>Post</td> <td><textarea name=\"news\" id=\"textarea\" cols=\"45\" rows=\"5\"></textarea></td> </tr> <tr> <td colspan=\"2\"><center><input type=\"submit\" name=\"button\" id=\"button\" value=\"Submit\" /></center></td> </tr> </table> </form> and this is the php side of things: <?php if ($_GET['new'] == 'yes') { $title = $_POST['title']; $news = $_POST['news']; $title = stripslashes($title); $news = stripslashes($news); $title = mysql_real_escape_string($title); $news = mysql_real_escape_string($news); $news = news_item($news); mysql_query("INSERT INTO news (news_title, news_date, news_by, news_message) VALUES ('$title', NOW(), '$id', '$news') ") or die(mysql_error()); echo "New news item added.</td> </tr> </table>"; ?>
  15. supanoob

    nl2br

    ok so i have the following function: <?php function news_item ($news) { $news=htmlspecialchars($news); $news=str_replace (array('[b]', '[/b]', '[i]', '[/i]', '[u]', '[/u]'), array('<b>', '</b>', '<i>', '</i>', '<u>', '</u>'), $news); return nl2br($news); } ?> but for some reason the nl2br doesnt conver my new lines to <br> when i use it. What i want to do is submit the data from a text area into the database, but when its inserted i want the new lines to stay in place, so when it is echo'd it comes up like: instead of: any ideas why?
×
×
  • 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.