Hey guys I'm in the middle of connecting my website to my SQL database at the moment i have the following and I need some help if you guys dont mind

config.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);

submit_form.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'

'".$_SERVER['REMOTE_ADDR']."')");

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

    echo '<div style="color:#008000; font-weight:bold;">Registred successfully..!!</div>';
}else
{
//error message
    echo '<div style="color:#c24f00; font-weight:bold;">unable to registred !!</div>';
}

I have only ever connected via the old ms access connection so connecting via sql is a whole new thing to me

Can someone just have a look and see where I'm going wrong please, a few weeks ago I put a password onto my PHPmyadmin and it has taken me a week to get back to this stage as xampp decided to bugger up on me

Use below code for config.php

<?php

$mysql_hostname = "localhost";

$mysql_user = "database username";

$mysql_password = "database password";

$mysql_database = "database name";

$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) 

or die("Opps some thing went wrong");

mysql_select_db($mysql_database, $bd) or die("Opps some thing went wrong");

?>

Due to column mismatch in line 14.

Remove '', in values from line 14

tried that and all that is coming up is the whole php code.

all that is showing is the following sorry to be such a pain

$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' '.$_SERVER['REMOTE_ADDR'].')); //if value inserted successyully disply success message if($query) { echo '
Registred successfully..!!
'; }else { //error message echo '
unable to registred !!
'; }
Member Avatar for Sanchit_Sahu

check for the following:-

  1. In Line14 under value(), the first empty ' ' is for some id that u have put on Auto_increment..right??

If yes, u need to put the field name of the id field from ur database there(before

`'firstname'`

on line14).

If not, please remmove those..u dont need it there.

  1. if u have put a password for ur mySql, put it in Line3.. Also the database name can be written in line3 as:

    $a=mysql_connect("localhost","root","", "database_name");

  2. And also on line16, i dont find the respective column of

    '".$_SERVER['REMOTE_ADDR']."'

    in your database

kindly check the above points

and if the prob still persists...please also give the details of ur database columns

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

replace the code as below

$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 thanks for you comments i will have a look and see if it helps

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.