Hi Guys I'm connecting to a database using PHP and MYSQL,

here is the code

<?php
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$username=$_POST['username'];
$confirmusername=$_POST['confirmusername'];
$password=$_POST['password'];
$confirmpassword=$_POST['confirmpassword'];
$email=$_POST['email'];
$confirmemail=$_POST['confirmemail'];

//Database connection
require_once("config.php");

//mysql query to insert value to database
$query=mysql_query("INSERT INTO registration (`firstname`, `lastname`, `username`, `confirmusername`, `password`, `confirmpassword`, `email` ,`confirmemail`) VALUES ('$firstname', '$lastname', '$username' , '$confirmusername' , '$password', '$confirmpassword', '$email' , '$confirmemail'));



//if value inserted successyully disply success message
//if($query)
{

    echo 'Registred successfully..!!</div>';
}else
{
//error message
    echo '<unable to registred !!</div>';
}
?>

When I click on submit I get the following error
Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\submit-form.php on line 29

Can anybody help me?

Rich

$query=mysql_query("INSERT INTO registration (`firstname`, `lastname`, `username`, `confirmusername`, `password`, `confirmpassword`, `email` ,`confirmemail`) VALUES ('$firstname', '$lastname', '$username' , '$confirmusername' , '$password', '$confirmpassword', '$email' , '$confirmemail');");

hi guys sorted that out now thanks for that

I have just one more problem, this is the connection string for the SQL

<?php 
Mysql Connect  |   mysql_connect("host","username","password");
//Below example to connect in localhost
$a=mysql_connect("localhost","root","");

//select your database
$b=mysql_select_db("database_name",$a);
?>

I'm getting this error message

Parse error: syntax error, unexpected 'Connect' (T_STRING) in C:\xampp\htdocs\config.php on line 2

Is this because I have not declaired the database name and or the user name password or the root of the loca host?

remove line 2 from your code
Mysql Connect | mysql_connect("host","username","password");

hi urtrivedi i've tried that and i've just looked at the phpmyadmin and there is still not reccords in the database just still a white screen when i press the submit button

White screen usually means syntax error in php code.

uncomment line 20 if ($query)
becasue you can not use ELSE (line 24) without IF

there is an if statment in there at the moment but i think it needs to be changed around a little bit

if($query)
{

    echo 'Registred successfully..!!</div>';
}else
{
//error message
    echo '<unable to registred !!</div>';
}
?>
Member Avatar for diafol

Sorry slightly off-topic, but you do realise that mysql_* functions have been deprecated and shouldn't be used?

Member Avatar for diafol

OK, PDO is probably the more convenient out of mysqli and PDO. mysqli can be a bitch when it comes to handling 'fetch' and sometimes the mysqlnd driver is not installed on servers - which some mysqli functions need.

See pritaeas' snippets on how to use PDO (or mysqli)

thanks so much for this I will take a look at it once i have got back from taking my mum to another hospital appointment i just hope this time we get some answers.

I have already got the table crated in sql so that is a relife, like i have said before when i was at uni we used the ms access and the old ace.oledb.12.0 connection but a year after they changed and used sql wich is always the case!

 $query=mysql_query("INSERT INTO registration (`firstname`, `lastname`, `username`, `confirmusername`, `password`, `confirmpassword`, `email` ,`confirmemail`) VALUES ('$firstname', '$lastname', '$username' , '$confirmusername' , '$password', '$confirmpassword', '$email' , '$confirmemail')");

Your mysql_query function syntax is wrong ….. you must put quotation end of the mysql_query() function.

thanks for the post but I'm still confused if I'm honest!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.