1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

form and mysql help please

Discussion in 'MySQL' started by YSeo, Nov 6, 2009.

  1. #1
    hey guys,

    Let me please describe the situation:

    I have a contact form in my website which sends emails every time a person fills out the form. then , it should also insert the data into mysql database.
    unfortunately , it does not work - not sending the form and does not insert into the database.
    can you guys please take a look at both my html and php scripts and let me know what you think ? I would greatly appreciate it.

    here is the html:

    <script type="text/javascript" language=JavaScript src=Validation.js></script>
    <table width="230" height="180" cellpadding="4" cellspacing="0" border="0" dir=rtl align=left bgcolor=#fffffff style="border: solid 1px #164976">
    <form method=post name="frmEmail" action="Test123.php" onsubmit="javascript:return CheckForm('frmEmail')">
    <tr>
    <td colspan=3 align="right" height=10 valign="top" class="leadFromTop"><b>Contact us</b></td>
    </tr>
    <tr>
    <td colspan=3 align="right" class="leadTextNN11">
    Please contact us:<br>
    <br>
    </td></tr>

    <tr>
    <td width=80 class="purpleTextN">&nbsp;name: <font color='red'>*</font>&nbsp;</TD>
    <td width=5></td>
    <td align="left"><input class="inputShort" type="text" id="txtName" name="txtName"></td>
    </tr>
    <tr>
    <td class="purpleTextN">phone: <font color='red'>*</font>&nbsp;</TD>
    <td width=5></td>
    <td align="left"><input class="inputShort" type="text" id="txtPhone" name="txtPhone"></td>
    </tr>
    <tr>
    <td class="purpleTextN">email</td>
    <td width=5></td>
    <td align="left"><input class="inputShort" type="text" id="txtEmail" name="txtEmail" ></td>
    </tr>
    <tr>
    <TD class=purpleTextN noWrap align=left><nobr>Subject <font color='red'>*</font>&nbsp;</nobr></TD>
    <TD align=middle colSpan=3>
    <SELECT class=inputList id="ddlSubject" name="ddlSubject">
    <option value="" selected>select</option>
    <option value="A">A</option>
    <option value="B">B</option>
    <option value="C">C</option>
    </SELECT>&nbsp;</TD>
    </tr>

    <tr>

    <td class="purpleTextN">Content</td>
    <td width="5" nowrap></td>
    <td class="purpleTextN"><textarea name="txtcontent" id="txtcontent" class="select210" rows="2" cols="20"></textarea></td>
    </tr>
    SEMrush
    <tr>
    <td colspan=3 align="right" class="leadTextNN11">
    <br>
    </td></tr>
    <tr>
    <td colspan=3 align=center>
    <input class="" type="button" name="Submit" value="send" onclick="CheckForm('frmEmail');return false";">
    </td></tr>
    </table><br>
    </form>


    here is the php:

    <?php
    $name = $_POST['txtName'] ;
    $phone = $_POST['txtPhone'] ;
    $email = $_POST['txtEmail'] ;
    $Subject = $_POST['ddlSubject'] ;
    $Content = $_POST['txtcontent'] ;

    mail( "emailtosendtheform", "Example feedback",
    $name , $phone, $email , $Subject ,$Content "From: $email" );
    header( "Location: http://www.example.com/thankyou.html" );


    // Make a MySQL Connection
    mysql_connect("localhost", "username", "password") or die(mysql_error());
    mysql_select_db("databasename") or die(mysql_error());

    // Insert a row of information into the table "tablename"
    mysql_query("INSERT INTO tablename
    (name, phone , email , Subject , Content) VALUES
    ('$_POST[name]','$_POST[phone]','$_POST', '$_POST[Subject]', '$_POST[Content]')";

    or die(mysql_error());

    echo "Data Inserted!";

    ?>
     
    YSeo, Nov 6, 2009 IP
    SEMrush
  2. organicCyborg

    organicCyborg Peon

    Messages:
    331
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Are you getting any errors?

    Your mail() function call needs to be fixed, unless you just changed that to remove your email address.
     
    organicCyborg, Nov 6, 2009 IP
  3. YSeo

    YSeo Peon

    Messages:
    533
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    do you refer to "emailtosendtheform" ?

    Yes , I just changed that to remove myemail address.

    I do getting errors , do you have any idea why?

    Thank you.
     
    YSeo, Nov 7, 2009 IP
  4. fairuz.ismail

    fairuz.ismail Peon

    Messages:
    232
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #4
    whats the error are you getting?
    take note that if you are developing this on your local pc at home, (i mean not on the real server), theres a chance the email will not come out.. you have to have a mail server.
     
    fairuz.ismail, Nov 7, 2009 IP
  5. YSeo

    YSeo Peon

    Messages:
    533
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    of course I do

    I have an hosting account in which I'm playing with.

    It just says "error in line 17" or similar.

    it does not specify anything.

    thank you.
     
    YSeo, Nov 7, 2009 IP
  6. fairuz.ismail

    fairuz.ismail Peon

    Messages:
    232
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #6
    so have you check what is the code at line 17? or at line16 at least
     
    fairuz.ismail, Nov 7, 2009 IP
  7. fairuz.ismail

    fairuz.ismail Peon

    Messages:
    232
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #7
    your table name is really tablename?

    one more thing, try to change (name, phone , email , Subject , Content) to ('name', 'phone' , 'email' , 'Subject' , 'Content')
     
    fairuz.ismail, Nov 7, 2009 IP
  8. YSeo

    YSeo Peon

    Messages:
    533
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    it is not really tablename of course

    I created a real table.

    regarding changing (name, phone , email , Subject , Content) to ('name', 'phone' , 'email' , 'Subject' , 'Content') :

    in this tutorial
    http://www.tizag.com/mysqlTutorial/mysqlinsert.php
    is says otherwise.


    any other ideas?

    thanks for your help.
     
    YSeo, Nov 7, 2009 IP
  9. fairuz.ismail

    fairuz.ismail Peon

    Messages:
    232
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #9
    so have you check what is the code at line 17?

    check your database connection. Maybe it's the source of the problem
     
    fairuz.ismail, Nov 7, 2009 IP
  10. YSeo

    YSeo Peon

    Messages:
    533
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #10
    I will

    so as far as you concern , is the code alright?

    thank you so much.
     
    YSeo, Nov 7, 2009 IP
  11. fairuz.ismail

    fairuz.ismail Peon

    Messages:
    232
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #11
    i just read the code, and look what i found! lol

    mail( "emailtosendtheform", "Example feedback",
    $name , $phone, $email , $Subject ,$Content "From: $email" );
    header( "Location: http://www.example.com/thankyou.html" );

    This is wrong. Refer to this http://fr2.php.net/manual/en/function.mail.php to get a good example of how using the mail function.

    $to = 'nobody@example.com';
    $subject = 'the subject';
    $message = 'hello';
    $headers = 'From: ' . "\r\n" .
    'Reply-To: ' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

    mail($to, $subject, $message, $headers);

    And you use header function just before the query to the database, thats kinda wrong to. If you call that header function, it will redirect you to the page you specified. Thus, the code below it will not be executed.
     
    fairuz.ismail, Nov 8, 2009 IP
  12. YSeo

    YSeo Peon

    Messages:
    533
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Alright man
    Once again , thanks for your help .
     
    YSeo, Nov 8, 2009 IP