Jump to content

Handy PHP

Members
  • Posts

    30
  • Joined

  • Last visited

    Never

About Handy PHP

  • Birthday 01/27/1974

Contact Methods

  • Website URL
    http://www.handyphp.com

Profile Information

  • Gender
    Male
  • Location
    Indianapolis, Indiana, USA (Midwest)

Handy PHP's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Well, this isn't the prettiest code I've ever seen but it functions more or less. And we all learned somewhere and it usually was deep in messy code so there isn't any reason to be so hard on the guy. He's just looking for help! I made the code a little easier for ME to read and may have found the issue but this isn't my strongest subject. Basically, I have a very hard time reading this style of coding (not just yours). I believe the you have the "view" case before the "compose" case and here is why I think that... Your "view" case doesn't have a break statement at the end which will allow your code to read the next case even if it doesn't match the variable. So when you view the message, it re-submits the message. Here is your code indented to make it easier to read: <? case 'compose': if(!$_POST[send]){?> <div id="main_heading_text" class="left">My Inbox: Compose Message</div> <div id="main_list_buttons" class="right"></div> <div class="my_account_info" id="contentdiv" > <form method="post" action=""> <table width="680" border="0" cellspacing="0" cellpadding="0" style='border: 1px solid #E1F4A6; '> <tr> <td width="212" height="35" bgcolor="#E7F7A5"><br /> <span class="edit_profile_label" style="padding-left:8px;">User Name:</span> <? if(isset($_GET[user])){ //check if there is a user in the address bar echo "<input type='text' name='to' value='$_GET[user]' size='15'>"; //if there is }else{ //or not.. echo "<input type=\"text\" name=\"to\" size=\"15\">"; //echo the input box without the value of the user! } //end user check in address bar</b>?></td> <td width="466" height="50" bgcolor="#E7F7A5" ><br /><b class="edit_profile_label" > Subject:</b><input type="text" name="title" value="My Offer" size="15"></td> </tr> <tr> <td height="125" colspan="2" valign="top" style="padding-left:8px;"><p> </p> <p> </p> <p><b class="edit_profile_label" style="font-size:14px;">Message:</b><br /><br /> <textarea name="message" rows="6" cols="75"></textarea> <br /><br /><br /><br /> </p> </td> </tr> <tr> <td height="35" style="padding-left:8px;"><input type="submit" name="send" value="Send message" id="update_listing_btn" ><br /><br /></td> <td><a href="my_account.php?page=pm" style="font-size:12px; color:#00AEBF;">Back to inbox</a></td> </tr> <tr> <td height="35" bgcolor="#E7F7A5"> </td> <td bgcolor="#E7F7A5"> </td> </tr> </table> </form> <? }else{ //or if it was.... $to = stripslashes(htmlspecialchars(strip_tags($_POST[to]))); //who its to $from =$_SESSION[uSERNAME]; //who its from $date = date("F j, Y, g:i a"); //the date sent $msg = addslashes($_POST[message]); //the message variable $subject = addslashes($_POST[title]); //the subject $do = mysql_query("INSERT INTO `private_msg` (`to`,`from`,`date`,`subject`,`content`) VALUES ('" . $to . "','" . $from . "','" . $date . "','" . $subject . "','" . $msg . "')") or die(mysql_error()); //insert into the table! echo "<div id='main_heading_text' class='left'>My Inbox: Compose Message</div> <div id='main_list_buttons' class='right'></div> <div class='my_account_info' id='contentdiv' > <table width='680' border='0' cellspacing='0' cellpadding='0' style='border: 1px solid #E1F4A6; '> <tr> <td height='35' bgcolor='#E7F7A5'></td></tr> <tr><td><br /><br /><center>Message Sent! <a href=\"my_account.php?page=pm\" style=\"font-size:12px; color:#00AEBF; \">Go back to inbox</a></center><br /><br /></td></tr> <tr> <td height='35' bgcolor='#E7F7A5'></td></tr> </table>";?> <?}?> <? break; ?> <? case 'view': $id = (int)htmlspecialchars(strip_tags($_GET[id])); $msgs = mysql_query("SELECT * FROM `private_msg` WHERE `to` = '" . $_SESSION[uSERNAME] . "' ORDER BY `pid` ASC") or die(mysql_error()); //get all the messages to the loged in user $id = (int)htmlspecialchars(strip_tags($_GET[id])); //make the ID safe if(!$id){ $user_message = "<table width=\"680\" border=\"0\" align=\"left\" cellpadding=\"5\" cellspacing=\"0\" class='private_msg_tbl' ><tr class=\"edit_profile_label\"> <td width=\"680\" height=\"35\" bgcolor=\"#E7F7A5\"> </td> <td width=\"680\" ><a href=\"pm.php\">Go back to inbox</a> <br /><br />No ID Selected!</td> <td width=\"680\" height=\"35\" bgcolor=\"#E7F7A5\"> </td></tr> </table>"; ?> <? }else{ $select = mysql_query("SELECT * FROM `private_msg` WHERE `pid` = '" . $id . "';"); //get the message's info $msg = mysql_fetch_array($select); //select all data if($msg[to] != $_SESSION[uSERNAME]){ //check if the user logged $user_message= "<table width=\"680\" border=\"0\" align=\"left\" cellpadding=\"5\" cellspacing=\"0\" class='private_msg_tbl'><tr class=\"edit_profile_label\"> <td width=\"680\" height=\"35\" bgcolor=\"#E7F7A5\"> </td> <td width=\"680\" ><a href=\"pm.php\">Go back to inbox</a><br /><br />This Message Was Not Sent To You</td> <td width=\"680\" height=\"35\" bgcolor=\"#E7F7A5\"> </td></tr> </table>"; }else{ //maybe... if(!$_POST[reply]) { //if the reply was not submitted $mark = mysql_query("UPDATE `private_msg` SET `status` = 'Read' WHERE `pid` = '" . $id . "'") or die(mysql_error()); //mark it as Read $message = nl2br(stripslashes($msg[content])); //make new lines to and strip the slashes $subject = stripslashes($msg[subject]); //strip the slashes $user_message="<table width=\"680\" align=\"left\" cellpadding=\"5\" cellspacing=\"0\" style='border: 1px solid #E1F4A6; ' ><form method=\"post\"> <tr > <td width='153' height='35' bgcolor='#E7F7A5' style='padding-left:7px;'><b class='edit_profile_label'>Subject:</b> $subject</td> <td width='507' bgcolor='#E7F7A5' style='padding-left:7px;' ><b class='edit_profile_label'>From:</b> $msg[from]</td> </tr> <div id='div_spacer'> <tr > <td height='100' colspan='2' style='padding-left:12px;'>$message</td> </tr> <tr> <td height='80' colspan='2' style='padding-left:8px;'><textarea rows=\"6\" cols=\"45\" name=\"msg\" ></textarea></td> </tr> <tr> <td height='35' style='padding-left:8px;'><input type=\"submit\" name=\"reply\" value=\"Reply\" style=' border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; width: 75px; font-weight: normal; color: #FFF; text-decoration: none; background-color: #00AEBF; height: 23px; float: left;'> </td> <td><a href=\"my_account.php?page=pm\" style=\"font-size:12px; color:#00AEBF; \">Go back to inbox</a></td> </tr> <tr> <td height='35' bgcolor='#E7F7A5'> </td> <td bgcolor='#E7F7A5'> </td> </tr> </table></form></div> "; }else{ $to = $msg[from]; //get who it is to $from =$_SESSION[uSERNAME]; //who its from $subject = "RE: " . $msg[subject]; //new subject $msg = addslashes($_POST[msg]); //the content $date = date("F j, Y, g:i a"); //the date sent $do = mysql_query("INSERT INTO `private_msg` (`to`,`from`,`date`,`subject`,`content`) VALUES ('" . $to . "','" . $from . "','" . $date . "','" . $subject . "','" . $msg . "')") or die(mysql_error()); //insert into the table! $user_message="<table width=\"680\" border=\"0\" align=\"left\" cellpadding=\"5\" cellspacing=\"0\" class='private_msg_tbl' ><tr class=\"edit_profile_label\"> <td width=\"680\" height=\"35\" bgcolor=\"#E7F7A5\"> </td><tr> <td width=\"680\" >Message Sent!</td></tr> <td width=\"680\" height=\"35\" bgcolor=\"#E7F7A5\"> </td></tr> </table>"; echo "$user_message"; } } } ?> The last line above needs a break before it no matter what order the cases are in your code unless you want the script to execute the additional cases. Now, a few suggestions for coding better in the future: As mentioned previously, use $_POST['field'] instead of $_POST[field]. It'll prevent problems in the future. Indent you code to keep your code more readable. Finding a missing curly bracket or quote is much easier this way. Create functions for your code and call those functions in your switch instead of raw code. Use <?php instead of <? as some servers don't like the short tags. That should do you for a bit. Hope this helps, Handy PHP
  2. Well, it would help to see the rest of the code but I think that outside of your switch, you are running the query again somehow. Please post any other code you have that uses $do or "INSERT..." Handy PHP
  3. $QueryResult = @mysqli_query($DBConncet, $SQLstring); or die("<p>Unable to execute the query.</p>" semi-colon preceding an OR statement. Generally, your error message will give you a line number for the error. Generally, the problem is on the line right before the error was found... You had a semi-colon on line 3 which made the OR statement on line 4 return an error. You might want to consider NOT breaking your lines up so much since this seems to be causing you a lot of problems. Breaking your lines up can make reading your code easier sometime but in this case, it actually makes it harder to read. Perhaps if you indent the code after the first break it would make it clearer what belongs with what. Like so: if (!@mysqli_select_db($DBConnect, $DBName)) { $SQLstring = "CREATE DATABASE $DBName"; $QueryResult = @mysqli_query($DBConncet, $SQLstring) or die("<p>Unable to execute the query.</p>" . "<p>Error code " . mysqli_errno($DBCoonect) . ":" . mysqli_error($DBConnect)) . "</p>"; echo "<p>You are the first visitor!</p>" mysqli_select_db($DBConnect, $DBName); Also, you have some typing errors: line 3: $QueryResult = @mysqli_query($DBConncet, $SQLstring); Should Be: $QueryResult = @mysqli_query($DBConnect, $SQLstring) And Line 5 . "<p>Error code " . mysqli_errno($DBCoonect) Should Be: . "<p>Error code " . mysqli_errno($DBConnect) You really need to try and pay more attention to your code. There isn't a spellchecker for PHP, just an error message! Handy PHP
  4. "post composed message twice..." What? It displays twice in the view screen or gets placed in the database twice? And, is it just the message that is duplicated or is all of the detail repeated such as to, from, time, date, message, etc... Answering these questions will make in more likely that someone can help you. Handy PHP
  5. Well, I don't use postgresql but in MySQL, you can set a field to accept NULL (blank) values. However, if you can't do that, just replace zeros with NULLS for any output and replace NULLS with zeros to add to the database: if($from_database == 0){ $from_database = ''; } if($to_database == '' || $to_database == NULL || !$to_database){ $to_database = 0; } Handy PHP
  6. Well, I'm having a hard time comparing your code to the images you posted. I'm wondering if the current1.jpg is an actual screen shot of what is being displayed or an image you created to illustrate the problem. I think this is a mater of emptying your array before you start a new loop but I'm not sure. Handy PHP
  7. Might be a good idea to get a decent code editor that highlights and color codes your code to make it easier to find errors. Also, if you have any more errors, it would help to see the updated code if you could post it. Handy PHP
  8. Missing end parenthesis on line 5: die("<p> You must enter name and email. You need to go back to the Guestbook.</p>"; Should be: die("<p> You must enter name and email. You need to go back to the Guestbook.</p>"); Additional errors will likey happen with each of your die functions since your parenthesis are misplaced. Handy PHP
  9. I assume that the other machines (that load the pages slowly) are in the same building correct? If this is the case, then your bandwidth isn't as big of an issue since the connection is local unless you are using a domain name in which case, you have to leave your LAN and goto the Internet then have a nameserver send you back. It could be a router issue but more than likely, the computer that acts as the server in this situation, probably isn't capable of performing the task adequately. Network Adapter, Processor, Memory, and of course how many other processes are running can dictate how quickly the pages load. Many hosting companies use a separate servers for Apache and SQL. I guess, my suggestion is to try different connections to the script... Have the accessing systems browse directly to the hosting systems IP address to reduce router lag. Test the script on a cheap hosting account on the internet to see if there is an improvement. While restructuring your PHP script may help somewhat, it isn't going to change a load time from 1 minute to 5 seconds. However, assuming that you are using MySQL, optimizing your database queries can really improve your load time. If your script queries the DB and get information for the next query then the next, then there will be a lot of time wasted. You should try to minimize the number of separate queries by combining queries. You can search in on table for information related to another table in the same query, etc... Handy PHP
  10. Well, you can try this: <Location /index.html> AddType application/x-httpd-php .cgi </Location> But I don't think it will work. It is likely that the server will only parse one language or the other... As a result, it will more than likely try to parse one as the other and give you a fatal error. You really should try to convert the PHP portion of your code to Perl but I assume that you either don't know Perl or the PHP script is too large to convert. Of course, it is possible to run the PHP script remotely and dump the data back into the Perl script but that requires the proper Perl code to be added to do so. I don't know Perl well enough to tell you how to go about that. Handy PHP
  11. Well, you should start by reading the manual: http://us.php.net/manual/en/features.file-upload.post-method.php Next, I don't see this defined anywhere: $web_location=$web_dir.$imagefile_name; You don't specify anywhere what $imagefile_name is so it is just checking if the directory exists more than likely. When you do assign a value to $imagefile_name, you need a slash and it would look something like this: $web_location="$web_dir/$imagefile_name"; That should at least get you to the point where you'll start getting error message that will show you what to fix next. Handy PHP
  12. Well, the most basic method would be to check if $opt has a value... If there isn't a response then no value would be set for $opt. Or am I missing something? Handy PHP
  13. I don't see a closing tag for the first (solved_it) form... So the browser only sees on form. Add </form> in the appropriate place in your script. Hope This Helps, Handy PHP
  14. Use absolute path from root: Good luck, Handy PHP
  15. Well, this is more of an HTML problem... You don't have table cells "<TD>". Try this: <tr> <td><? echo $rows['datetime']; ?></td> <td><? echo $rows['cat']; ?></td> <td><? echo $rows['title']; ?></td> <td><? echo $rows['views']; ?></td> <td><? echo $rows['replies']; ?></td> </tr> Hope this helps, Handy PHP
×
×
  • 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.