Web Hosting Talk







View Full Version : can sum1 check this please....


Flumps
10-06-2008, 04:21 PM
<?php
$con = mysql_connect("localhost","shcvnet_simon","bombfire101");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("shcvnet_shcv", $con);

$sql="INSERT INTO phoneList (firstName, lastName, email, phone)
VALUES
('$_POST[firstName]','$_POST[lastName]','$_POST[email]','$_POST[phone]')";

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

mysql_close($con)

?>



error im getting is No database selected.

the database name is correct ive checked it 101 times.

I can establish a connection fine ive tested that bit of the code too so I know the username and password are fine.

any ideas?

im uploading from a form.

Marc_W3Solutions
10-06-2008, 04:53 PM
It might be because your VALUES command and the values you are inserting are on separate lines. Just a thought from glancing at it. Might work by changing just that. Otherwise i'd need to look at it more closely.

getweb
10-06-2008, 05:47 PM
Probably the user doesn't have access to the DB. Add one more line of error-checking where you select the DB:


$db_selected = mysql_select_db("shcvnet_shcv", $con);
if (!$db_selected) {
die ('Could not select DB: ' . mysql_error());
}

Flumps
10-07-2008, 05:13 AM
Probably the user doesn't have access to the DB. Add one more line of error-checking where you select the DB:


$db_selected = mysql_select_db("shcvnet_shcv", $con);
if (!$db_selected) {
die ('Could not select DB: ' . mysql_error());
}



ah yes....silly me forgot to add the user to the database lmao, i feel so stupid lol.