Jump to content

pocobueno1388

Members
  • Posts

    3,369
  • Joined

  • Last visited

    Never

Everything posted by pocobueno1388

  1. Hmm, that doesn't make any sense, it should for sure be printing out the $sql variable. I wonder if your form is even making it to that page. Try this and see if you see anything: <?php include('adminconnect.php'); // table name $tbl_name="adminusers"; // values sent from form $name=$_POST['name']; $address=$_POST['address']; $address1=$_POST['address1']; $address2=$_POST['address2']; $address3=$_POST['address3']; $address4=$_POST['address4']; $county=$_POST['county']; $zip=$_POST['zip']; $telephone=$_POST['telephone']; $email=$_POST['email']; $username=$_POST['username']; $password=$_POST['password']; echo "I hope you see this..."; $sql="INSERT INTO $tbl_name(name, address, address1, address2, address3, address4, county, zip, telephone, email, username, password)VALUES('$name', '$address', '$address1', '$address2','$address3', '$address4','$county' ,'$zip', '$telephone', '$email', '$username', '$password')"; $result=mysql_query($sql)or die(mysql_error()."<p>With Query<br>$sql"); echo "<p>$sql<p>"; ?>
  2. <?php $query = mysql_query("SELECT script_name FROM my_scripts ORDER BY RAND() LIMIT 1")or die(mysql_error()); $row = mysql_fetch_assoc($query); include "{$row['script_name']}"; ?>
  3. Try this: <?php $query = mysql_query("SELECT script_name FROM my_scripts")or die(mysql_error()); $row = mysql_fetch_assoc($query); //this will add the content (hopefully) include "{$row['script_name']}"; ?>
  4. You didn't delete all the stuff above it, did you? signup.php should look like this: <?php include('adminconnect.php'); // table name $tbl_name="adminusers"; // values sent from form $name=$_POST['name']; $address=$_POST['address']; $address1=$_POST['address1']; $address2=$_POST['address2']; $address3=$_POST['address3']; $address4=$_POST['address4']; $county=$_POST['county']; $zip=$_POST['zip']; $telephone=$_POST['telephone']; $email=$_POST['email']; $username=$_POST['username']; $password=$_POST['password']; $sql="INSERT INTO $tbl_name(name, address, address1, address2, address3, address4, county, zip, telephone, email, username, password)VALUES('$name', '$address', '$address1', '$address2','$address3', '$address4','$county' ,'$zip', '$telephone', '$email', '$username', '$password')"; $result=mysql_query($sql)or die(mysql_error()."<p>With Query<br>$sql"); echo "<p>$sql<p>"; ?>
  5. Try this, and post whatever you see on the screen. <?php $sql="INSERT INTO $tbl_name(name, address, address1, address2, address3, address4, county, zip, telephone, email, username, password)VALUES('$name', '$address', '$address1', '$address2','$address3', '$address4','$county' ,'$zip', '$telephone', '$email', '$username', '$password')"; $result=mysql_query($sql)or die(mysql_error()."<p>With Query<br>$sql"); echo "<p>$sql<p>";
  6. Put die()'s at the end of ALL your queries. or die(mysql_error());
  7. Do you get any errors? Try changing this line $tbl_name=Adminusers; To $tbl_name="adminusers";
  8. mysql_num_rows() returns the number of rows your query found in the database. So look at this line: if (mysql_num_rows($check) < 1) { Thats saying that if the query $check returns less than one row, then they got the wrong login information, because it obviously doesn't exist in the database. And of course, if it returns "1" that means they got the correct login information. Hopefully I explained that clear enough. Remember, if you ever want to know what a function does, just look in the manual. In this case, you would just type in the URL: www.php.net/mysql_num_rows - that will give you all the information you need to know about it.
  9. Try replacing all the <.br> tags with \n's, like this: <?php $message="Your password reset link \n\n"; $message.="Click on the following link to reset your password \n"; $message.="http://mberanek.dyndns.org:8204/resetpass.php?u=$username&passkey=$uniqueid"; $message.="\n\nPlease do not reply to this email.";
  10. I see other problems with your script as well. You don't need a while loop when your only expecting one row, so that needs to be taken out. Also, there is an easier way of checking whether the username/password combination was found in the database by modifying the query a little and just checking how many rows it returned. Here is some modified code, see if it works for you. <?php //Checks if there is a login cookie if (!isset($_COOKIE['ID_my_site'])){ $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username' AND password='$pass'")or die(mysql_error()); if (mysql_num_rows($check) < 1) { ?> <form action="login.php" method="post" STYLE="margin: 0px; padding: 0px;"> <input name="username" type="text" id="username" value="Username" onFocus="if (this.value==this.defaultValue) this.value='';" /> <input name="password" type="password" id="password" value="Password" onFocus="if (this.value==this.defaultValue) this.value='';"/><br> <a href="members.php" title="Members Area" target="content">Members Area</a> | <a href="registration.php" title="Register" target="content">Register</a> <input type="submit" id="login" name="login" value="Login" /> </form> <?php } } else { echo "Welcome"; } ?> You may have to redefine your $username and $pass variable, because if they aren't logged in then those cookies probably aren't set. I would assume you would get those values from the form they use to log in.
  11. I'm a little confused by the logic of your script. Your script is saying IF the cookie "ID_my_site" exists check if their login/password are correct. But if that cookie exists, doesn't that mean they are already logged in? So doesn't that mean the IF statement should be: if(!isset($_COOKIE['ID_my_site'])) I may just have it wrong, if I do can you explain where you register those cookies? I promise I have a point to all this =]
  12. Try <?php if (isset($_GET['search'])){ if (strlen($_GET['search']) < 3){ echo "Search is less than 3 chars"; } } if ($ _GET['search'] == "") { ?> <form action="phpsearch.php" method="get"> <input type="text" name="search"><br> <input type="submit" value="Search"> </form> <?php } ?>
  13. It means one of your queries is failing, add die errors to the end of them, like this: $result = mysql_query($sql)or die(mysql_error()); Do that to both of them and see if you get an error.
  14. Just add another curly brace after the last one.
  15. Well, I must be way too much of an amateur still when it comes to OOP, because I'm not understanding at all. I'm not going to make you sit here and explain everything to me, it's obvious that I have much more research to do on the topic. Thank you so much for your feedback, I will refer back to it after I learn a bit more.
  16. I'm not exactly sure what to take from that =/ Are you saying that my class does too much asking for information instead of doing stuff with it? I may be way off on that one I don't know if I'm going to understand what your saying unless you actually show me with my code.
  17. ignace - Wow, I am completely confused by that code. I can't even comprehend anything in the links provided, hah. keeB - Okay, I understand how the get/set functions are wrong. I never had to use them in my code, so I will just get rid of that altogether. So the way I'm doing it is correct then (initiating a new instance of the class for each part of my script)? If I think about it, I guess it really doesn't matter that I'm creating a new instance as there would always be one being created regardless. So do you guys see anything wrong with not setting many variables in the class? I mean, I just pass those ones through the parameters of the functions, and so far it hasn't caused me any problems. Then again, should functions have parameters if they are inside a class? Because if I did have those variables defined in the class, it would seem a little pointless to have parameters. I'm just confused on which way is correct....
  18. I'm practicing using OOP and would like some feedback on a class I programmed, as well as the use of the class. The class is for a private messaging system. The Class <?php class inbox { var $user; //The users ID function __construct($user){ $this->user = $user; } function set($var, $value){ $this->$var = $value; } ################################################################################# # FUNCTION retrieve # DESCRIPTION # Retrieve all messages from a users inbox from designated folder # PARAMETERS # VARCHAR $folder - From which folder to get messages from? [1=inbox, 2=saved] ################################################################################# function retrieve($folder=1){ $folder = (int)$folder; $query = "SELECT i.messageID, i.subject, i.status, DATE_FORMAT(i.date, '%b %D %l:%i %p') as date, u.username, u.userID FROM inbox i LEFT JOIN users u ON u.userID = i.sender WHERE reciever='$this->user' AND folder=$folder"; if ($result = mysql_query($query)) return $result; else return FALSE; } ################################################################################# # FUNCTION get_status # DESCRIPTION # Returns word depending on status number (unread, read, replies) # PARAMETERS # INT $status - The ID of the message ################################################################################# function get_status($status){ switch($status){ case 1: return "Unread"; break; case 2: return "Read"; break; case 3: return "Replied"; break; } } ################################################################################# # FUNCTION read_message # DESCRIPTION # Gets message information for specific message # PARAMETERS # INT $messageID - The ID of the message ################################################################################# function read_message($messageID){ //check if this message belongs to the user trying to view it if ($this->check_user($this->user, $messageID)){ $query = "SELECT i.subject, i.body, DATE_FORMAT(i.date, '%b %D %l:%i %p') as date, u.username, u.userID FROM inbox i LEFT JOIN users u ON u.userID = i.sender WHERE messageID = $messageID"; if ($result = mysql_query($query)){ $this->update_status($messageID, 2); return $result; } else { return FALSE; } } else { return FALSE; } } ################################################################################# # FUNCTION send_message # DESCRIPTION # Send a message to another users inbox # PARAMETERS # INT $to - Users ID to send message to # VARCHAR $subject - Subject of message # TEXT $body - Body of message ################################################################################# function send_message($to, $subject, $body){ require_once 'purifier/HTMLPurifier.standalone.php'; $purifier = new HTMLPurifier(); $to = $purifier->purify(mysql_real_escape_string($to)); $subject = $purifier->purify(mysql_real_escape_string($subject)); $body = $purifier->purify(mysql_real_escape_string($body)); $query = "INSERT INTO inbox (sender, reciever, subject, body, date) VALUES ('$this->user', '$to', '$subject', '$body', NOW())"; if (mysql_query($query)) return TRUE; else return FALSE; } ################################################################################# # FUNCTION delete # DESCRIPTION # Delete all selected messages from folder # PARAMETERS # ARRAY $messages - Array of message IDs to delete ################################################################################# function delete($messages){ $query = "DELETE FROM inbox WHERE messageID IN(" .implode(', ', $messages) . ")"; if (mysql_query($query)) return TRUE; else return FALSE; } ################################################################################# # FUNCTION check_user # DESCRIPTION # Checks if the user is the owner of the message, if not don't let them read # it. # PARAMETERS # INT $user - The user's ID logged in # INT $messageID - The ID of the message they are reading ################################################################################# function check_user($user, $messageID){ $query = "SELECT COUNT(*) FROM inbox WHERE messageID='$messageID' AND reciever='$user'"; if ($num_rows = mysql_result(mysql_query($query), 0)) return $num_rows; else return FALSE; } ################################################################################# # FUNCTION update_status # DESCRIPTION # Updates the status of a message (read, unread, replies) # PARAMETERS # INT $messageID - The ID of the message they are reading ################################################################################# function update_status($messageID, $status){ $query = mysql_query("SELECT status FROM inbox WHERE messageID=$messageID"); $row = mysql_fetch_assoc($query); if ($row['status'] != $status){ if (mysql_query("UPDATE inbox SET status=$status WHERE messageID=$messageID")) return TRUE; else return FALSE; } } ################################################################################# # FUNCTION save # DESCRIPTION # Saves a message to users "saved" folder # PARAMETERS # INT $messageID - The ID of the message they want to save ################################################################################# function save($messageID){ $messageID = (int)$messageID; $query = "UPDATE inbox SET folder=2 WHERE messageID=$messageID"; if (mysql_query($query)) return TRUE; else return FALSE; } } ?> Using the class <?php include 'header.php'; include 'lib/inbox.class.php'; //=============== READ MESSAGE ===================================// if (isset($_GET['messageID'])){ echo '<table width="50%" align="center"><td><a href="inbox.php"><<< Back to Inbox</a></td></table>'; $messageID = (int)$_GET['messageID']; $inbox = new inbox($sid); if ($result = $inbox->read_message($messageID)){ $row = mysql_fetch_assoc($result); print<<<HERE <form action="{$_SERVER['PHP_SELF']}?userID={$row['userID']}" method="post"> <table id="mytable" cellspacing=0> <tr> <th colspan=2><b>{$row['subject']}</b></th> </tr> <tr> <td class="color"><a href="profile.php?userID={$row['userID']}">{$row['username']}</a></td> <td class="color" align="center">{$row['date']}</td> </tr> <tr> HERE; echo '<td class="read-message" colspan=2>' . nl2br($row['body']) . '</td>'; print<<<HERE </tr> <tr> <td class="color" align="center" colspan=2> <input class="send-btn" type="submit" name="reply" value="Reply"> <input class="send-btn" type="submit" name="save" value="Save"> </td> </tr> </table> <input type="hidden" name="send_to" value="{$row['userID']}"> <input type="hidden" name="subject" value="{$row['subject']}"> <input type="hidden" name="messageID" value=$messageID> <input type="hidden" name="body" value="\n\n\n--------------Player #{$row['userID']} said-------------------\n{$row['body']}"> <form> HERE; } else { $error[] = "This isn't your message!"; error($error); } //================ COMPOSE ============================================// } else if ($_GET['action'] == 'compose' || isset($_POST['reply']) || isset($_POST['save'])){ //If they save a message if (isset($_POST['save'])){ $inbox = new inbox($sid); if ($inbox->save($_POST['messageID'])){ msg("Message Saved"); } else { $error[] = "There was an error saving your message"; } } //if they press "send" if (isset($_POST['compose'])){ if ((empty($_POST['send_to'])) || (empty($_POST['subject'])) || (empty($_POST['body']))) $error[] = "Please fill out all fields!"; if (!is_numeric($_POST['send_to'])) $error[] = "Please enter a numeric player ID"; if(!empty($error)){ error($error); } else { $inbox = new inbox($sid); if (isset($_POST['update'])) $inbox->update_status($_POST['update'], 3); if ($inbox->send_message($_POST['send_to'], $_POST['subject'], $_POST['body'])){ msg("Message Sent"); } else { $error[] = "There was an issue sending the message, please contact an administrator."; } } } //figure out who the message is to for the user if (isset($_GET['userID'])) $send_to = (int)$_GET['userID']; else if (isset($_POST['send_to'])) $send_to = (int)$_POST['send_to']; else $send_to = ""; print<<<HERE <table width="50%" align="center"><td><a href="inbox.php"><<< Back to Inbox</a></td></table> <form action="{$_SERVER['PHP_SELF']}?action=compose" method="post"> <table id="mytable" cellspacing="0"> <tr> <th colspan=2>Compose</th> </tr> <tr> <td class="color"><b>Player #</b></td> <td><input type="text" name="send_to" maxlength=11 size=11 value="$send_to"></td></td> </tr> <tr> <td class="color"><b>Subject</b></td> <td><input type="text" name="subject" maxlength=25 size=25 value="{$_POST['subject']}"></td></td> </tr> <tr> <td class="color"><b>Body</b></td> <td><textarea rows=10 cols=50 name="body">{$_POST['body']}</textarea></td> </tr> <tr> <td class="color" align="center" colspan=2><input type="submit" name="compose" class="send-btn" value="Send"></td> </table> HERE; if (isset($_POST['reply'])) echo "<input type='hidden' name='update' value='{$_POST['messageID']}'>"; echo '</form>'; //================ INBOX ==============================================// } else { $inbox = new inbox($sid); //=== Delete selected messages ===// if (isset($_POST['delete']) && !empty($_POST['del'])){ if ($inbox->delete($_POST['del'])){ msg("Messages Deleted"); } else { $error[] = "Message(s) could not be deleted, please contact an administrator."; error($error); } } else if (isset($_POST['delete']) && empty($_POST['del'])) { $error[] = "You didn't select any messages to delete!"; error($error); } ?> <h2>Inbox Demo</h2> <a href="inbox.php?action=compose">Compose</a> || <?php if (isset($_GET['folder']) && $_GET['folder'] == 2) echo '<a href="inbox.php">Inbox</a>'; else echo '<a href="inbox.php?folder=2">Saved</a>'; ?> <p> <form method="post"> <script type="text/javascript" src="http://www.shawnolson.net/scripts/public_smo_scripts.js"></script> <table id="mytable" cellspacing="0"> <tr> <th><input type="checkbox" name="checkall" onclick="checkUncheckAll(this);"/></th> <th>Subject</th> <th>Sender</th> <th>Time</th> <th>Status</th> </tr> <?php $folder = (isset($_GET['folder'])) ? (int)$_GET['folder'] : 1; $result = $inbox->retrieve($folder); if (mysql_num_rows($result) > 0){ while ($row = mysql_fetch_assoc($result)){ echo '<tr>' ."<td class='color'><input type='checkbox' name='del[]' value='{$row['messageID']}'></td>" ."<td><a href='{$_SERVER['PHP_SELF']}?messageID={$row['messageID']}'>{$row['subject']}</a></td>" ."<td class='color'><a href='profile.php?user={$row['userID']}'>{$row['username']}</a></td>" ."<td>{$row['date']}</td>" ."<td class='color'>" . $inbox->get_status($row['status']) . "</td>" .'</tr>'; } } else { echo '<td colspan=5 align="center">No Messages</td>'; } echo '</table>'; print<<<HERE <table align="center" width="48%"> <td><input type="submit" name="delete" value="Delete"></td> </table> </form> HERE; } ?> Concerns Initiating class multiple times through script I am initiating a new class for each separate part of my script. Should I be only initiating the class at the top of the script and just change the information inside the class with my set() function (inside class) as I go along with the script, or am I doing it the best way? Not setting enough variables in class As you can see in my class I only set the variable $user for the class. Should I be setting much more variables, such as for the messageID, body, subject, send to, etc? I just put those as the parameters of the functions, and that takes care of it. Those are the only concerns that immediately jumped out at me. So if anyone has any suggestions or comments at all, I would really appreciate hearing them. Thanks
  19. We need more information. Are these articles stored in a database? If so, then all you need to do is perform a query that counts them.
  20. Try <?php $query_trout = "SELECT species_id, team_id, MAX(length) FROM submit WHERE species_id=2 GROUP BY team_id"; $result5 = mysql_query($query_trout) or die(mysql_error()); if (mysql_num_rows($result5) > 0){ while($row = mysql_fetch_array($result5)) { $team_id = $row['team_id']; $species_id = $row['species_id']; $trout = $row['MAX(length)']; //get team's name from team table get_team_name($team_id); get_species($species_id); } $trout_bonus .=<<<EOD <tr> <td align='center'>$speciesname</td> <td align='center'>$teamname</td> <td align='center'>$trout"</td> </tr> EOD; } else { echo "No fish caught yet."; }
  21. would this work? shouldnt it be: echo '<pre>'.print_r($narray).'</pre>'; ? Yes, you can do concatenation with commas or periods. I only use the comma when I'm using print_r() as I did above. For some reason a period won't work with that, I'm honestly not exactly sure why. Must be something to do with using a function in an echo statement or something.
  22. <?php $num = 54321; $narray = str_split($num); echo '<pre>',print_r($narray),'</pre>'; ?>
  23. Where are you pulling this variable from? $ch['r'.$num.''] You are defining variables outside of the function, then trying to use them inside the function. Instead you should pass those variables through the functions parameters, otherwise the function is only going to be good for about one use, and that defeats the entire purpose of a function.
  24. The site really isn't visually appealing at all. So appearance wise, I would start from scratch. I would suggest paying someone to do a nice job on a professional layout, it will most likely be worth the money in the long run.
  25. Look in the manual at the number_format() function.
×
×
  • 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.