![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Apr 2006
Posts: 35
Rep Power: 0
![]() |
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 3:12 PM. Reason: didnt read the rules thread so thought i would do it properly (code) |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
You're missing a semicolon. :p
Please, use [code] tags next time. |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Apr 2006
Posts: 35
Rep Power: 0
![]() |
okay i edited it into code tags and where are the semicolons missing. i kinda new to this.
thanks again piercy |
|
|
|
|
|
#4 |
|
Hobbyist Programmer
Join Date: Oct 2005
Posts: 134
Rep Power: 3
![]() |
There should a semicolon after your call to mail()
|
|
|
|
|
|
#5 |
|
Programmer
Join Date: Apr 2006
Posts: 35
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#6 |
|
Programmer
Join Date: Apr 2006
Posts: 35
Rep Power: 0
![]() |
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: |
|
|
|
|
|
#7 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
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.
|
|
|
|
|
|
#8 |
|
Programmer
Join Date: Apr 2006
Posts: 35
Rep Power: 0
![]() |
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 9:38 AM. |
|
|
|
|
|
#9 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Are you using the superuser to run navicat?
|
|
|
|
|
|
#10 |
|
Programmer
Join Date: Apr 2006
Posts: 35
Rep Power: 0
![]() |
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 10:18 AM. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|