Page 1 of 1

I Need Help !!!! ( well in many areas, but for now in PHP)

Posted: Sun Sep 18, 2005 7:14 pm
by willb77
I need help. I'm sure it is something simple. I'm just not seeing it.

I am getting the following message when I try to connect to a MySQL db.

"Warning: mysql_connect(): Lost connection to MySQL server during query in /hsphere/local/home/willb/3pp.com/php3/MedProfiles/my_functions.php on line 22
Could not connect: Lost connection to MySQL server during query"

Here's my code;

Code: Select all

<?php
$link = mysql_connect('the_correct_server_name', 'the_correct_uid', 'the_correct_psw'') or
die('Could not connect: ' . mysql_error());
mysql_select_db('willb_medprofiles', $link) or die ('Could find DB: ' . mysql_error());

include("my_functions.php");
$unique_id = unique_id();

$sql = "Insert into customer
(fname,
lname,
mid_intial,
social_security_num,
sex,
date_of_birth,
email,
address,
city,
state,
zip,
country,
phone,
cell,
DNR,
unique_id)
VALUES
('". $_Post['fname']."',
'". $_Post['lname']."',
'". $_Post['mid_intial']."',
'". $_Post['social_security_num']."',
'". $_Post['sex']."',
'". $_Post['date_of_birth']."',
'". $_Post['email']."',
'". $_Post['address']."',
'". $_Post['city']."',
'". $_Post['state']."',
'". $_Post['zip']."',
'". $_Post['country']."',
'". $_Post['phone']."',
'". $_Post['cell']."',
'". $_Post['DNR']."',
'$unique_id') ";

echo "DEBUG :" ;
echo $sql;
echo "<br>";
echo $unique_id ;

/*If (isset($sql) && !empty($sql)) {
$result = mysql_query($sql) or die("Invalid Query:" . mysql_error());
*/
?>

JCART | Please use

Code: Select all

tags when posting php code. Review [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Sun Sep 18, 2005 9:14 pm
by John Cartwright
first things first,

Code: Select all

$link = mysql_connect('the_correct_server_name', 'the_correct_uid', 'the_correct_psw'') or
die('Could not connect: ' . mysql_error());
should be

Code: Select all

$link = mysql_connect('the_correct_server_name', 'the_correct_uid', 'the_correct_psw') or
die('Could not connect: ' . mysql_error());
You had an extra quote in there

Posted: Sun Sep 18, 2005 10:20 pm
by feyd
Moved to PHP - Code.

I still need help with PHP connection to MYSQL!!!!

Posted: Mon Sep 19, 2005 7:12 am
by willb77
feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hi thanks for the reply.

I changed the quote and still got the same error.  I am going bald pulling my hair out on this one. 


Warning: mysql_connect(): Lost connection to MySQL server during query in /hsphere/local/home/willb/3pp.com/php3/MedProfiles/set_cust_info.php on line 2
Could not connect to the DB: Lost connection to MySQL server during query





Here's my code;

Code: Select all

<?php
$link = mysql_connect('the_correct_server_name', 'the_correct_uid', 'the_correct_psw') or
die('Could not connect: ' . mysql_error());
mysql_select_db('willb_medprofiles', $link) or die ('Could find DB: ' . mysql_error());

include("my_functions.php");
$unique_id = unique_id();

$sql = "Insert into customer
(fname,
lname,
mid_intial,
social_security_num,
sex,
date_of_birth,
email,
address,
city,
state,
zip,
country,
phone,
cell,
DNR,
unique_id)
VALUES
('". $_Post['fname']."',
'". $_Post['lname']."',
'". $_Post['mid_intial']."',
'". $_Post['social_security_num']."',
'". $_Post['sex']."',
'". $_Post['date_of_birth']."',
'". $_Post['email']."',
'". $_Post['address']."',
'". $_Post['city']."',
'". $_Post['state']."',
'". $_Post['zip']."',
'". $_Post['country']."',
'". $_Post['phone']."',
'". $_Post['cell']."',
'". $_Post['DNR']."',
'$unique_id') ";

echo "DEBUG :" ;
echo $sql;
echo "<br>";
echo $unique_id ;

/*If (isset($sql) && !empty($sql)) {
$result = mysql_query($sql) or die("Invalid Query:" . mysql_error());
*/
?>
8O


feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Mon Sep 19, 2005 7:19 am
by Jenk
There is a connection problem between yourself and the mysql server/database.

Unfortunately it's not a lot we can help with I am afraid (i.e. it's not your code at fault)

I would also like to point out your code is VERY open to attacks. You should sanities your inputs with the use of mysql_real_escape_string() but worry about this after you have solved the connectivity issues :)

Posted: Mon Sep 19, 2005 8:51 am
by shiznatix
well try a real small query see if it works, somtin like

Code: Select all

INSERT INTO
  customer
    (fname)
VALUES
    ("my fname")
also you use $_Post[].... does it not have to be $_POST[] (all caps)? i thought it would have to be since $Submit won't exist if you named it like name="submit"