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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
willb77
Forum Newbie
Posts: 2
Joined: Sun Sep 18, 2005 7:10 pm

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

Post 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]
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Moved to PHP - Code.
willb77
Forum Newbie
Posts: 2
Joined: Sun Sep 18, 2005 7:10 pm

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

Post 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]
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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 :)
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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"
Post Reply