Page 3 of 3 FirstFirst 123
Results 21 to 24 of 24

Thread: Another error

  1. #21
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    your mysql error will probably tell you that you have syntax error.

    one of your fields is named from, which is a mysql keyword (command). you must tell mysql that you mean to use the literal value of the word. you should always use backticks to specify literal words (column names, etc.) in your sql commands:
    PHP Code:
    $insert "
       INSERT INTO `pmsys` (`to`, `from`, `title`, `message`, `date`, `ifread`) 
       VALUES ('
    $to', '$from', '$title', '$content', '$date', '$ifread')"
    note that these are backticks ( ` ), NOT single-quotes ( ' ).

    (I could have sworn that we'd addressed this issue before, but I guess it was a different thread. also, in PHP, you don't need to break out of a double-quoted string to use a variable. that's what double-quotes are for, to use $variables inside a string. note my changes above.)

    Edit: I've looked over your current code again (from post 19).
    • you still have the form inside your first if() block.
      If you can see the form, then you're either submitting from a different page, or this is not the current version of the code you're using.
    • you have _no_ form fields named message_from or message_date.
      this means that your $time and $from variables will always be empty.
      further, your sql statement uses the variable $date (which doesn't exist), not $time as I suspect you intended.
    • the variable $ifread doesn't exist, either.
    • you don't escape any of your POST values, so your database is wide open to sql injection attacks.


    As I said earlier, I would strongly recommend planning this all out first, and then opening a new file and rewriting it from scratch.
    As it stands now, you are losing track of where your changes were made, and you're starting to have old problems show up again (probably as a result of copy-pasting).

    I'll be happy to help you further if you decide to follow this advice.

    Last edited by traq; 08-24-2011 at 09:39 PM.

  2. #22
    Join Date
    Mar 2011
    Posts
    2,145
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    Thanks for the advise Traq. If this dosn't work I will plan it all out then rewrite it all.

    The page that the form is on, is also the page that is processing the form. It's called messageck.php

    I would like it so that If the form hasn't been submitted yet, The form shows up, else it says thankyou and the form disappears. So the form can't be in the isset $ post and I think that's were the problem is. Could anyone offer a soloution?

  3. #23
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by keyboard1333 View Post
    I would like it so that If the form hasn't been submitted yet, The form shows up, else it says thankyou and the form disappears. So the form can't be in the isset $ post and I think that's were the problem is. Could anyone offer a soloution?
    you should re-read posts #2, 6, 8, 11, 13, 16, and 21.

    As far as "planning it out" goes, I'm going to press the issue. here's an outline of what you're trying to do (as I understand it so far):
    PHP Code:
    if( /* cookie exists? */ ){ 
         
    /* set user name */ 
    /* (no else{} block) */

    if( /* form was submitted? */ ){
         
    /* prepare variables to process form submission */

         
    if( /* "to" user exists? */ ){
              
    /* save message to database, display "thanks" */ 

         
    }else /* "to" user doesn't exist */ 
              
    /* display error message */ 
         
    }

    }else 
    /* form not submitted */ 
         
    /* display form */ 

    once you understand the process that your script needs to follow, it becomes much easier to write the code.
    Last edited by traq; 08-25-2011 at 05:03 AM.

  4. #24
    Join Date
    Mar 2011
    Posts
    2,145
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    Thanks Traq for all your suggestions. I have gotten the script working. Thankyou so much everyone.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •