Jump to content

simcoweb

Members
  • Posts

    1,104
  • Joined

  • Last visited

Everything posted by simcoweb

  1. Ok, got it. I modified that line as you laid out but still got no results. That's because I kept that one part ('banned_ip') in there thinking it was necessary. I deleted it and now it works fine. Thanks for the help! Finished code: [code]foreach($_POST['banip'] as $ipkey => $ip) {     $sql = "DELETE FROM banned_ip WHERE banned_ip = '$ip'";     mysql_query($sql); } // if successful we do this echo "<center><font face='Verdana' size='2'>IP address $ip has been reinstated.<br />";[/code]
  2. I have this code in a script that parses the data from a form and inserts it into the MySQL database. [code]echo '<form action="unban.php" method="POST">'; while($row = mysql_fetch_array($result)) {   echo "<br><table width='400' border='1' padding='3'><tr><td align='center'>";     echo '<input type="checkbox" name="banip[]" value="' . $row['banned_ip'] . '" /> &nbsp; &nbsp;';     echo $row['banned_ip'] . "<br />\n";     echo "</td></tr></table><br />";   } if (mysql_num_rows($result) == 0) { echo "<p><center>There are currently no banned IP addresses in the database."; } else { echo "<p><center>Here are the current banned IP addresses. Select the checkbox next to any IP you wish to unban and click below<br>"; echo '<br><input type="submit" name="unban" value="UnBan Selected"></form>'; }[/code] This is the code i'm trying to use to delete the items upon hitting submit IF they are checkmarked: [code]$ip = $_POST['banip']; // this will erase the banned IP addresses chosen by the administrator mysql_connect($dbhost, $dbuser, $dbpass) or die('No database connection!'); mysql_select_db($dbname) or die('Cannot find that darn database!'); // now we run our query and deletion based upon what is checked foreach($_POST['banip'] as $ipkey => $ip) {     $sql = "DELETE FROM banned_ip (`banned_ip`) VALUES ('$ip')";     mysql_query($sql); } // if successful we do this echo "<center><font face='Verdana' size='2'>IP address $ip has been reinstated.<br />";[/code] The first section of code works just peachy. It displays the IP addresses that i've selected to be banned along with a checkbox next to it. the second section extracts that value and uses it to delete the checkmarked item. It gives me a successful message that the IP address has been reinstated but when I check again the IP address was not deleted. Ideas?
  3. I moved the header() statement to the 'else' section and now it works fine. The original point of insertion you specified was in the 'if' section which would then redirect the page if the person was indeed banned. Now it just displays the message as it should. Thanks for all the help! :)
  4. I checked the config.php and there was a blank white space after the closing tag. I deleted that, reuploaded and then the error switched to pointing to the header.php as the problem. Since the header.php file only contains one line calling an image I commented out the include statement and wrote an echo statement to call the image and now no errors show up. However, it's still redirecting if the IP is banned instead of just displaying the message.
  5. Ok, I commented out the include 'header.php' and it still shows that same error. So, it's not something in the header file. It keeps pointing to the last line of the config.php file as the culprit but that's just the closing PHP tag. I tried a few ways to get the javascript to parse on an echo call but couldn't seem to get it to work. Is there a special format I have to put that in?
  6. The config file contains strictly variables. Line 15 is actually a comment // Here's the lineup: [code]<?php //comment //comment //another comment // MySQL Database information - edit these variables $dbname = 'database_name'; $dbhost = 'localhost'; $dbuser = 'username'; $dbpass = 'dbpassword'; // Admin password $admin_password = "eatpotatoes"; // Site URL $siteurl = 'http://www.xxxxxxx.com/iptest/csv/iplog.zip'; // Site email $site_email = 'yourname@yourdomain.com'; ?> [/code] In the main script there's two include files at the top before your header statement. One is the include 'config.php' and the other is include 'header.php' which contains basically a title tag and image reference.
  7. I got this error when I inserted the header code where you specified: [quote]Warning: Cannot modify header information - headers already sent by (output started at /home/xxxxxx/public_html/iptest2/config.php:15) in /home/xxxxxx/public_html/iptest2/index.php on line 32[/quote] In my 'logical' mind I thought that the javascript code could be executed if placed in the 'else' section which would make sense since I only want them to be redirected IF they are not banned. The idea is if they reach an unauthorized area then the script would redirect them to an authorized area. If they are banned from the site it should just display the banned message and not redirect. Or, I could be a real prick and have it redirect them to some porn site or similar. But, then again, that may not be punishment ;) So, in my noobiest way, I attempted to place the javascript code inside the else statment, got an error about unexpected '<', placed some quotes around it, got more errors, tried an echo command, got an error... rinse, repeat 45 times. So...
  8. thorpe, yes the table/fields are right and they are actually named 'banned_ip' for each and I did change them from your original post. Turns out the problem was something in the copy/paste of the code from this post to my file. Not sure why or how it did it but it left off the ; on the first 'if' statement which caused it to break. I fixed that and then got the next error about line 24 which didn't make sense either. So, I copied the code again but this time stuck it into a text editor to strip out the extra characters, pasted it in, changed the $result line to the one wildteen88 recommended and now it's working. I do have one more question. I want to run this javascript redirect code IF the results return as false. Right now I have it placed outside the PHP brackets so it redirects no matter what. What I want to happen is that IF they are indeed on the banned list that the 'You're banned...' message displays and stays there. Only IF they are not banned should it redirect. Here's the code: [code]<script language=javascript> // Adjust the time and URL for the redirect. 1000 equals 1 second. Currently set at 6 secs. window.setTimeout("location='http://www.yoursitename.com/index.php'",6000); </script>[/code] Is there a way to execute this inside the PHP tags and IF they return false only? Or, should I use a PHP 'header' method to do it instead?
  9. Hey, thanks for the ultra-fast response! Ok, I replaced the current function with your changes. It still displays the 'else' information instead of the 'You're banned...' as it should and produces this error (which, i'm assuming is why it's not displaying the 'You're banned... ' text): Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/xxxxxxx/public_html/iptest2/index.php on line 24 This is line 24: [code]if (mysql_num_rows($result) == 1) {[/code]
  10. Summary: This landing page is supposed to check the visitor's IP address against a data table to see if it's been 'banned'. If so, displays one message that they are banned. If not, performs another function and displays entirely different message and logs the visitor's IP address into the database. The first section of this code is supposed to check against the IP's in the 'banned_ip' table and return a true or false then proceed accordingly. [code]//check for the possibility if it is banned before we write it to the database function isbanned($ip) {   $sql = "SELECT banned_ip FROM banned_ip WHERE ip = '$ip'";   if ($result = mysql_query($sql)) {     return true;   }   return false; } if (isbanned($_SERVER['REMOTE_ADDR'])) {   echo "<table align='center' width='500' bgcolor='C0C0C0'><tr><td><center><font face='Verdana'><h3>Your IP address has been banned from accessing this site.</h3><font face='Verdana' size='2'> If you feel this is in error you can contact the site administrator <a mailto='$site_email'>via email</a><br></td></tr></table>"; } else { // go about whatever it is you want to do. // Insert a row of information into the table "iplog" mysql_query("INSERT INTO iplog (ip, date, directory) VALUES('$ip', '$v_date','$dir') ") or die(mysql_error()); print "<table width='500' align='center' border='1'><tr><td>"; print "<table width='100%'><tr><td bgcolor='#C8D4DF'>"; echo "<center><font face='Verdana'><h3>Unauthorized Access Warning Message</h3></font>"; print "</td></tr>"; print "<tr><td bgcolor='#FFF0C0'>"; print "<center><h3>You should not be here</h4><p>"; print "</td></tr>"; print "<tr><td bgcolor='#FFF0C0'>"; echo "<center><font size='2' face='Verdana'>Your IP address is ". $ip . " and has been logged</font><p>"; echo "$v_date<p>"; echo "<center><font size='1' face='Verdana'><strong>You will be redirected to an authorized page.</strong></font>"; print "</td></tr></table></td></tr></table>"; }[/code] What's happening is it appears to be skipping the validation and displays the second set of HTML about the logging of their IP address. I have banned my own IP address and then returned to the page that should be telling me i've been banned but it's not working. Ideas?
  11. Ahhh yes...the simple missing ;  I've had that as well. Glad you found it!
  12. Heh..like I said..i'm a noob. Using the forums to learn more. Ok, a couple of things. Your last query example is correct. I think I was focusing on the comma separating the two fields and the lack of a space between the comma and the second field name.  I honestly don't know if that makes  a diff or not but what was being reported was a syntax error. Here's the example I use: [quote]$query = "SELECT b_name, b_author, b_cat, b_price from lib where id='" . $book_id . "'";[/quote] Noting the list of fields, the comma, then the space to separate. It's just a thought. But why you're getting an error unrelated to this query is strange. Unless you have a second query statement in your code.
  13. What's the new error? That could possibly resolve it further. In regards to the Select statement, once again i'm a noobster, but looking at the syntax in the MySQL manual there's either a space or some sort of operator between the query commands ( ie: the '*' for example). Otherwise it's pretty much like this: $sqlUser = "SELECT FROM users (username, Account) WHERE id='$userid'"; This reference link might help :) [url=http://dev.mysql.com/doc/refman/4.1/en/select.html]http://dev.mysql.com/doc/refman/4.1/en/select.html[/url]
  14. I'm not an expert but in this statement: [quote]$sqlUser = "Select username,Account from users where id='$userid'";[/quote] I've never used a comma in the query string. The one you have after 'username'. Remove that, put a space there, and try again.
  15. First, thanks for the response. Secondly, I was assuming that even in my logical mind that I was over complicating it. This looks simple and easy to adapt. I'm soaking this stuff up like a sponge Thanks for the help!
  16. Here's the scenario: I have a script that pulls their IP address along with the date and the directory and posts that information to a mysql database. What I want to do  now is have the script be capable of banning ip's. So, to do so the script must first determine it (which it does) but before it adds it to the database it needs to check to see if it's possibly in the 'banned' section. If that IP is banned then it should display a separate message. (like 'you are banned, dude!). Here's the code for the main page that collects and writes the data: [code]<?php $ip = $_SERVER["REMOTE_ADDR"]; $dir = $_SERVER["REQUEST_URI"]; include 'config.php'; //edit the location of your logging file or MySQL database in the config.php include 'header.php'; //set the date $v_date = date("l d F H:i:s"); print "<table width='500' align='center' border='1'><tr><td>"; print "<table width='100%'><tr><td bgcolor='#C8D4DF'>"; echo "<center><font face='Verdana'><h3>Unauthorized Access Warning Message</h3></font>"; print "</td></tr>"; print "<tr><td bgcolor='#FFF0C0'>"; print "<center><h3>You should not be here</h4><p>"; print "</td></tr>"; print "<tr><td bgcolor='#FFF0C0'>"; echo "<center><font size='2' face='Verdana'>Your IP address is ". $ip . " and has been logged</font><p>"; echo "$v_date<p>"; echo "<center><font size='1' face='Verdana'><strong>You will be redirected to an authorized page.</strong></font>"; print "</td></tr></table></td></tr></table>"; //open the MySQL database and write to the table mysql_connect($dbhost, $dbuser, $dbpass) or die('Database will not open'); mysql_select_db($dbname); // Insert a row of information into the table "iplog" mysql_query("INSERT INTO iplog (ip, date, directory) VALUES('$ip', '$v_date','$dir') ") or die(mysql_error()); echo "<center><h2>Data logged successfully!<br />"; ?>[/code] I'm a noob so I think in logical expressions when it comes to what needs to be done. So, i've outlined it but I'm not sure how to code it. Here's my presumptions: 1) create a function() that would check the incoming $ip address against the MySQL database 2) the function would run a mysql_query into the 'banned' field of the db table to search for a match 3) the function would contain an 'if' statement pertaining to the query finding the match or not 4) the 'if' statement would state 'if a match is found... blah blah.. echo 'you suck and don't come back' 5) the 'else' statement would, if no match found, push the script to do its normal thing, display the normal message and log the new data Now, that's my logical brain mode. I've looked at some code that performs similar analysis/comparison that was posted in here for someone looking to validate if a username/password/email were already in the database. It makes sense but at the same time it's confusing. Here's the snippet: [code]//check to see if the login id or email is already being used $loginid_sql = sprintf("SELECT COUNT(*) AS loginid_match FROM `login_tbl ` WHERE `loginid` = '%s'", $login_id); $email_sql = sprintf("SELECT COUNT(*) AS email_match FROM `login_tbl ` WHERE `email` = '%s'", $email); $loginid_result= mysql_query($loginid_sql) or die(mysql_error()); $email_result= mysql_query($email_sql) or die(mysql_error()); $loginid_match= mysql_result($loginid_result, 0, 'loginid_match'); $email_match= mysql_result($email_result, 0, 'email_match'); if ( $loginid_match > 0 ) { //if there are any login ids that match     echo "This login id is already taken. Please try again";     include('register.html');//your register form     unset($loginid);     exit(); } if ( $email_match > 0 ) { //if there are any email addresses that match     echo "This email has already been used";     include('register.html');//your register form     unset($email);     exit(); } [/code] What I see is it does the inquiry to validate if it exists, runs the 'if' statements based upon the results. What I need is a simple way to either adapt this or do similar for my needs. I'm just stuck on the proper method. Thanks for any suggestions and code help :)
  17. Check this. I just copied and pasted the script into both a text editor and into a coding program. When copying and pasting it the last few lines are broken. Like this: [code]<b>Login Id :</b> $loginid <br> d</b> $password <br>"; <b>Passwor[/code] When it should look like this: [code] echo " Your account has now been created. You may login with the following information:<br>"; echo "<b>Login Id :</b> $loginid <br>"; echo "<b>Password</b> $password <br>";[/code] [color=red]tomfmason[/color], I don't mean to change your code. I'm just a noob. But what I'm pointing out is that the last echo statement you wrote that displays the username/password for some reason wouldn't copy and paste properly and was producing broken syntax errors 'as is' because of that. So, I changed it to 3 separate echo statements just to make sure it worked. I'm thinking that perhaps that's what happened to onthespot in his attempt to copy/paste and execute the code. Just a guess :)
  18. Great! Ok, i'll insert this and keep you posted. It's clear and understandable even for a noobster like me :)
  19. Here's a summary. This code extracts IP addresses, the date and the directory accessed from a MySQL database and displays it in a simple format/layout for viewing purposes. What i'd like to do is add the ability for the IP address to have a checkbox next to it in this display so the user can select which one(s) they'd like to ban. They would then select the respective IP's checkboxes and upon submit it would write these to a new table in the database called 'banned'. That part of the code I think I can muscle through. But the automatic display of the checkboxes that retain and pass the IP number is where I haven't a clue. Obviously it would work as a form function once they've selected the IP's they wish to ban. I could point the submit button action to something like 'banned.php' and have it write the results to the database. Once again, however, it's the extracting of the results from the MySQL database and having the checkbox displayed next to it that mystifies me. Here's my simple code right now that summons the data: [code]    // if successful it will connect to the database and display the info     mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());     mysql_select_db($dbname) or die(mysql_error());     echo $title . "<p>\n";     echo "</center><font face='Verdana' size='2'>Results show Ip address, date of entry, directory entered</font></center><p>";     print "<table align='center' width='600' border='0'><tr><td>";     // loop through array and print each line     $query = "SELECT * FROM iplog";     $result = mysql_query($query) or die(mysql_error());     while($row = mysql_fetch_array($result))     {     echo $row['ip']. " - ". $row['date']. " - ".$row['directory'];     echo "<br />";     }[/code] Any help would be appreciated. Thanks in advance!
  20. It would help if you posted your code :)
  21. Well son-of-a-biscuit-maker. Thanks for being the other set of 'eyes'!  ::)
  22. Simple. Trying to create a table. Looked at this code 'til i'm ready to puke. Compared with other ones i've done that work fine. Perhaps another set of eyes can set me straight. [code]<?php include 'config.php'; // Make connect to DB first mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error()); mysql_select_db($dbname) or die("Where is the dang database"); // Now we create the tables and rows mysql_query("CREATE TABLE members( business VARCHAR(255) NOT NULL, name VARCHAR(30) NOT NULL PRIMARY KEY, title VARCHAR(30) NOT NULL, phone VARCHAR(30) NOT NULL, email VARCHAR(30) NOT NULL, url VARCHAR(30) NOT NULL, details VARCHAR(30) NOT NULL, category VARCHAR(30) NOT NULL") or die(mysql_error()); echo "Table Was Created Successfully!"; ?>[/code] Error I get: [quote]You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 9[/quote] Hellllllllllllllllllp meeeeeeeeeeeeeeeeeeeeee.......  :P
  23. That class file was a snap and worked exactly as I needed. Thanks for pointing me to that great resource. That's definitely a class file that can be used a LOT.
  24. We're writing this file: [code]$data = ""; $result = mysql_query("SHOW COLUMNS FROM `iplog`") or die(mysql_error()); while($row = mysql_fetch_array($result)) {     $data .= $row[0].","; } $data = substr($data,0,-1)."\r\n"; $result = mysql_query("SELECT * FROM `iplog`") or die(mysql_error()); while($row = mysql_fetch_assoc($result)) {     foreach($row as $r) {         $data .= "$r,";     }     $data = substr($data,0,-1)."\r\n"; } $handle = fopen("data.csv","wb"); fwrite($handle,$data); fclose($handle);[/code] Which works great in creating the CSV file. However, we'd like to make this newly generated file downloadable. As it stands right now all i've been able to do is have it display the CSV file and the person would need to copy and paste it. Sorta lame i'd say. So, what I would like it to do is either: 1) write/create the file AND turn it into a downloadable zip file, or 2) write/create the file AND have another 'option' to download it which would then turn it into a zip file (so instead of write/zip at once it's two different functions). With scenario #2 the person could then decide if they want to copy and paste or zip and download. Ideas?
  25. I knew it would be something simple. Thanks for the help! :)
×
×
  • 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.