Jump to content

alpine

Members
  • Posts

    759
  • Joined

  • Last visited

Everything posted by alpine

  1. Example: <?php $arr1 = array(1,5,7,6); $arr2 = array(3,; $arr3 = array(2,0,6); $arr_all = array_merge($arr1,$arr2,$arr3); if($arr_all == array_unique($arr_all)) { echo "All values are unique"; } else { echo "One or more values was identical"; } ?>
  2. Try to set up some debugging by echoing id's etc while testing to see if it reveals anything. You are however constantly overwriting the $result during foreach, so the redirection is purely based on the last id delete New example: <?php if(isset($_POST['delete'])){ if(isset($_POST['checkbox'])){ $fail = array(); $ok = array(); foreach($_POST['checkbox'] as $no => $del_id){ $sql = "DELETE FROM $tbl_name WHERE id='$del_id'"; $result = mysql_query($sql) or die(mysql_error()); if(mysql_affected_rows() == 1){ $ok[] = "OK: ".$del_id; } else{ $fail[] = "Failed: ".$del_id; } } if(empty($fail)){ echo "<meta http-equiv=\"refresh\" content=\"0;URL=index.php\">"; } else{ echo "Following id's failed to delete:<br />"; echo implode($fail, '<br />'); echo "These id's returned ok and should be deleted:<br />"; echo implode($ok, '<br />'); } } else{ echo "No rows where selected to be deleted"; } } ?>
  3. On this part <?php if($delete){ for($i=0;$i<$count;$i++){ $del_id = $checkbox[$i]; $sql = "DELETE FROM $tbl_name WHERE id='$del_id'"; $result = mysql_query($sql); } // if successful redirect to delete_multiple.php if($result){ echo "<meta http-equiv=\"refresh\" content=\"0;URL=index.php\">"; } } ?> Change to <?php if(isset($_POST['delete'])){ foreach($_POST['checkbox'] as $no => $del_id){ $sql = "DELETE FROM $tbl_name WHERE id='$del_id'"; $result = mysql_query($sql); } // if successful redirect to delete_multiple.php if($result){ echo "<meta http-equiv=\"refresh\" content=\"0;URL=index.php\">"; } } ?> should get you going
  4. Can't you just run both jobs in the same file ? Simplified example: [code] <?php $hide_form = false; if(isset($_POST['submit_preview'])){   echo htmlspecialchars(nl2br($_POST['message']), ENT_QUOTES);   } elseif(isset($_POST['submit_save'])){ // save posted message $hide_form = true; } if($hide_form == false){ echo <<<_FORM <form method="post" action="test.php"> <textarea name="message" rows="14" cols="70">$message</textarea> <input type="submit" name="submit_save" value="Save" /> <input type="submit" name="submit_preview" value="Preview" /> </form> _FORM; } ?> [/code] ...or did i misunderstand you ?
  5. Or something like this - example with textfields [code] <?php if(isset($_POST['submit'])) { $query = "select * from house"; $count = 0; foreach($_POST as $key => $value){ $value = htmlspecialchars($value, ENT_QUOTES); if($count == 0): $qq = " WHERE"; else: $qq = " OR"; endif; if(!empty($value)): $query .= "$qq $key = '$value'"; endif; $count++; } $query .= " order by houseid desc"; $sql = mysql_query($query) or die(mysql_error()); // fetch array, show results } else { // Each formfield name here, must match the target column names in your table (city,state) echo <<<_HTML <form action="search.php" method="post"> <p>City: <input type="text" name="city" /></p> <p>State: <input type="text" name="state" /></p> <p><input type="submit" name="submit" value="search" /></p> </form> _HTML; } ?> [/code]
  6. [b]test@server.co.uk[/b] doesn't pass [b]test@ser;ver.com[/b] passes ...and so will many many more - you should start checking against a valid range of chars instead of illegal chars when matching.
  7. [code] <?php $status = mail('me@mydomain.com','my subject','email text',$mailheaders); if($status == 1) {   // mail() returned true } else {   // failed } ?>[/code] That's about the closest you get to a success-machine
  8. Agree on something else being your problem if you have tried all solutions here, but not all of these suggestions work (on my server anyhow) A simplified collection of the proposed soulutions, just one works IF $title is set as "", two of them works if $title is not defined at all [code] <?php function setup_page1($title = false){ if($title == false) $title = "NO TITLE"; echo $title ."<br />"; } function setup_page2($title = "Untitled") { echo $title ."<br />"; } function setup_page3($title){ $title = (isset($title) || trim($title) != 0) ? "$title" : "NO TITLE"; echo $title ."<br />"; } $title = ""; setup_page1($title); // prints "NO TITLE" setup_page2($title); // prints nothing setup_page3($title); // prints nothing - but if $title is absent, this one works ?> [/code]
  9. In short: you can't reverse it
  10. This should work, look at the examples below: [code] <?php function setup_page($title = false){ if($title == false) $title = "NO TITLE"; echo " <html> <head> <title>My Database $title</title> "; } setup_page($title); // result: NO TITLE $title = ""; setup_page($title); // result: NO TITLE $title = "foo"; setup_page($title); // result: foo ?> [/code]
  11. You havent got any result div at all in your code Taking your code, adding a result div - and it's fine in both IE6 and IE7 + FF [code] <html> <head> <script language="javascript"> function ajaxTest( id ) { var ajaxRequest; try{ ajaxRequest = new XMLHttpRequest(); } catch (e){ try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e){ try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ alert("Your browser broke!"); return false; } } } ajaxRequest.onreadystatechange = function() { if(ajaxRequest.readyState == 4) { var ajaxDisplay = document.getElementById(id); ajaxDisplay.innerHTML = ajaxRequest.responseText; } } var field = document.getElementById('field').value; var queryString = "?field=" + field; ajaxRequest.open("GET", "aj_test.php" + queryString, true); ajaxRequest.send(null); } </script> </head> <body> <form action="test.php" method="post" > <table cellpadding="0" cellspacing="0" class="table_edit" width="800"> <tr> <td width="40" align="left" valign="middle" > &nbsp;&nbsp;<span style="color:#003366; text-decoration:">CNP<span>:&nbsp;&nbsp; </td> <td  width="160" align="left" > <input class="fields2" type="text" id="field" name="cnp" value="" size="15" maxlength="13" /> </td> <td width="140"> <input class="submit" type="button" name="bigsubmit" value="Search" onclick="ajaxTest('victim');" /> </td> </tr> </table> </form> <div id="victim"></div> </body> </html> [/code] ..And, you call some <i>strange</i> function in your php file btw
  12. My level must be something in the area of "level 2 beginner" - i'm past all those parse errors and i find my way around the manual.
  13. As i don't see the point in doing this without using regex, i still found it to be an amusing idea. None of the above one does the trick, neither will my example - anyhow, here it is: [code] <?php function noregex_email($email){ $main = explode('@', $email); if(count($main) <> 2){   return false; } $domain = explode('.',$main[1]); if(!in_array(count($domain), array(2,3))){   return false; } foreach($domain as $dom){   if(strlen($dom) < 2){     return false;   } } $valid = array_merge(range('a','z'), range('0','9'), array('-','_','.')); foreach(str_split(strtolower($email)) as $char){ if($char == "@") $char = "a"; if(!in_array($char, $valid, true)){   return false; } } return true; } ?> [/code]
  14. Sorry for not spotting this sticky - too many stickie makes it tricky (blæh.) I have an issue with very small fonts inside code areas, thread i made this morning with expl: http://www.phpfreaks.com/forums/index.php/topic,121741.0.html
  15. Well, the code is clearly smaller than before and on my laptop (witch i almost without exeption use) and it's simply too small to bother reading now. The fonts melts together in a blur. I'm running widescreen 14.1" WXGA 1280x768 Must be other than me that notices this and now are having problems reading code contents ? With the fonts like they are now - sorry, i can't read it on my machine.
  16. What happend ? The [ code ] fonts appears very small suddenly.... On my laptop it's now very hard to read. [attachment deleted by admin]
  17. And you should remove all those session_register(), learn more: http://no2.php.net/manual/en/function.session-register.php
  18. Don't think utf-8 will work on those, try [code] <?php $text = str_replace(array("Æ","æ","Ø","ø","Å","å"),array("& # 198;","& # 230;","& # 216;","& # 248;","& # 197;","& # 229;"),$text); ?> [/code] *EDIT* some problems getting them visually right displayed  in this board... Remove the spaces in the code between "& # foo"
  19. Example with sessions, jumping to another file upon success: [code] <?php session_start(); if(isset($_POST['submit'])) { $empty_arr = array(); foreach($_POST as $fieldname => $fieldvalue) {   if(empty($fieldvalue))   {     $empty_arr[] = $fieldname." was left empty";   }   ${$fieldname} = $_POST[$fieldname]; // just so that submitted values can be re-displayed in the form if another field value is missing   $_SESSION[$fieldname] = ${$fieldname}; // also store value in a session in case no field values is missing in the end } if(!empty($empty_arr)) {   echo "<ul><li>";   echo implode($empty_arr, '</li><li>');   echo "</li><ul>"; } else {   header("location: next.php"); // and in next you fetch all current data from $_SESSION['fieldname']     // inside next.php you can put this as a test (uncomment it ofcource):     // <? php   // session_start();   // echo "<pre>";   // print_r($_SESSION);   // echo "</pre>";   // ? >     exit(); } } echo <<<_HTML <form method="post" action="{$_SERVER['PHP_SELF']}"> <p>Name:<br /><input type="text" name="name" value="$name" /></p> <p>Email:<br /><input type="text" name="email" value="$email" /></p> <p><input type="submit" name="submit" value="Send" /></p> </form> _HTML; ?> [/code]
  20. Here is one example using a function, just include the function on every page you expect to use it [code] <?php function NotDemo(){ $user = htmlspecialchars($_SESSION['user'], ENT_QUOTES); $check = mysql_query(" SELECT `id` FROM `login` WHERE `user` = '$user' AND level = 1 "); if(mysql_num_rows($check) == 1) {   return true; } else {   Print 'Error: You do not have access.';   include('includes/admin_footer.php');   exit(); } } // then use it if(NotDemo()) {   // ok, made it here so it's not running demo mode } ?> [/code] I don't prefer using echo, include and/or exit within a function check like this - but it works
  21. The easiest way is to run the validation on the same page as the form. Usually this is not a problem. Example: [code] <?php $complete = false; $empty_arr = array(); foreach($_POST as $fieldname => $fieldvalue) {   if(empty($fieldvalue))   {     $empty_arr[] = $fieldname." was left empty";   }   ${$fieldname} = $_POST[$fieldname]; } if(!empty($empty_arr)) {   echo "<ul><li>";   echo implode($empty_arr, '</li><li>');   echo "</li><ul>"; } else {   // no empty fields, prosess posted values already defined as $fielnames   $complete = true; } if($complete == false) { echo <<<_HTML <form method="post" action="{$_SERVER['PHP_SELF']}"> <p>Name:<br /><input type="text" name="name" value="$name" /></p> <p>Email:<br /><input type="text" name="email" value="$email" /></p> <p><input type="submit" name="submit" value="Send" /></p> </form> _HTML; } ?> [/code]
  22. You seem to do the mysql_num_rows bit wrong, if num rows is equal to 1 changes are allowed, else no changes can be made. Another twist is to simply set a session with the level stored and check by that - it will save you a query Example: [code] <?php // in login, set session as 0 for demo account $_SESSION['level'] = "0"; // wherever you are about to do some changes, check the session level if($_SESSION['level'] > "0") {   // level is above demo, do the desired changes } else {   echo "Demo mode in affect, no changes can be made"; } ?> [/code] Your db version would look something like this: [code] <?php $user = htmlspecialchars($_SESSION['user'], ENT_QUOTES); $check = mysql_query(" SELECT `id` FROM `login` WHERE `user` = '$user' AND level = 1 "); if(mysql_num_rows($check) == 1) { // do the required task include('includes/admin_footer.php'); exit(); } else { echo "Demo mode in affect, no changes can be made"; include('includes/admin_footer.php'); exit(); } ?> [/code]
  23. If you want help on this forum you have to bother posting your relevant script here too. Out of curiosity i tried your link anyhow but it would never load possibly due to a slow server in the other end. So, post your code!
  24. It works if set as 'timestamp' and presumeable as 'datetime'
×
×
  • 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.