SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2006
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy sending email using form in page...problem...

    hi,i'm trying enable my user to send a feedback to the author under his post by email using form...

    however,i keep getting error message:
    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 1

    i have go through the code for times but don't get to figure the problem...

    can anyone please show me where are my mistakes?

    thank you!

    PHP Code:
    <?php 

    include("../config.php");
    $id=$_GET['id'];

    $query="SELECT * FROM post WHERE id='".$id."'";
    $result=mysql_query($query) or die (msql_error());
    $row mysql_fetch_array($result) or die(mysql_error());

    $tmpId=$row['id'];
    $tmpTitle=$row['title'];



      if (
    $mode == "submit") { 
        if (
    $enable_html != "on") { 

          
    $mail_body htmlspecialchars ($mail_body); 
        } 



        
    $headers .= "MIME-Version: 1.0 \n"
        
    $headers .= "Content-type: text/html; charset=iso-8859-1 \n"
        
    $headers .= "from:$mail_from\r\nCc:$mail_cc\r\nBcc:$mail_bcc"


        if (@
    mail ($mail_to$mail_subject$mail_body$headers)) { 
          print (
    "<h1><font color=\"#004000\">The e-mail was sent successfully!</font></h1>"); 
        } else { 
          print (
    "<h1><font color=\"#880000\">An error occurred while sending the e-mail!</font></h1>"); 
        } 


      } 
    ?> 

    <script language="javascript"> 
      function DoSubmit () 
      { 

        if (document.form.mail_from.value == "") { 
          alert ("You forgot to enter the 'from' field."); 
          document.form.mail_from.focus (); 
          return ""; 
        } 

        if (document.form.mail_to.value == "") { 
          alert ("You forgot to enter the 'to' field."); 
          document.form.mail_to.focus (); 
          return ""; 
        } 

        if (document.form.mail_subject.value == "") { 
          alert ("You forgot to enter the 'subject' field."); 
          document.form.mail_subject.focus (); 
          return ""; 
        } 

        if (document.form.mail_body.value == "") { 
          alert ("You forgot to enter the 'body' field."); 
          document.form.mail_body.focus (); 
          return ""; 
        } 
        
        document.form.submit (); 
        
      } 
    </script> 

    <fieldset><legend><b>Send Email</b></legend>
    <form action="<?php echo $_SERVER['document root'?>" method="post" name="form"> 
      <table width="100%" border="0">
       
        <tr>
          <td colspan="2"> Simply fill out the following form to directly contact 
            this member.<br><br></td>
        </tr>
        <tr>
          <td colspan="2"> <b>*Required Fields</b></td>
        </tr>
        <tr> 
          <td width="25%"><b>* Your Email</b></td>
          <td width="75%">
            <input type="text" name="mail_from" size="40">
          </td>
        </tr>
        <tr> 
          <td></td>
          <td>
            <input type="hidden" name="mail_to" size="40" value="myemail@google.com">
          </td>
        </tr>
        <tr> 
          <td><b> &nbsp;&nbsp;&nbsp;Subject:</b></td>
          <td>
            <input type="text" name="mail_subject" size="40" value="Reply to : <?php echo $tmpTitle ?>" readonly>
          </td>
        </tr>
        <tr> 
          <td valign="top"><b>* Your Message</b></td>
          <td>
            <textarea name="mail_body" cols="40" rows="10"></textarea>
          </td>
        </tr>
        <tr> 
          <td></td>
          <td>
            <input type="checkbox" name="enable_html">
            enable HTML in this message.<br><i>- Max. 5,000 characters (approximately 850 words) <br> 
    - Please do not spam and send messages containing foul, offensive and/or obscene material. </i></td>
        </tr>
        <tr> 
          <td height="34"> 
            <input type="hidden" name="mode" value="submit">
            
          </td>
          <td height="34"> 
            <input type="button" onclick="DoSubmit ()" value=" Send ">
            <input type="reset" value="Reset">
          </td>
        </tr>
      </table> 
    </form> 
    </fieldset>
    Attached Files Attached Files
    newbie...really need your guidance......

  2. #2
    SitePoint Wizard bronze trophy Kailash Badu's Avatar
    Join Date
    Nov 2005
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you sure $id holds a value?

    Replace the second block of code with this:
    PHP Code:
    $query="SELECT * FROM post WHERE id='".$id."'"
    $result=mysql_query($query) or die (msql_error()); 
    $row mysql_fetch_array($result) or die($query "<br />" .mysql_error()); 
    run the code again.

  3. #3
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    note that mSql is not the same as mYsql

  4. #4
    SitePoint Wizard bronze trophy Kailash Badu's Avatar
    Join Date
    Nov 2005
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, at least I should have noted it.

  5. #5
    SitePoint Wizard bronze trophy Kailash Badu's Avatar
    Join Date
    Nov 2005
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $query="SELECT * FROM post WHERE id='".$id."'"
    $result=mysql_query($query) or die ($query "<br />" mysql_error()); 
    $row mysql_fetch_array($result) or die(mysql_error()); 


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
  •