6 Replies - 410 Views - Last Post: 10 April 2012 - 02:54 AM Rate Topic: -----

#1 Tsukuyomi  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 84
  • Joined: 22-February 11

Sending information to database error

Posted 08 April 2012 - 04:09 PM

I created variables for the ones that $ sign and assigned them values for the server, user and password and the $conn_error too.

I keep getting this: Error connecting to MySQL server

I basically have a form and want to send it what the user typed/enter to my database.
I already created a table called Test1

<?php
$dbc = mysql_connect($mysql_host , $mysql_user, $mysql_pass ) or die ($conn_error );

//select the database
mysql_select_db($mysql_db) or die($conn_error);

$query = "INSERT INTO Test1( First_Name, Last_Name, Religion) VALUES ($firstName, $lastName, $religion)";	


$result = mysql_query($dbc, $query) or die('Error querying database.');


mysqli_close($dbc);

?>




Is This A Good Question/Topic? 0
  • +

Replies To: Sending information to database error

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3115
  • View blog
  • Posts: 4,675
  • Joined: 08-June 10

Re: Sending information to database error

Posted 08 April 2012 - 04:19 PM

View PostTsukuyomi, on 08 April 2012 - 11:09 PM, said:

I created variables for the ones that $ sign and assigned them values for the server, user and password and the $conn_error too.

Where do you set those values? It's nowhere in that code. Given the error message, it's more than likely that those values are incorrect or missing.

Use the mysql_error function to get the actual error you are receiving from MySQL.
$dbLink = mysql_connect("host", "user", "pwd") or die(mysql_error());



Also, on line #13, you are using mysqli_close rather than mysql_close. (Notice the "i" after "mysql".)
Was This Post Helpful? 1
  • +
  • -

#3 jonesa01  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 25
  • View blog
  • Posts: 125
  • Joined: 18-February 07

Re: Sending information to database error

Posted 09 April 2012 - 04:15 AM

I would also recommend having two different messages for mysql_conntect and mysql_select_db so you can see which function is not working correctly.
Was This Post Helpful? 1
  • +
  • -

#4 Tsukuyomi  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 84
  • Joined: 22-February 11

Re: Sending information to database error

Posted 09 April 2012 - 03:13 PM

View Postjonesa01, on 09 April 2012 - 04:15 AM, said:

I would also recommend having two different messages for mysql_conntect and mysql_select_db so you can see which function is not working correctly.


I fixed it but still can't connect.

$dbc = mysql_connect($mysql_host , $mysql_user, $mysql_pass ) or die (mysql_error() );

//select the database
mysql_select_db($mysql_db) or die(mysql_error());

$query = "INSERT INTO Test1( First_Name, Last_Name, Religion) VALUES ($firstName, $lastName, $religion)";	


$result = mysql_query($dbc, $query) or die(mysql_error());


mysql_close($dbc);



here is the error:
Access denied for user 'myuser'@'starka.x10hosting.com' (using password: YES)
Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5723
  • View blog
  • Posts: 22,639
  • Joined: 23-August 08

Re: Sending information to database error

Posted 09 April 2012 - 03:15 PM

Contact your hosting company, or the help pages for your hosting company, for the correct settings to use.
Was This Post Helpful? 0
  • +
  • -

#6 Tsukuyomi  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 84
  • Joined: 22-February 11

Re: Sending information to database error

Posted 09 April 2012 - 04:30 PM

View PostJackOfAllTrades, on 09 April 2012 - 03:15 PM, said:

Contact your hosting company, or the help pages for your hosting company, for the correct settings to use.


Lets say I wanted to send the information the user enter into to the database. So far I have created a database, created a table named Test1 and Test1 has 3 rows.

BUT I got this error: Unknown column 'Sasuke' in 'field list'
when I entered Sasuke as the first name
Was This Post Helpful? 0
  • +
  • -

#7 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5723
  • View blog
  • Posts: 22,639
  • Joined: 23-August 08

Re: Sending information to database error

Posted 10 April 2012 - 02:54 AM

You need to quote string variables in queries:

$query = "INSERT INTO Test1( First_Name, Last_Name, Religion) VALUES ('$firstName', '$lastName', '$religion')";

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1