Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 22nd, 2006, 4:04 PM   #1
piercy
Programmer
 
Join Date: Apr 2006
Posts: 35
Rep Power: 0 piercy is on a distinguished road
Unhappy php mysql_connect parse error

hi am quite new to php and i have made a code that sends an email to a specified email address. i also want the code to store the email in a database. i have tried many online tuorials and books but always get a parse error on the line of mysql_connect().

user name: root
with no password.

here is the code i have put together:
$fname = $_POST["first"];
$sname = $_POST["last"];
$email = $_POST["email"];
$msg = $_POST["message"];
$date = date('l dS F Y at h:i:s A');


mail('anon@anon.com', 'html form to email' , 
"From: $fname $sname \n email address: $email \n sent: 
$date \n \n \n \t $msg")


$db = @mysql_connect('localhost', 'root', '');
mysql_select_db(test) ;
$result = "INSERT INTO messages ('first name' , 'last name' 
, 'email address' , 'date' , 'message') VALUES ('$fname' , 
'$lname' , '$email' , '$date' , '$msg'")
mysql_query($sql)

also to note that when we installed mysql we had a little trouble setting the usernames and permissions. im wondering if this is why im getting this problem. i really dont see how the many examples and books i ahve gone through can all be wrong.

please help!
thanks
piercy

:banana:

Last edited by piercy; Apr 22nd, 2006 at 4:12 PM. Reason: didnt read the rules thread so thought i would do it properly (code)
piercy is offline   Reply With Quote
Old Apr 22nd, 2006, 4:11 PM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
You're missing a semicolon. :p

Please, use [code] tags next time.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Apr 22nd, 2006, 4:14 PM   #3
piercy
Programmer
 
Join Date: Apr 2006
Posts: 35
Rep Power: 0 piercy is on a distinguished road
okay i edited it into code tags and where are the semicolons missing. i kinda new to this.

thanks again
piercy
piercy is offline   Reply With Quote
Old Apr 22nd, 2006, 4:47 PM   #4
Kaja Fumei
Hobbyist Programmer
 
Join Date: Oct 2005
Posts: 134
Rep Power: 4 Kaja Fumei is on a distinguished road
There should a semicolon after your call to mail()
Kaja Fumei is offline   Reply With Quote
Old Apr 23rd, 2006, 6:10 AM   #5
piercy
Programmer
 
Join Date: Apr 2006
Posts: 35
Rep Power: 0 piercy is on a distinguished road
okay thanks guys but i now have an error in a different line im told there error is on the middle line but i know that somtimes the surrounding code can affect it so i will paste that to.

mysql_select_db(test) ;
$result = "INSERT INTO messages ('first name' , 'last name' , 'email address' , 'date' , 'message') VALUES ('$fname' , '$lname' , '$email' , '$date' , '$msg'") ;
mysql_query($result) ;

thanks once again
piercy
piercy is offline   Reply With Quote
Old Apr 23rd, 2006, 9:38 AM   #6
piercy
Programmer
 
Join Date: Apr 2006
Posts: 35
Rep Power: 0 piercy is on a distinguished road
erm sorry again guys count the above post out because im using yet another coding to do it. i would really like to get thiis one sorted out.
$fname = $_POST["first"];
$sname = $_POST["last"];
$email = $_POST["email"];
$msg = $_POST["message"];
$date = date('l dS F Y at h:i:s A');



mail('pierm002@suttonlea.org', 'html form to email' , "From: \t $fname $sname \n email address: \t $email \nsent:\t $date \n \n \n \t $msg");
$db="test";
$link = mysql_connect("localhost","guest","password");
if (! $link)
die("unable to send message please try again.");
mysql_select_db($db , $link) or die("Select Error: ".mysql_error());

$resulst = mysql_query("INSERT INTO messages (first name,last name,email address,date,message) VALUES ('$fname','$lname','$email','$date','$msg')") or die("insert error: ".mysql_error());
mysql_close($link);
print "Message sent";

when i run the script it says
Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2) in /Users/mike/sites/tutorial/emailsend.php on line 14

line 14 being $link = mysql_connect("localhost","guest","password");

i cant see whats wrong with it :cry:
piercy is offline   Reply With Quote
Old Apr 23rd, 2006, 10:13 AM   #7
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
As it says, it can't connect to the local MySQL server. Something's broken server end. If you're hosting this yourself, see if you can access MySQL directly using the command-line client. If not, contact your host and find out what's going on.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Apr 23rd, 2006, 10:22 AM   #8
piercy
Programmer
 
Join Date: Apr 2006
Posts: 35
Rep Power: 0 piercy is on a distinguished road
Cool

erm im hosting myself and im using a visual aid called navicat to arrange the database because learning php is hard enough for me as it is without having to memorize command line codes. navicat connects to the database table and lets me add information if i want. so im not sure what that means now...

Last edited by piercy; Apr 23rd, 2006 at 10:38 AM.
piercy is offline   Reply With Quote
Old Apr 23rd, 2006, 10:41 AM   #9
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Are you using the superuser to run navicat?
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Apr 23rd, 2006, 11:06 AM   #10
piercy
Programmer
 
Join Date: Apr 2006
Posts: 35
Rep Power: 0 piercy is on a distinguished road
erm im not sure what you mean by using superuser to run it. navicat is an application which i open on my normal login. when connecting to the database it uses the username root and no password.

Last edited by piercy; Apr 23rd, 2006 at 11:18 AM.
piercy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:06 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC