Jump to content

[SOLVED] Submitting data but getting error "no database selected"


fbm

Recommended Posts

Hi

 

I am trying to submit some very simple data to my DB but it returns an error saying no DB selected.

 

my submit page is simple

 

<form name="form" method="POST" action="?page=processclient">
<input name="client_name" type="text" value="client name" />
<input name="client_email" type="text" value="client email" />
<input name="add" type="submit"/>
</form>

 

it gets passed to processclient.php which looks like this

 

<?php

include "includes/config.php";

$client_name = $_POST['client_name'];
$client_email = $_POST['client_email'];

$query = "INSERT INTO `clients`(`client_name`,`client_email`)VALUES('".$client_name."','".$client_email."')";
mysql_query($query) or die(mysql_error());

echo "<center>";
echo "Please Wait ... Client being added";
echo "<META HTTP-EQUIV=Refresh CONTENT='5; URL=?page=manage'> ";
echo "</center>";
?>

 

and my config file looks like this

 

<?php

$dbhost = "localhost"; 
$dbname = "hidden"; 
$dbuser = "hidden"; 
$dbpass = "hidden"; 

//connect to MySQL database
$db = mysql_connect($dbhost,$dbuser,$dbpass); 
mysql_select_db("$dbname",$db); 

?>

 

I have removed my DB login details, i'm sure i get connected to the DB as i don't get an error saying cant connect.

 

I'm new to PHP but have a few years HTML/CSS knowledge so be easy in your response if its something sillly :)

 

Any ideas?

 

Cheers

Make sure this value is 100% correct, also it is case sensitive:

 

$dbname = "hidden";

 

This should work:

$dbHost = "localhost";        //Location Of Database usually its localhost
$dbUser = "xxxx";            //Database User Name
$dbPass = "xxxx";            //Database Password
$dbDatabase = "xxxx";       //Database Name

$db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Error connecting to database.");
mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database."); 

Your form action is wrong.

 

<form name="form" method="POST" action="?page=processclient">

 

should be....

 

<form name="form" method="POST" action="processclient.php">

 

I don't think there is anything wrong with that...

Your form action is wrong.

 

<form name="form" method="POST" action="?page=processclient">

 

should be....

 

<form name="form" method="POST" action="processclient.php">

 

I don't think there is anything wrong with that...

 

The first action will post to the same page. The op states he is passing the form to processclient.php.

Your form action is wrong.

 

<form name="form" method="POST" action="?page=processclient">

 

should be....

 

<form name="form" method="POST" action="processclient.php">

 

I don't think there is anything wrong with that...

 

The first action will post to the same page. The op states he is passing the form to processclient.php.

 

ah... didn't read that :) but it still could work if he was on processclient.php, and just have it post back to it's self, he never specified what page the form was on...

WOW 3 fast responses.

 

I checked over my code and all was lookign good against your comments so i checked my DB and silly me mispelt the DB name in PMA so corrected that and all workign fine now :)

 

As for the comments about the form action beign correct or not, I am using a variable for my page links and the action i had in my code does post correctly :) not sure how it all works lol just getting code from tutorials and guides on teh web and putting it all together :)

 

Thanks guys, working now. How do i changed the forum post to solved? im new here

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.