0

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

6
Contributors
13
Replies
50
Views
3 Years
Discussion Span
Last Post by stokie-rich
0
$query=mysql_query("INSERT INTO registration (`firstname`, `lastname`, `username`, `confirmusername`, `password`, `confirmpassword`, `email` ,`confirmemail`) VALUES ('$firstname', '$lastname', '$username' , '$confirmusername' , '$password', '$confirmpassword', '$email' , '$confirmemail');");

Edited by cfv1000

0

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?

0

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

0

White screen usually means syntax error in php code.

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

0

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>';
}
?>
0

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

0

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)

0

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!

-2
 $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.

Edited by pritaeas: Removed unrelated self-promotion link.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.