0

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

3
Contributors
6
Replies
22
Views
3 Years
Discussion Span
Last Post by stokie-rich
0

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

Edited by rpv_sen: missed

0

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

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

0
$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'));

Edited by rpv_sen: update

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.