Jump to content

Zoey

Members
  • Posts

    27
  • Joined

  • Last visited

    Never

Everything posted by Zoey

  1. thorpe - I tried that and it still didn't work. Jenk - how do you mean?
  2. But its not an else.  The second clause should only happen under a specific set of circumstances, that are not the opposite of the circumstances called by the first if.
  3. If a new pet is being added, it does the first thing, else if the person is banned it does the second thing, otherwise it just goes onto the rest of the page.  The second one is not an else because users may not be adding pets and may not be banned but still should be able to access the rest of the page.
  4. Variables are being set: [code]<form method="POST" action="add_pet.php"> <table><tbody>   <tr><td>Pet name:</td><td><input type="text" name="new_pet" size="50"></td></tr>   <tr><td>Contact name:</td><td> <?php if (array_key_exists("username",$_SESSION)) print $_SESSION["username"];                       else print("<a href=\"user_login.php\">Log in first.</a>"); ?></td></tr>   <tr><td>Rules Page URL:</td><td><input type="text" name="owner_url" size="50"> </td></tr>   <tr><td>Color:</td><td><?php my_build_adv_listbox("neopets", "color", "id", "description",""); ?> </td></tr>   <tr><td>Species:</td><td><?php my_build_adv_listbox("neopets", "species", "id", "description",""); ?> </td></tr>   <tr><td>Sex:</td><td><?php my_build_adv_listbox("neopets", "sex", "id", "description","1"); ?> </td></tr>   <tr><td><input type="hidden" name="status" value="8"></td></tr>   <tr><td colspan=2 align=center><?php if (array_key_exists("username",$_SESSION)) print("<input type=\"submit\" name=\"Submit\" value=\"Add pet\">"); ?> </td></tr> </tbody></table> </form> [/code] Userlevel function: (it returns the userlevel for the user accessing the page) [code]function userlevel() { GLOBAL $_SESSION; if(array_key_exists("adminflags",$_SESSION)) { return $_SESSION["adminflags"]; } else {return 0;}; }[/code]
  5. Okay, so on my site, I'm having trouble with users being falsely banned.  I have userlevels set up so that 10 is user and anything below that is banned, frozen, etc.  So on my page where users can add new pets (it's a Neopets.com fansite, for anyone particularily interested) to the database, I've got this code: [code]   if($new_pet && userlevel() > 9)   {     if (array_key_exists("username",$_SESSION)) $owner=$_SESSION["username"];     if (array_key_exists("userid",$_SESSION)) $ownerid=$_SESSION["userid"];     if($today = getdate()) { $curdate = $today[year]."-".$today[mon]."-".$today[mday]." ".$today[hours].":".$today[minutes].":".$today[seconds]; }     $result=mysql_query("INSERT INTO pet (petname,ownername,owner_id,link_url,color,species,status,submitdate,sex) VALUES ('$new_pet','$owner','$ownerid','$owner_url','$color','$species','$status','$curdate','$sex');");     if($result)     {        print("\n<p><b><i>Pet $new_pet added.  Please note, you will not see your pet in the database immediately.  An admin will need to verify your pet before it is added.</i></b></p>\n");     }     else     {        print("\n<p><b><i>Add FAILED for pet $new_pet <br><br>Please check that your pet is not in the adopted<br>section before contacting a FAERIE FEEPIT admin.</i></b></p>\n");     }   } else if (userlevel() <= 9) { print ("<center>You cannot add pets after being banned from the database."); print ("</div><div id=\"rightcontent\">"); print_right_loginbar(); print ("</div></body>"); print ("</html></center>"); exit; } ?> The rest of the page coded here.[/code] So when some users are logging in while their userlevels are 10, they are finding that they have been 'banned' from the site (are getting that banned message).  However, when I log into their accounts, I am able to add pets and not get that banned message.  I have no clue why the same accounts would be banned for them and not for me.. and why users with userlevels of 10 would even ever get that error message.  I've been at this for a month, so really, any insight you can give me would be MUCHLY appriciated. Thanks.
  6. I created the table character, which has the following info: [code]`id` int(11) NOT NULL auto_increment,   `character` varchar(255),   PRIMARY KEY  (`id`)[/code] However, I later realized that I wanted the column character to be called description so it matched up with some of my other tables.  So using this code: [code]$sql = "ALTER TABLE `character` CHANGE `character` `description` varchar(255)"; mysql_query($sql) or DIE (mysql_error());[/code] I attempted to do that.  I received no error messages so I assumed everything was fine... however, when I plugged in this code: [code]$result = mysql_query("DESCRIBE `character`");   while ($row = mysql_fetch_array($result, MYSQL_NUM)) {     printf("%s %s", $row[0], $row[1]);   echo"<br>";   }     mysql_free_result($result) OR DIE (mysql_error());[/code] It was still displaying the following info, even after I refreshed a few times: [quote] id int(11) character varchar(255) [/quote] Instead of: [quote] id int(11) description varchar(255) [/quote] I dont have access to my server directly, so I have to make these adjustments via PHP.  I'm really hoping that someone can help me.  Thanks SO much!
  7. Hm, okay that got it to connect, but now I'm getting: Incorrect table definition; there can be only one auto column and it must be defined as a key
  8. No database selected Why would it be giving me that?  I'm only connecting to the one database, and the username and password and all that are correct.. copied and pasted from another page that works.
  9. Alright, I must have read through the syntax for creating a table in mysql a thousand and one times, but I cannot figure out what is wrong with my code.  I'm hoping another pair of eyes can help me. [quote] $database=mysql_connect("localhost","username","password"); $result=mysql_query("CREATE TABLE `poll` (   `id` int(11) NOT NULL auto_increment,   `name` varchar(50) default NULL,   `question` varchar(255) default NULL,   `bgcolor` varchar(20) default NULL,   `fontsize` varchar(10) default NULL,   `font` varchar(50) default NULL,   `fontcolor` varchar(20) default NULL,   `orientation` varchar(100) default NULL,   `tbgcolor` varchar(20) default NULL,   `tfontsize` varchar(10) default NULL,   `tfontcolor` varchar(20) default NULL,   `tfont` varchar(50) default NULL,   `votes` int(11) default '0')");   if ($result) { echo "Table Created!"; } else print "Error"; [/quote] No matter what I do, I keep getting "Error".  And I know the table hasn't already been created because when I plug it into this code: [quote] $result = mysql_query("DESCRIBE poll");   while ($row = mysql_fetch_array($result, MYSQL_NUM)) {     printf("%s %s", $row[0], $row[1]);   echo"<br>";   }     mysql_free_result($result); [/quote] I get a blank page, even though when I test it on a table that I know already exsists, it gives me the feedback I'm looking for (the names of all the columns in the specified table). Can someone please help? (And unfortunatly, no, I don't have access to my server itself, so I do need to create the tables in PHP)
  10. [code]function get_ip () { $ip = ! empty ( $_SERVER['CLIENT_IP'] ) ? $_SERVER['CLIENT_IP'] : ''; $ip = ! empty ( $_SERVER['HTTP_CLIENT_IP'] ) ? $_SERVER['HTTP_CLIENT_IP'] : $ip; if ( ! empty ( $_SERVER['HTTP_X_FORWARDED_FOR'] ) && preg_match_all ( '#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $_SERVER['HTTP_X_FORWARDED_FOR'], $f ) ) { foreach ( $f[0] AS $id ) { if ( ! preg_match ( "#^(10|172\.16|192\.168)\.#", $id ) ) { $ip = $id; break; } } } $ip = ! empty ( $_SERVER['REMOTE_ADDR'] ) && empty ( $ip ) ? $_SERVER['REMOTE_ADDR'] : $ip; return $ip; } function ip_check() { $myip = get_ip(); $addr = mysql_db_query("blah","SELECT ip FROM bans;"); while ($ip = mysql_fetch_assoc($addr)) { $banned_ip = $ip['ip']; if(strstr($myip,$banned_ip)) {   print ("Error message");   exit;   } } }[/code] That's not working..
  11. So I can still have admins enter IPs on the webpage itself? I actually don't have access to the database, my webhost only gives me access to the code itself, so I just get to work with what I have.  All I know is the table is bans and the field is ip... would you need more information than that? :/ (But if you can't do it from what I have, the current way I have it works, so I'm okay either way :P) ======== That code you just added... so whole thing would take the place of $myip = $_SERVER['REMOTE_ADDR'];? Sorry, I'm confused now :(
  12. Ohoh!  Figured it out.  Thanks SO much! Topic closed.
  13. function ip_check() { $myip = $_SERVER['REMOTE_ADDR']; $addr = mysql_query("SELECT ip FROM bans"); while ($ip = mysql_fetch_assoc($addr)) { $banned_ip = $ip['ip']; if(strstr($myip,$banned_ip)) {   print ("Error Message");   exit;   } } } Like that? Yes, I tried.  And no, not working yet. :/
  14. I also posted on the page print $_SERVER['REMOTE_ADDR']; so she can let me know if any changes happen when she refreshes.  So far no change in IP..
  15. Still not working. :( Banned IPs are still gaining access to the site (I'm testing it out with a friend and her IP.. she's getting the non-error version).
  16. I'm trying to create a simple IP ban script, just a little function that I can place in my webpages.  I dont want to modify my .htaccess pages or just put the IPs directly in the code, because I want some admins on my site who don't have access to the code to be able to add IPs as they see fit if/when I am unavailable.  I created a mysql table called bans, which has the field ip.  I have something set up so it will add IPs into the table, and its working.  However, when I try to check it against the IPs for the current user, its not working.  I've tried a BUNCH of different things, so I'm REALLY looking for some help.  Thanks so much. The function, at present: $addr = mysql_db_query("blah","SELECT ip FROM bans;",$database); $ip = $_SERVER['REMOTE_ADDR']; while ($ip = mysql_fetch_assoc($addr)) { print ("Error Message"); exit; }
  17. Here is pretty much the entire coding of the form (the rest being stuff involving the layout and whatnot): [code] <?php if($edit_pet)          {             $sexid = ($sexid != "Male" && $sexid != "Female") ? "Male" : $sexid;             $logdata = "Pet $edit_pet edited by ";             $logdata .= $_SESSION["username"];             $logdata .= " status ";             $logdata .= get_text("status",$status);             log_event($logdata, "petedit");         $owner1 = $owner;         if(!$adopter)         { $owner = $owner1; print("DEBUG IF"); }         else         { $owner = $adopter; unset($adopter); print("DEBUG ELSE"); }             $result=mysql_db_query("neopets","UPDATE pet SET petname='$petname',ownername='$owner',pic_url='$pic_url',adoptdate='$cur_date',link_url='$owner_url',color='$color',species='$species',status='$status',comment='$comment' WHERE id = $edit_pet;",$database);         if($result)             {                  print("\n<p><center><b><i>Pet $edit_pet modified.</i></b></center></p>\n");             }             else             {                print("\n<p><center><b><i>Modify FAILED for pet $edit_pet</i></b></center></p>\n");             }            }          else if($holdid)          {             $result=mysql_db_query("neopets","UPDATE pet SET status='4' WHERE (id = '$delid');",$database);             $logdata = "Pet ".$holdid." on admin hold";             log_event($logdata, "pethold");             if($result)             {                print("\n<p><center><b><i>Pet $holdid on administrative hold!</i></b></center></p>\n");             }             else             {                print("\n<p><center><b><i>Hold FAILED for pet $holdid</i></b></center></p>\n");             }          }          else if($delid)          {             $result=mysql_db_query("neopets","DELETE FROM pet WHERE (id = '$delid');",$database);             $logdata = "Pet ".$holdid." deleted by ".$_SESSION["username"];             log_event($logdata, "petdelete");             if($result)             {                print("\n<p><center><b><i>Pet $delid deleted!</i></b></center></p>\n");             }             else             {                print("\n<p><center><b><i>Delete FAILED for pet $delid</i></b></center></p>\n");             }          }          else if($id)          {             $result=mysql_db_query("neopets","SELECT petname, ownername, adoptername, pic_url, link_url, color, species, sex, status, comment FROM pet WHERE (id= '$id');",$database);             if(!$result)                print("\n<center>No pet selected for edit.</center>\n");             else             {                if($pet_row=mysql_fetch_row($result))                {                   $petname=$pet_row[0];                     $owner=$pet_row[1];                   $adopter=$pet_row[2];                   $pic_url=$pet_row[3];                     $owner_url=$pet_row[4];                     $colorid=$pet_row[5];                   $speciesid=$pet_row[6];                   $sexid=$pet_row[7];                   $status=$pet_row[8];                   $comment=$pet_row[9];                }             }          }       }       else print("\n<center><b>Invalid admin status.</b></center>");    }    else print("\n<center><b>Invalid session.</b></center>"); ?> <table> <tr><td><center><b><u>Edit pet</u></b></center><br></td></tr> <tr><td> <form method="POST" action="pet_edit.php"> <table><tbody> <tr><td>    <input type="hidden" name="edit_pet" value="<?php print $id; ?>">    Pet Name:</td><td>    <textarea cols="30" rows="1" wrap="soft" name="petname"><?php print $petname; ?></textarea></td></tr>    <tr><td>Owner:</td>    <td><?php print $owner; ?></td></tr>    <tr><td>Adopter Username:</td>    <td><textarea cols="30" rows="1" wrap="soft" name="adopter"></textarea></td></tr>    <tr><td>Picture URL:</td>    <td><textarea cols="30" rows="1" wrap="soft" name="pic_url"><?php print $pic_url; ?></textarea></td></tr>    <tr><td>Rules URL:</td>    <td><textarea cols="30" rows="1" wrap="soft" name="owner_url"><?php print $owner_url; ?></textarea></td></tr>    <tr><td>Color: </td><td><?php my_build_adv_listbox("neopets", "color", "id", "description","$colorid"); ?></td></tr>    <tr><td>Species:</td><td><?php my_build_adv_listbox("neopets", "species", "id", "description","$speciesid"); ?></td></tr>    <tr><td>Sex:</td><td><?php my_build_adv_listbox("neopets", "sex", "id", "description","$sexid"); ?></td></tr>    <tr><td>Status:</td><td>       <?php          if(array_key_exists("adminflags",$_SESSION)) {             if($_SESSION["adminflags"] > 10) {my_build_adv_listbox("neopets", "status", "id", "description","$status"); }             else {my_build_adv_listbox("neopets", "userstatus", "id", "description","$status"); }          }       ?>    </td></tr>    <tr><td>Comment:</td><td>    <textarea cols="30" rows="10" wrap="soft" name="comment"><?php print $comment; ?></textarea>    <tr><td colspan=2><center><br><br><input type="submit" name="Submit" value="Modify Pet"></center></td></tr></tbody></table> </form> </td></tr></tbody></table> [/code] And this is the code that defines the functions used on that page [code] <?php         function my_build_adv_listbox($database, $tablename, $valfieldname, $displayfieldname, $defaultval)         {                 $fulltable = mysql_db_query($database,"SELECT $valfieldname, $displayfieldname FROM $tablename ORDER BY $displayfieldname ASC;");                 $tablesize = mysql_num_rows($fulltable);                 if($tablesize) //if no entries in table, do not make list.                 {                         print ("\n<select name=\"$tablename\">");                         for ($loopcnt=0; $loopcnt < $tablesize; $loopcnt++)                         {                                 $cur_row=mysql_fetch_row($fulltable);                                 print ("\n<option value=\"$cur_row[0]\"");                                 if($cur_row[0]==$defaultval) print(" SELECTED");                                 print(">$cur_row[1]</option>");                         }                         print ("\n</select>\n");                 }                 else { print ("\n<b><i>Empty list omitted.</i></b>\n"); }         };         function build_listbox($database, $tablename, $valfieldname, $displayfieldname, $defaultval)         {                 $fulltable = mysql_db_query($database,"SELECT $valfieldname, $displayfieldname FROM $tablename ORDER BY $displayfieldname ASC;");                 $tablesize = mysql_num_rows($fulltable);                 if($tablesize) //if no entries in table, do not make list.                 {                         $retval = "\n<select name=\"$tablename\">";                         for ($loopcnt=0; $loopcnt < $tablesize; $loopcnt++)                         {                                 $cur_row=mysql_fetch_row($fulltable);                                 $retval .= "\n<option value=\"$cur_row[0]\"";                                 if($cur_row[0]==$defaultval) $retval .= " SELECTED";                                 $retval .= ">$cur_row[1]</option>";                         }                         $retval .= "\n</select>\n";                 }                 else { $retval = "\n<b><i>Empty list omitted.</i></b>\n"; }                 return $retval;         };         function yesno_to_bool($inval)         {                 if(stristr($inval,"y"))                    return "t";                 elseif(stristr($inval,"n"))                    return "f";                 else return "NULL";         };         function checkbox_to_bool($inval)         {                 if(stristr($inval,"on"))                    return "t";                 else                    return "f";         };         function get_text($tablename, $inref)         {            $row_data=mysql_fetch_row(mysql_db_query("neopets","SELECT description FROM $tablename WHERE id='$inref';"));            return $row_data[0];         }         ?> [/code] If you need anything else let me know.. and thanks in advanced for your help!
  18. I've got this form, in which there is an intial 'owner' name for a pet (part of a virtual pet adoptions fansite), and people can input the adopter name into the form. If an adopter name is entered, I want the owner name to switch and become the adopter name.. but if none is entered, I want the owner name to stay the same when the form is update. However, the way it's coded curently, even though my DEBUG statements seem to be working, the owner name is /always/ becoming the adopter name. Any ideas why this is and how to fix this? [code]         $owner1 = $owner;         if(!$adopter)         { $owner = $owner1; print("DEBUG IF"); }         else         { $owner = $adopter; unset($adopter); print("DEBUG ELSE"); }             $result=mysql_db_query("neopets","UPDATE pet SET ownername='$owner' WHERE id = $edit_pet;",$database); [/code] And the code for the two input areas of the form is: [code]    <tr><td>Owner:</td>    <td><?php print $owner; ?></td></tr>    <tr><td>Adopter Username:</td>    <td><textarea cols="30" rows="1" wrap="soft" name="adopter"></textarea></td></tr> [/code]
  19. Well, I'm not /entirely/ sure I know what you mean.. but if you set the inside table to a certain width, it cannot get any bigger than that, and the other sections of the table won't be affected. Or am I not understanding your question correctly?
  20. Ack, ok nevermind. I thought I had it, but for some reason I'm having another problem. I changed the code so that the checkbox code is [code]$maindiv.= "<input type='checkbox' name='ids[]' value='".$row['id']."'>";[/code] And to delete multple comments is: [code]else if($row_del) {     $query = "DELETE FROM polls WHERE";     $j=0;     foreach($_POST['ids'] as $key=>$id)       {           if($j>0)           {             $query .= " OR";           }       $query .= " id='".$id."'";       $j++;                }     }[/code] But now its not letting me edit comments. I think it has something to do with the remaining: [code]     if(isset($_POST['sub_del']) || isset($_POST['sub_edit'])) {         foreach($_POST as $key => $value) {             if ( strpos($key, "id_") !== false ) {                 $row_id = str_replace("id_","",$key);                 if ($row_id > 0) break;             }         }     } [/code] since the checkbox is no longer called id_.. but no matter what combination of ids[] I try to change the id_ to, its still not allowing me to edit my comments. Any idea what I should fix the id_ to?
×
×
  • 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.