Jump to content

alpine

Members
  • Posts

    759
  • Joined

  • Last visited

Everything posted by alpine

  1. Or use foreach [code] <?php $files = array("one.jpg","two.jpg","whatever.jpg"); foreach($files as $file) {   if(file_exists($file)) echo "$file does exist <br />"; else break; } ?> [/code]
  2. You have a misplaced tr close, probably that one messing up: echo "<table width='500 px' height= '400 px' align = 'center' border='1' cellpadding='3' cellspacing='3'>[color=red] </tr>"[/color]; **EDIT** Noticed another one - missing close bracket on one of your tr starts echo "<tr bgcolor='#ddd8dc'[color=red]>[/color]"; } else { echo "<tr bgcolor='#feaae9'>";
  3. You can detect your own cookies when logged in on your own system and thereby determ keys [code] <!-- Find cookies --> <?php print "<pre>"; print_r($_COOKIE); print "</pre>"; ?> <!-- Outputs --> Array (     [PHPSESSID] => 93aecbf189f91b972145dcf25a42610a     [user] => blabla     [ip] => 88.216.180.88     [code] => 923hdhuewh934y39euhudhwd ) <!-- use information now that you know the key names --> <?php $user = $_COOKIE['user']; ?> [/code] Otherwise, use the third party scripts section for help on phpBB: http://www.phpfreaks.com/forums/index.php/board,34.0.html[/code]
  4. I cannot see that you are fetching the result from the MAX query named $results ..... You need to run e.g. mysql_fetch_array($results) - as you have it now you only run the mysql_query($results)
  5. Wow - i feel very honored to be decorated with this title, despite my moderate number of post's on this great and without doubt in my mind the no.1 PHP community. I must join in on redbullmarky's appreciation to PHPFreaks - and add that this is the forum where i've learned to get started on PHP and Mysql + this is the forum where i get my inspiration to continuously move on learning as time never stands still here! Thank you  :)
  6. This will detect empty, but the number 0 will pass as not empty [code] <?php if(empty($scorehome) && !preg_match("/^[0]+$/", $scorehome)) { echo "value is empty but NOT number 0"; } ?> [/code]
  7. [quote author=mgallforever link=topic=110627.msg447561#msg447561 date=1160085805] It isnt working Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/neoblob/public_html/inc/do_reg.inc on line 20 [/quote] Did you change your table- and fieldnames etc. ?
  8. [code] <?php $num = mysql_result(mysql_query("select count(*) from users where user = '$user' or email = '$email' or ip = '$ip'"),0); if($num == 1) {   // already exists } ?> [/code]
  9. Do you mean adding a message to the user if they already exist in db ?
  10. To ensure YOUR form really is the source of POST, you could generate a random string and include it in a hidden field in your form simultaniously as you insert the same random string into a mysql table. When checking the POST'ed form, match the posted random string against the one stored in mysql --> Match = ok, if not - abort. Regardless, clean up and delete the string from mysql.
  11. [code] <?php $value = 192; switch(true) { case in_array($value, range(1,400)): echo "between 1-400"; break; case in_array($value, range(401,601)): echo "between 401-601"; break; } ?> [/code]
  12. Now - i would agree on some rewriting on this, but i've re-arranged a bit on your original post You probably are using POST on this too, so defining variables as POST.... [code] <?php session_start(); include("db.php"); if(!empty($_POST['email'] || !empty($_POST['password'] ) { $error = "Please Fill Out Both Fields!"; header("Location: index.php?error=".$error.""); exit(); } else { $email = mysql_real_escape_string($_POST['email']); $password = mysql_real_escape_string($_POST['password']); $getinfo = mysql_query("SELECT password FROM users WHERE email = '$email'") or die(mysql_error()); if(mysql_num_rows($getinfo) == "1") { $user = mysql_fetch_array($getinfo); if(md5($password) == $user['password']) { $_SESSION['css'] = $email; header("Location: index.php"); exit(); } else { $error = "The Password You Entered Was Incorrect!"; header("Location: index.php?error=".$error.""); exit(); } } else { $check_admin = mysql_query("SELECT password FROM admins WHERE email = '$email'") or die(mysql_error()); if(mysql_num_rows($check_admin) == "1") { $admin = mysql_fetch_array($check_admin); if(md5($password) == $admin['password']) { $_SESSION['cssadmin'] = $email; } else { $error = "The Password You Entered Was Incorrect!"; header("Location: index.php?error=".$error.""); exit(); } } else { $error = "Their Is No Such Email Registered Here!"; header("Location: index.php?error=".$error.""); exit(); } } } ?> [/code] But instead of running for only matches on email and then extracting password from db, it would be better to simply run "SELECT id FROM users WHERE password = '$password' AND email = '$email'" I see you are comparing to see if the user have the identical password as the one actually stored in db on THAT username, and giving an error msg if the password is incorrect. In my point of view you should not give that kind of message because then you have already revealed a valid username with only a wrong password. One barrier less to break. Nevertheless, this is quite common afterall - I prefer to keep login usernames just as secret as login passwords and just give a common "no found" message on failure.
  13. How/where do you define $id ? As it is now you are depending for register globals set ON - and my guess is that $id is not set here. *EDIT* I see it in your second query as GET Also, you are not setting delete properly in your link (i added the red bit): a href=$PHP_SELF?delete[color=red]=1[/color]&id=$id [code] <?php if (isset($_GET['delete']) && !empty($_GET['id'])) { $sql = mysql_query("DELETE FROM web_announcements WHERE id='$id'") or die(mysql_error()); if($sql) echo "The announcement has successfully been removed.<br><br>- <a href=./acp.php>Back</a>"; else echo "No row deleted.."; } else { echo "You are now ready to either remove or edit an announcement, please select your options below.<hr color=#990000>"; $query = mysql_query("SELECT * FROM web_announcements") or die(mysql_error()); while ($results = mysql_fetch_array($query)) { extract($results); echo"- $title (<a href=>EDIT</a>)/(<a href=$PHP_SELF?delete=1&amp;id=$id>DELETE</a>)<br>"; } } ?> [/code] Another thing (not related to the error) - you should start using $_GET[] instead of $HTTP_GET_VARS[] http://no2.php.net/manual/en/language.variables.predefined.php
  14. [code] <?php $value = "0"; $arr = array(); $arr["no 1"] = $value; $arr["no 2"] = "$value"; $arr["no 3"] = (float)$value; $arr["no 4"] = (string)$value; $arr["no 5"] = (bool)$value; $arr["no 6"] = (object)$value; $arr["no 7"] = (int)$value; foreach($arr as $key=>$value) {   if(empty($value)) echo $key." is empty | ";   else echo $key." is not empty | "; } ?> [/code] echo --> [code] no 1 is empty | no 2 is empty | no 3 is empty | no 4 is empty | no 5 is empty | no 6 is not empty | no 7 is empty | [/code]
  15. [code] (SELECT username FROM user1 WHERE username = '$username') UNION (SELECT username FROM user2 WHERE username = '$username') UNION (SELECT username FROM user3 WHERE username = '$username') [/code]
  16. This could be lots of different things, you could have an include - issue, form - issue etc. etc. I suggest you post a code example..
  17. That's not your primary problem here, Change --> [color=red]if ( $_POST['action'] == "Login" )[/color] to --> [color=blue]if ( $_GET['action'] == "Login" )[/color] for it to work as you intended in this script (POST to GET on THAT variable) Still it would be better to name the submit button e.g. "submit" and then sniff for --> if(isset($_POST['submit'])) ....then removing the get variable in your form action.... Just a point of view though..
  18. You have a misplaced closing bracked in your switch-statement, Remove that and it seems good to go..: [color=red]}[/color] break; case "activate":
  19. Don't know what's not working since you don't post your current code - but Give this a go! [code] <?php elseif(isset($_POST['register'])) { //put errors into an array $errors = array(); $set_estaffcode = "wombat"; if(!empty($_POST['estaffcode'])) { if($_POST['estaffcode']==$set_estaffcode) { $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); $email = mysql_real_escape_string($_POST['email']); $activation_code = generateCode(25); $userq = "SELECT username FROM user_system WHERE username = '$username' LIMIT 1"; $emailq = "SELECT email FROM user_system WHERE email = '$email' LIMIT 1"; } else { $errors[] = "E-Staff Authorization Code not Valid! <br />"; } } else { $errors[] = "E-Staff Authorization Code was blank! <br />"; } if(empty($username)) { $errors[] = "The username field was blank! <br />"; } if(mysql_num_rows(mysql_query($userq)) > 0) { $errors[] = "The username given is already in use! Please try another one! <br />"; } if(empty($password)) { $errors[] = "The password field was blank! <br />"; } if(empty($email)) { $errors[] = "The email field was blank! <br />"; } if(mysql_num_rows(mysql_query($emailq)) > 0) { $errors[] = "The email given is already in use! Please try another one! <br />"; } if(count($errors) > 0) { foreach($errors as $err) { echo $err; } } } ?> [/code]
  20. Could you show us the query you are using ?
  21. http://dev.mysql.com/doc/refman/5.0/en/fulltext-boolean.html
  22. It does split and search each one - however i've added some () in first where clause (it did however split as it was too), and by echoing the $query you see what the final query looks like later on: [code] <?php $start = 0; // only set here for visual purposes $per_page = 10; // only set here for visual purposes $search = htmlspecialchars($_GET['search']); $sq = explode(" ",$search); $aq = count($sq) - 1; $ac = 0; if($aq>0): $qq = "("; $qc = ")"; else: $qq = ""; $qc = ""; endif; for($i=0; $i<=$aq; $i++) { if($ac == 0) { $query = "SELECT * FROM womensproducts WHERE $qq ProductName LIKE '%$sq[$i]%'"; $query .= " OR CategoryID LIKE '%$sq[$i]%'"; $query .= " OR Category LIKE '%$sq[$i]%' $qc"; } else { $query .= " AND ( ProductName LIKE '%$sq[$i]%'"; $query .= " OR CategoryID LIKE '%$sq[$i]%'"; $query .= " OR Category LIKE '%$sq[$i]%' )"; } if($aq == $ac) { $query .= " limit $start, $per_page"; } $ac ++; } //$result = mysql_query($query) or die(mysql_error()); echo $query; ?> [/code] With a search-url like www.site.com/search.php?search=blue+blouse this is what you get if you echo $query: [code] SELECT * FROM womensproducts WHERE ( ProductName LIKE '%blue%' OR CategoryID LIKE '%blue%' OR Category LIKE '%blue%' ) AND ( ProductName LIKE '%blouse%' OR CategoryID LIKE '%blouse%' OR Category LIKE '%blouse%' ) limit 0, 10 [/code] Now, another issue might be that you need to match the exact frases "blue" and "blouse" - in that case you must remove all [color=red]%[/color] located around each $search inside the query string If you use %$search% you will match on for example "nonblues" and "antiblouses" If you use %$search you will match on for example "bluesbrothers" and "blouses" If you use $search you will match only "blue" and "blouse" And the htmlspecialchars will take care of db security If you wrote this search-script yourself, you will be able to implement this and work your way.
  23. My example was only replacing one query as example, i've put it in place here - test and adjust: [code] <?php include("config.php"); // Get the category or assign a defailt if (isset($_GET['search'])) $search = htmlspecialchars($_GET['search']); else $search = "Dress"; // enter a default category here $sq = explode(" ",$search); $aq = count($sq) - 1; $ac = 0; for($i=0; $i<=$aq; $i++) { if($ac == 0) { $query = "SELECT count(*) FROM womensproducts WHERE ProductName LIKE '%$sq[$i]%'"; $query .= " OR CategoryID LIKE '%$sq[$i]%'"; $query .= " OR Category LIKE '%$sq[$i]%'"; } else { $query .= " AND (ProductName LIKE '%$sq[$i]%'"; $query .= " OR CategoryID LIKE '%$sq[$i]%'"; $query .= " OR Category LIKE '%$sq[$i]%')"; } $ac ++; } $result = mysql_query($query) or die(mysql_error()); $num_records = mysql_result($result,0,0); if ($num_records == 0){   echo "There are no records to display in the selected category, please select another\n";   exit; } // Set maximum number of rows and columns $max_num_rows = 3; $max_num_columns = 3; $per_page = $max_num_columns * $max_num_rows; // Work out how many pages there are $total_pages = ceil($num_records / $per_page); // Get the current page number if (isset($_GET['page'])) $page = $_GET['page']; else $page = 1; // Work out the limit offset $start = ($page - 1) * $per_page; // Run your query with the limit and offset in place $ac2 = 0; for($i=0; $i<=$aq; $i++) { if($ac2 == 0) { $query2 = "SELECT * FROM womensproducts WHERE ProductName LIKE '%$sq[$i]%'"; $query2 .= " OR CategoryID LIKE '%$sq[$i]%'"; $query2 .= " OR Category LIKE '%$sq[$i]%'"; } else { $query2 .= " AND (ProductName LIKE '%$sq[$i]%'"; $query2 .= " OR CategoryID LIKE '%$sq[$i]%'"; $query2 .= " OR Category LIKE '%$sq[$i]%')"; } if($aq == $ac2) { $query2 .= " limit $start, $per_page"; } $ac2 ++; } $result_main = mysql_query($query2) or die(mysql_error()); $num_columns = ceil(mysql_num_rows($result_main)/$max_num_rows); $num_rows = ceil(mysql_num_rows($result_main)/$num_columns); // If there's more than one page, show links if ($total_pages > 1){   echo <<<HTML   <table>     <tr>       <td> HTML;   // Build the previous link   if ($page > 1){       $prev = ($page -1);       echo "<a href=\"http://pluswomen.thefreestuffvault.com/moresear-{$search}-$prev.htm\">Previous</a>";   }   // Build the page numbers   for($i = 1; $i <= $total_pages; $i++){       if($page == $i){         echo "$i ";       }       else {         echo "&nbsp;<a href=\"http://pluswomen.thefreestuffvault.com/moresear-{$search}-$i.htm\">$i</a> &nbsp;";       }   }   // Build the next link   if ($page < $total_pages){       $next = ($page +1);       echo "&nbsp;<a href=\"http://pluswomen.thefreestuffvault.com/moresear-$search-$next.htm\">Next</a>";   }   // Close off the links   echo <<<HTML       </td>     </tr>   </table> HTML; } // Lets start creating tables and echoing code echo "<table>\n"; $c = 0; while($row = mysql_fetch_array($result_main)){   // make the variables easy to deal with   extract($row); if($row["prodSale"] < $row["prodPrice"] and $row["prodSale"] != NULL){     $price = $prodSale . " - Sale Price";       }       else {         $price = $prodPrice;       }   // open row if counter is zero   if($c == 0){       echo "<tr>";   }   // echo the individual cells   echo <<<HTML     <td align=center><table class="quick" width="180" height="350" border="0" align=center cellspacing="0" cellpadding="0">   <tr>     <td align=center><a href="http://pluswomen.thefreestuffvault.com/searchproduct-{$ProductID}.html"> <img rel="nofollow" src="{$BigImage}" border="0" height=180 alt="{$Name}"></a></td>   </tr>   <tr>     <td align=center><p id="productname"><a href="http://pluswomen.thefreestuffvault.com/searchproduct-{$ProductID}.html">{$ProductName}</A></p></td>   </tr>   <tr>     <td align=center><font size="2">Price: $ {$price}</font></td>   </tr> </table></td> HTML; // increment counter - if counter = max columns, reset counter and close row   if(++$c == $max_num_columns){       echo "</tr>";       $c = 0;   } } // clean up table - makes your code valid! if($c < $max_num_columns){   for($e = $c; $e < $max_num_columns; $e++){       echo "&nbsp;";   } } // If there's more than one page, show links if ($total_pages > 1){   echo <<<HTML   <table>     <tr>       <td align="center"> HTML;   // Build the previous link   if ($page > 1){       $prev = ($page -1);       echo "<a href=\"http://pluswomen.thefreestuffvault.com/moresear-$search-$prev.htm\">Previous</a>";   }   // Build the page numbers   for($i = 1; $i <= $total_pages; $i++){       if($page == $i){         echo "$i ";       }       else {         echo "&nbsp;<a href=\"http://pluswomen.thefreestuffvault.com/moresear-$search-$i.htm\">$i</a> &nbsp;";       }   }   // Build the next link   if ($page < $total_pages){       $next = ($page +1);       echo "<a href=\"http://pluswomen.thefreestuffvault.com/moresear-$search-$next.htm\">Next</a>";   }   // Close off the links   echo <<<HTML       </td>     </tr>   </table> HTML; } ?> [/code]
×
×
  • 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.