Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-12-2012, 05:04 PM   PM User | #1
mscoder
New to the CF scene

 
Join Date: Nov 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
mscoder is an unknown quantity at this point
database connectivity problem

I used the following code for inserting form data into "userinfo" table of "user" database.The database and table was created on xampp(phpmyadmin).But the page displayed "Error: No database selected".... why?pls help..


<?php
$con = mysql_connect("localhost","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("user",$con);

$sql="INSERT INTO userinfo(id,pass)
VALUES
('$_POST[UID]','$_POST[pass]')";

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";

mysql_close($con);
?>
mscoder is offline   Reply With Quote
Old 11-12-2012, 05:06 PM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Try
PHP Code:
mysql_select_db("user",$con) or die(mysql_error()); 
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 11-13-2012, 01:49 PM   PM User | #3
alemcherry
New Coder

 
Join Date: Apr 2010
Posts: 55
Thanks: 0
Thanked 4 Times in 4 Posts
alemcherry is an unknown quantity at this point
Wasn't that obvious? You have error checking everywhere, except on line where it select the db. The error message clearly says "Error: No database selected"

Should be a wrong database name or the user have no rights on database mentioned.
__________________
Hosting Reviews and Discounts: Bluehost Coupon and Hostmonster Coupon
alemcherry is offline   Reply With Quote
Reply

Bookmarks

Tags
database

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:20 PM.


Advertisement
Log in to turn off these ads.