Parse error driving me insane

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

gandy92
New php-forum User
New php-forum User
Posts: 1
Joined: Tue Apr 09, 2013 9:14 am

Parse error driving me insane

Postby gandy92 » Tue Apr 09, 2013 9:21 am

Hi im really new to php and have been trying to connect my html 5 web forms with an MySQL database that is on my local host (using php my admin and Apache through WAMP). I have written my code as best i can and through internet/peer guidance the code is correct and yet i still get a parse error on the ?> at the end of my code.
Please if anyone could help me it would be very much appreciated
thanks

code:

<?php
if ($_SERVER['REQUEST_METHOD'] == "POST") {
$con = mysql_connect("localhost");
if (!$con){die('Could not connect: ' . mysql_error());}
mysql_select_db("site", $con);
mysql_query("INSERT INTO contact(email)VALUES ('$_POST[Email]')");
if ($_POST['submit']) {
if ($Email) {

echo "Successful";
}

else {
echo "ERROR";
}

mysql_close();}
?>

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Parse error driving me insane

Postby johnj » Tue Apr 09, 2013 8:35 pm

Do you need "}" after mysql_close() ??

swarups
New php-forum User
New php-forum User
Posts: 20
Joined: Tue Mar 06, 2012 11:05 pm

Re: Parse error driving me insane

Postby swarups » Tue Apr 09, 2013 9:49 pm

Hi gandy92,

You have missed a curly brace(}) at the end. So the first curly brace({) does not end. Your code should look like

Code: Select all

<?php
if ($_SERVER['REQUEST_METHOD'] == "POST") {
    $con = mysql_connect("localhost");
    if (!$con){die('Could not connect: ' . mysql_error());}
    mysql_select_db("site", $con);
    mysql_query("INSERT INTO contact(email)VALUES ('$_POST[Email]')");
    if ($_POST['submit']){
   
        if ($Email) {
                echo "Successful";
        }
       
        else {
            echo "ERROR";
        }
   
        mysql_close();
    }//end of 2nd brace
}//end of first brace
?>


I think this will solve your prob. :)

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: Parse error driving me insane

Postby seandisanti » Tue Apr 09, 2013 10:01 pm

Also, look into PDO instead of mysql_ functions. mysql_ are deprecated and will probably be removed in a future version sooner rather than later. http://jream.com/learning/videos/php-oo ... o-examples is a good short video of PDO in action. It's faster, more secure, and the accepted standard for database interaction with php. </rant>


Return to “PHP coding => General”

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron