Jump to content

Alkimuz

Members
  • Posts

    45
  • Joined

  • Last visited

Everything posted by Alkimuz

  1. Like Davey says, i am not going to search your whole code.. but if the questions are in an array, you could use the function shuffle() http://php.net/manual/en/function.shuffle.php
  2. you can use html in the content of the e-mail by adding the following headers: // To send HTML mail, the Content-type header must be set $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; cant help you with the multiple attachments, my knowledge is limited
  3. my end goal is to show an invoice with data of the customer, therefor i made a templatefile with pure html and within a function, i get the content of the templatefile and replace specific words in the templatefile with the data of the customer. so far so good. but now, i have a repeatitive part of the templatefile, the one with the bought items.. my idea is to substract that specific part out of the variable with the content of the templatefile, duplicate and fill it with a while loop and put it back in the variable, replacing the original.. (hopefully your still with me?) this works: $url = $_SESSION['dir'].'php/invoice.php'; $invoice = file_get_contents($url); //replace data $replacement = array("name", "prefix", "ordernumber", "orderdate", "address", "zipcode", "place", "country", "ordername", "orderaddress", "orderzipcode", "orderplace", "ordercountry"); foreach ($replacement as $word){ $invoice = str_replace('{$'.$word.'}', $data[$word], $invoice); } so the whole invoice code is in $invoice and the data of the customer is allready in it now time for the next step: the substraction of the specific part, which is between these tags: <!-- repeat --> <!-- /repeat --> i was thinking of: preg_match("/<!-- repeat -->(.*)<!-- \/repeat -->/", $invoice, $invoicepart); but that does not work.. is that because the syntax is wrong or because the part to select excists of a lot of html code? after that, i was think of: $itemresult = item_query(); while ($itemrow = mysql_fetch_array($itemresult)){ //replace item data $temporalpart = $invoicepart; $replacement = array("itemname", "itemamount", "itemprice", "itempricetotal"); foreach ($replacement as $word){ $temporalpart= str_replace('{$'.$word.'}', $itemrow[$word], $temporalpart); } $newinvoicepart.= $temporalpart } $invoice = str_replace("$invoicepart", "$newinvoicepart", "$invoice"); would that be the right way to go further? many thanks for helping me!
  4. awesome, i didn't know this kind of variable handling in SQL, thank you! for now, my question is kind of answered, as i will use your suggestion, although i was also curious if there is some kind of "standard" way to handle with database prefixes in coding; unfortunately, i am not advanced enaugh to figure out how the major CMS-systems are doing it, but for now, i am happy
  5. hi, i was wondering what an easy and right way would be to use a variable that can stand before the names of your tables. I've seen that a CMS like joomla or wordpress calls this a 'database prefix' what does work is for example: [config.php] $prefix = 'prefix_'; [index.php] $table = $prefix.'tablename'; $tableresult = mysql_query("SELECT * FROM $table") or die ("could not execute tableresult"); but i gues there should be a better way, as it looks kind of silly to declare the $table every time before the actual query.. thanks for any help!
  6. hmm.. i think more and more that it is indeed a server-issue.. i'll contact my hoster..
  7. maybe a stupid reply, but dit you think of looking into the spam-folders? the email might not come through the spam-filters of yahoo and gmail.. making the email more personal might help..
  8. Hey, i'd like to extract filenames from my database and present them as a downloadable zip-file to my users. I found a usefull function on http://davidwalsh.name/create-zip-php and thought i could work that out to my needs, but on this function itself (before using it), i get an error.. on the following line: if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) { i get: Parse error: syntax error, unexpected ')', expecting '(' i dont get it, dont think there is actually an error in the function.. does it mean that the php installed on the server i use, cant handle this function or anything? my phpinfo: http://dwarsfluit.davidvandiepen.nl/test.php the function is: <?php /* creates a compressed zip file */ function create_zip($files = array(),$destination = '',$overwrite = false) { //if the zip file already exists and overwrite is false, return false if(file_exists($destination) && !$overwrite) { return false; } //vars $valid_files = array(); //if files were passed in... if(is_array($files)) { //cycle through each file foreach($files as $file) { //make sure the file exists if(file_exists($file)) { $valid_files[] = $file; } } } //if we have good files... if(count($valid_files)) { //create the archive $zip = new ZipArchive(); if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) { return false; } //add the files foreach($valid_files as $file) { $zip->addFile($file,$file); } //debug //echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status; //close the zip -- done! $zip->close(); //check to make sure the file exists return file_exists($destination); } else { return false; } }?> thanks for helping!
  9. Alkimuz

    date_format

    wow, just move the date_format to the WHERE-clause!! thanks!!!
  10. Alkimuz

    date_format

    thanks for your help in the mean time, i also found an other solution, i didnt know the SQL-formulas MONTH() and YEAR() before ^^, probably there is still a lot faster way, but for now it works: <?php $datumresult = mysql_query("SELECT *, DATE_FORMAT(datum, '%m') as maand, DATE_FORMAT(datum, '%Y') as jaar FROM strip WHERE vlag = '0' AND datum = '$ID' LIMIT 1") or die ("could not execute paginaresult!"); $datumrow = mysql_fetch_array($datumresult); $m = $datumrow['maand']; $jaar = $datumrow['jaar']; if ($m <2){$vorigem = 12; $vorigej = $jaar - 1;} else {$vorigem = $m - 1; $vorigej = $jaar;} $vorigeresult = mysql_query("SELECT * FROM strip WHERE vlag = '0' AND MONTH(datum) = '$vorigem' AND YEAR(datum) = '$vorigej' ORDER BY ID DESC ") or die ("could not execute vorigeresult!"); $vorigerow = mysql_fetch_array($vorigeresult); ?>
  11. Alkimuz

    date_format

    perfect, but can you explain me how to do that?
  12. Alkimuz

    date_format

    ok, thanks! i am one stap further, but what if you dont know the date on forehand? for example, i take a random item and i want to select all items of the same month as this item, or all items of the previous month of this item? first i thought i could subtract the month number of the random item and select all items with the same month number or month number -1, but that would not be possible, like you say..
  13. i use the following for resizing to other size in pixels, you can change it a little to work for percentages (set in the main code the pixel size to, for example, 0.5 and define the new width and height in the function photoresize by multiplying the original width and height with this number) this code will mentain the aspect ratio and use the with as main resize variable and adapt height to that, you can play with the beginning of the function photoresize to change that. notice the "copy()" in the uploadscript in function.php: <?php function photoupload($filename, $source, $destination, $destination2) { /*START PHOTOUPLOAD*/ // Does the file have the right MIME type? if ($_FILES[$filename]['type'] != 'image/pjpeg' AND $_FILES[$filename]['type'] != 'image/jpeg' AND $_FILES[$filename]['type'] != 'image/gif' AND $_FILES[$filename]['type'] != 'image/png' AND $_FILES[$filename]['type'] != 'image/wbmp') { echo 'the file you want to upload is no photo, please go back to try again'; exit; } move_uploaded_file ($source, $destination ); copy($destination, $destination2); return 0; /*END PHOTOUPLOAD*/ } function photoresize($source, $maxx, $maxy)//foto wordt max breedte { /*START PHOTORESIZE*/ // Get current dimensions list($width_orig, $height_orig) = getimagesize($source); // Check if they are over their limit if ( ($width_orig > $maxx) || ( $height_orig > $maxy)) { if ($maxx && ($width_orig < $height_orig)) { $maxx = ($maxy / $height_orig) * $width_orig; } else { $maxy = ($maxx / $width_orig) * $height_orig; } // Resample voorbereiden $image_p = imagecreatetruecolor($maxx, $maxy); $image_type = strtolower( substr($source, strrpos( $source, '.' )) ); switch( $image_type ) { case '.gif' : $image = imagecreatefromgif($source); break; case '.jpg' : $image = imagecreatefromjpeg($source); break; case '.jpeg': $image = imagecreatefromjpeg($source); break; case '.png' : $image = imagecreatefrompng($source); break; case '.bmp' : $image = imagecreatefromwbmp($source); break; } // Resample de afbeelding imagecopyresampled($image_p, $image, 0, 0, 0, 0, $maxx, $maxy, $width_orig, $height_orig); // Output switch( $image_type) { case '.gif' : imagegif($image_p, $source, 100); break; case '.jpg' : imagejpeg($image_p, $source, 100); break; case '.jpeg' : imagejpeg($image_p, $source, 100); break; case '.png' : imagepng($image_p, $source, 100); break; case '.bmp' : image2wbmp($image_p, $source, 100);break; } } return 0; /*END PHOTORESIZE*/ } ?> in your main code: <?php @$picture = time().'-'.$_FILES['picture']['name']; @$filename = 'picture'; if ($_FILES['picture']['tmp_name'] == TRUE) { //photo uploaden $source = $_FILES['picture']['tmp_name']; $path= 'pictures/'; $destination = $path.$picture ; photoupload($filename, $source, $destination); //photo resizen $source = $destination; $maxx= '500'; $maxy= '500'; photoresize2($source, $maxx, $maxy); } ?> hope this helps!
  14. Alkimuz

    date_format

    hi, would like to select stuff on a specific month number and/or year where their date is stored as a DATE (0000-00-00), so i came up with this: $dateresult = mysql_query("SELECT *, DATE_FORMAT(date, '%m') as month, DATE_FORMAT(date, '%Y') as year FROM table WHERE month = '10' AND year = '2011' ") or die ("could not execute dateresult!"); but it seams not to work.. is it wrong to select on colums that are newly defined? if so, what is the right method? thanks!
  15. yeah, no problem, you should get the info from the link with $_GET[''], and than use that to look in your database again: $memberid = $_GET['lc_URL']; $result = mysql_query("SELECT * FROM playedgames WHERE memberid = '$memberid'"); while ($row = mysql_fetch_array($result)){ echo $row['gamename']; } EDIT: sorry, same solution as the one above me that dit post his answer a littlebit faster
  16. just checking, but you do add the codes to run this SQL right? like: $con = mysql_connect($host, $user, $password); if (!$con) { die('Could not connect: ' . mysql_error()); } $db = mysql_select_db($database, $con); $SQL = "UPDATE settings SET site_title = '$site_title' WHERE email = '$email'"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }
  17. Hi guys, got a real puzzle here, did break my head about it for hours, but cant figure it out, hope you can help me.. (and hope this is the right spot as it is not only php, but a lot of javascript and css involved..) I did place bits of code together to make an imageselector: above a textfield is a picture, a jQuery-popup appears after clicking, showing all the uploaded pictures as thumbnails, you click on one of them and the link withing bb-codes is placed within. It works really beautiful, but now the problem: i want to have several textareas on my page, all with imageselectors above them... But: the queries work with id's, and we all know, you cant have more of the same id's on one page i you are calling them.. here my codes: (in fact it is more code and also spread out over more pages, but i show it as simple as possible) mainpage: <form> <p>Tekst:<br> <div ID="edittextbox"> <script>edToolbar(\'edittekst\');</script> <textarea ID="edittekst" class="width" style="height:200px;" name="tekst"></textarea>'; </div>'; </form> <?php imageselector('edittekst') ?> The php with the imageselectorbox, now hidden, but shown after hitting the picture, (central issue: because the css of the id's here are changed with the javascripts) function imageselector($textbox) { ?> <div id="popupContact"> <a id="popupContactClose">x</a> <b>Choose picture:</b> <br /> <div ID="imageselectorbox"> <?php $plaatjesresult = mysql_query("SELECT * FROM plaatje ORDER BY ID DESC") or die ("could not execute plaatjesresult"); while ($plaatjesrow = mysql_fetch_array($plaatjesresult)) { $plaatjeklein = 'plaatjes/klein/'.$plaatjesrow['plaatje']; $plaatjegroot = 'plaatjes/groot/'.$plaatjesrow['plaatje']; if(file_exists($plaatjeklein) && file_exists($plaatjegroot)) { echo '<div style="width:73px; height: 73px; vertical-align: middle; float:left;"><center>'; echo '<a href="javascript: doImage(\''.$textbox.'\', \''.$plaatjegroot.'\')"><img src="'.$plaatjeklein.'"></a>'; echo '</center></div>'; } } ?> </div> </div> <div id="backgroundPopup"></div> <?php } The javascript that let the box show and popup: function imageselector(){ //request data for centering var windowWidth = document.documentElement.clientWidth; var windowHeight = document.documentElement.clientHeight; var popupHeight = $("#popupContact").height(); var popupWidth = $("#popupContact").width(); //centering $("#popupContact").css({ "position": "absolute", "top": windowHeight/2-popupHeight/2, "left": windowWidth/2-popupWidth/2 }); //only need force for IE6 $("#backgroundPopup").css({ "height": windowHeight }); //loads popup only if it is disabled if(popupStatus==0){ $("#backgroundPopup").css({ "opacity": "0.7" }); $("#backgroundPopup").fadeIn("slow"); $("#popupContact").fadeIn("slow"); popupStatus = 1; } } The javascript that shows the picture with the onclick-image (in fact this has a lot more buttons besides the picture) function edToolbar(obj) { document.write("<img class=\"button\" ID=\"imageselector\" src=\"images/picture.png\" name=\"btnPicture\" onClick=\"imageselector()\">"); } The javascript that places the image in the textbox: function doImage(obj, url) { textarea = document.getElementById(obj); //var url = prompt('Enter the Image URL:','http://'); var scrollTop = textarea.scrollTop; var scrollLeft = textarea.scrollLeft; if (document.selection) { textarea.focus(); var sel = document.selection.createRange(); sel.text = '[img=' + url + ']'; } else { var len = textarea.value.length; var start = textarea.selectionStart; var end = textarea.selectionEnd; var sel = textarea.value.substring(start, end); //alert(sel); var rep = '[img=' + url + ']'; textarea.value = textarea.value.substring(0,start) + rep + textarea.value.substring(end,len); textarea.scrollTop = scrollTop; textarea.scrollLeft = scrollLeft; disablePopup(); } } My css #backgroundPopup{ display:none; position:fixed; _position:absolute; /* hack for internet explorer 6*/ height:100%; width:100%; top:0; left:0; background:#000000; border:1px solid #cecece; z-index:1; } #popupContact{ display:none; position:fixed; _position:absolute; /* hack for internet explorer 6*/ height:384px; width:408px; background:#FFFFFF; border:2px solid #cecece; z-index:2; padding:12px; font-size:13px; } #popupContactClose{ font-size:14px; line-height:14px; right:6px; top:4px; position:absolute; color:#6fa5fd; font-weight:700; display:block; } #imageselectorbox{ height:300px; width:390px; overflow: auto; } Of course i have also code that closes the popup, but i guessed, that is not really essential. the point is: adding more textboxes on one page, how to handle that? of course for 2 boxes i can double all the codes, naming every id in the imageselector-php different, but that will be a lot of code for doing the exact same thing.. how to make every imageselector popup unique for every textfield in an elegant way? i dont mind if the code is changed a lot, as long as it works.. thanks so much for looking at this and hope my english is good enaugh, sorry for any spellingmistakes
  18. i hope than that the name stored in the database is the same as the name of the file stored on the server.. for this piece of code it should be, but i dont know whats going on in that extra asidofiles that are called in.. check if the code for the image under that cross you see (right-click, imageinfo en check the directory + name of the image) is the same as the directory and imagename on your server if not, see if the code for placing the image is allright, a different directory is easely changed, if there is a difference with the imagename, the code is messing with the imagename..
  19. text between single quotes is just only plain (html-)text, text between dubblequotes have a littlebit more richness, for example, you can place variables within dubblequotes and they will work, as in singlequotes i will just appear as text. Also you can use some extra layout for the text like codes as "\n" wich will work as <br>. for myself, i like to work as much as possible with only singlequotes when just working with plain html codes and text, but that differs between people the difference between = and == is very easy, the first is giving a variable a surtain value, the second is testing if a given variable is allready containing a surtain value $variable = 'hello world'; $variable contains now the text: 'hello world' if ($variable == 'hello world') { echo 'the variable contains the text: hello world!' } this code is testing if the variable is containing the text 'hello world', if so, the text 'the variable contains the text: hello world!' is displaid
  20. glad i could help nice solution at the end! i'm not sure.. i've used it without problem, but than again, i don't have big websites that are under a lot of attack, i only prevent moderators from making mistakes maybe use it togethet with htmlentities for transforming anything that is left to make it saver? $data= htmlentities(htmlspecialchars(trim($_POST['data']))); thanks for the compliment ^^, the advantage in changing it afterwards is that you can edit your bb-coded text after storing it without transforming it again
  21. hey, i am sorry to say that i cant help you further, as i really dont know mutch about AJAX myself.. i only can help a little with php and SQL.. i really hope some other helper will jump in here to help you further!
  22. hey Wil, what i dont understand is that for example é is changed into &#xED; as the right code would be &#233; (http://www.w3schools.com/tags/ref_entities.asp) maybe its an idea to change the wrong charactercode into the right one? (and in that way avoid working with the outputcharacters) function handleSpanishCharacters($input) { return str_replace("&#xED;", "&#233;", $input); }
  23. i am not sure what is wrong in your code, but i might help you by showing the code i always use to do what you want, it works perfectly: $filename = 'photo'; $file = time().'-'.$_FILES['photo']['name']; if (trim($_FILES[$filename]['tmp_name']) == TRUE) { //photo uploaden $filename = 'photo'; $source = $_FILES[$filename]['tmp_name']; $path= 'photos/big/'; $path2= 'photos/small/'; $destination = $path.$file ; $destination2 = $path2.$file ; photoupload($filename, $source, $destination, $destination2); //photo big resizen $source = $destination; $maxx= '450'; $maxy= '450'; photoresize($source, $maxx, $maxy); //photo small resizen $source = $destination2; $maxx= '75'; $maxy= '75'; photoresize($source, $maxx, $maxy); } $sql="INSERT INTO photo (file) VALUES ('$file')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } and the used functions: function photoupload($filename, $source, $destination, $destination2) { /*START PHOTOUPLOAD*/ // Does the file have the right MIME type? if ($_FILES[$filename]['type'] != 'image/pjpeg' AND $_FILES[$filename]['type'] != 'image/jpeg' AND $_FILES[$filename]['type'] != 'image/gif' AND $_FILES[$filename]['type'] != 'image/png' AND $_FILES[$filename]['type'] != 'image/wbmp') { echo 'the file you want to upload is no photo, please go back to try again'; exit; } move_uploaded_file ($source, $destination ); copy($destination, $destination2); return 0; /*END PHOTOUPLOAD*/ } function photoresize($source, $maxx, $maxy) { /*START PHOTORESIZE*/ // Get current dimensions list($width_orig, $height_orig) = getimagesize($source); // Check if they are over their limit if ( ($width_orig > $maxx) || ( $height_orig > $maxy)) { if ($maxx && ($width_orig < $height_orig)) { $maxx = ($maxy / $height_orig) * $width_orig; } else { $maxy = ($maxx / $width_orig) * $height_orig; } // Resample voorbereiden $image_p = imagecreatetruecolor($maxx, $maxy); $image_type = strtolower( substr($source, strrpos( $source, '.' )) ); switch( $image_type ) { case '.gif' : $image = imagecreatefromgif($source); break; case '.jpg' : $image = imagecreatefromjpeg($source); break; case '.jpeg': $image = imagecreatefromjpeg($source); break; case '.png' : $image = imagecreatefrompng($source); break; case '.bmp' : $image = imagecreatefromwbmp($source); break; } // Resample de afbeelding imagecopyresampled($image_p, $image, 0, 0, 0, 0, $maxx, $maxy, $width_orig, $height_orig); // Output switch( $image_type) { case '.gif' : imagegif($image_p, $source, 100); break; case '.jpg' : imagejpeg($image_p, $source, 100); break; case '.jpeg' : imagejpeg($image_p, $source, 100); break; case '.png' : imagepng($image_p, $source, 100); break; case '.bmp' : image2wbmp($image_p, $source, 100);break; } } return 0; /*END PHOTORESIZE*/ } hope it helps!
  24. i'm not sure that i understand all your code, but seeing what is php and what not, does this work? (just place all between echo and alternate between html and php with code between '' and code that is not, added together with dots) $userObj->_userId = $_SESSION['G_userId'.CONFIG_SITE_NAME]; $userObj->getUserDetails(); echo '<a href="'.CONFIG_SITE_PATH.'/settings.php">'.$userObj->_name.'</a></span> / <a href="logout.php" >Logout</a></span>';
  25. dont let them use html-tags, but let them use bb-tags instead (like within this forum) so make your users know that they should use [b] and [/b], [u] and [/u] etc.. after getting the information in, use htmlspecialchars to remove all html-entries and make the code save: $data= htmlspecialchars(trim($_POST['data'])); store it and after that, just before placing the data, replace all the bb-tags with html again with str_replace: $data= str_replace("[b]", "<b>", $data); $data= str_replace("[/b]", "</b>", $data); $data= str_replace("[u]", "<u>", $data); $data= str_replace("[/u]", "</u>", $data); etc.. and after that, you can place the data echo $data;
×
×
  • 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.