Linny
Junior Member
Posts: 263
inherit
115575
0
Jul 30, 2012 13:11:24 GMT -8
Linny
263
December 2007
linny58
|
Post by Linny on Sept 30, 2009 8:14:52 GMT -8
This must be the 3rd time I have posted a PHP to SQL connection error, but I need help again, sorry Ok so I'm using this script to send data from my form to my SQL DB. The form is sending the information through here to the DB but as you can see I am receiving this error. Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host '(mikewhis_play).mysql.aplus.net' (3) in /home/mikewhis/public_html/formindb.php on line 2 Could not connect: Unknown MySQL server host '(mikewhis_play).mysql.aplus.net' (3)The red is where I think the error is but I don't know what to replace it with. My PHP script <?php $con = mysql_connect("(mikewhis_play).mysql.aplus.net","mikewhis_play","MY PASS"); //Replace with your actual MySQL DB Username and Password if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mikewhis_play", $con); //Replace with your MySQL DB Name $consoles=mysql_real_escape_string($_POST['consoles']); //This value has to be the same as in the HTML form file $usernames=mysql_real_escape_string($_POST['usernames']); //This value has to be the same as in the HTML form file $name=mysql_real_escape_string($_POST['name']); //This value has to be the same as in the HTML form file $email=mysql_real_escape_string($_POST['email']); //This value has to be the same as in the HTML form file $timezone=mysql_real_escape_string($_POST['timezone']); //This value has to be the same as in the HTML form file $sql="INSERT INTO users (consoles,usernames,name,email,time zone) VALUES ('$consoles','$usernames','$name','email','time zone')"; /*form_data is the name of the MySQL table where the form data will be saved. name and email are the respective table fields*/ if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "The form data was successfully added to your database."; mysql_close($con); ?>
Thank you.
|
|
inherit
100824
0
May 13, 2012 5:37:49 GMT -8
Michael
14,585
March 2007
wrighty
|
Post by Michael on Sept 30, 2009 9:04:10 GMT -8
the first attribute in the mysql_connect function should be localhost really! =/
|
|
Linny
Junior Member
Posts: 263
inherit
115575
0
Jul 30, 2012 13:11:24 GMT -8
Linny
263
December 2007
linny58
|
Post by Linny on Sept 30, 2009 9:16:31 GMT -8
Thanks for that Wrighty, now I get this error -
Parse error: syntax error, unexpected T_STRING in /home/mikewhis/public_html/formindb.php on line 2
Could this be the "
<?php $con = mysql_connect("("localhost").mysql.aplus.net","mikewhis_play","MY PASS");
<?php $con = mysql_connect("("localhost").mysql.aplus.net","mikewhis_play","MY PASS"); //Replace with your actual MySQL DB Username and Password if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mikewhis_play", $con); //Replace with your MySQL DB Name $consoles=mysql_real_escape_string($_POST['consoles']); //This value has to be the same as in the HTML form file $usernames=mysql_real_escape_string($_POST['usernames']); //This value has to be the same as in the HTML form file $name=mysql_real_escape_string($_POST['name']); //This value has to be the same as in the HTML form file $email=mysql_real_escape_string($_POST['email']); //This value has to be the same as in the HTML form file $timezone=mysql_real_escape_string($_POST['timezone']); //This value has to be the same as in the HTML form file $sql="INSERT INTO users (consoles,usernames,name,email,time zone) VALUES ('$consoles','$usernames','$name','email','time zone')"; /*form_data is the name of the MySQL table where the form data will be saved. name and email are the respective table fields*/ if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "The form data was successfully added to your database."; mysql_close($con); ?>
|
|
inherit
17569
0
Aug 14, 2023 13:11:03 GMT -8
frufru
11,774
December 2003
frufru
|
Post by frufru on Sept 30, 2009 11:23:22 GMT -8
Thanks for that Wrighty, now I get this error - Parse error: syntax error, unexpected T_STRING in /home/mikewhis/public_html/formindb.php on line 2
Could this be the "<?php $con = mysql_connect( "("localhost").mysql.aplus.net","mikewhis_play","MY PASS"); <?php $con = mysql_connect("("localhost").mysql.aplus.net","mikewhis_play","MY PASS"); //Replace with your actual MySQL DB Username and Password if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mikewhis_play", $con); //Replace with your MySQL DB Name $consoles=mysql_real_escape_string($_POST['consoles']); //This value has to be the same as in the HTML form file $usernames=mysql_real_escape_string($_POST['usernames']); //This value has to be the same as in the HTML form file $name=mysql_real_escape_string($_POST['name']); //This value has to be the same as in the HTML form file $email=mysql_real_escape_string($_POST['email']); //This value has to be the same as in the HTML form file $timezone=mysql_real_escape_string($_POST['timezone']); //This value has to be the same as in the HTML form file $sql="INSERT INTO users (consoles,usernames,name,email,time zone) VALUES ('$consoles','$usernames','$name','email','time zone')"; /*form_data is the name of the MySQL table where the form data will be saved. name and email are the respective table fields*/ if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "The form data was successfully added to your database."; mysql_close($con); ?>
I don't think having double-quotations within each other without some sort of escape is ever good . And I think Wrighty meant $con = mysql_connect(" localhost","mikewhis_play","MY PASS"); The thing is, that assumes your database is on the same server as your pages. If it isn't, the server name is usually somewhere in your hosting account control panel (i.e. where you set up the database from)
|
|
Linny
Junior Member
Posts: 263
inherit
115575
0
Jul 30, 2012 13:11:24 GMT -8
Linny
263
December 2007
linny58
|
Post by Linny on Sept 30, 2009 11:46:37 GMT -8
Oh, I understand That has cleared that error, just one more error now, Parse error: syntax error, unexpected T_STRING in /home/mikewhis/public_html/formindb.php on line 12
If you could spot what the error is, that would help! Line 12; $time zone=mysql_real_escape_string($_POST['time zone']); //This value has to be the same as in the HTML form fileI'll check the to see if the form names are the same.
|
|
inherit
17569
0
Aug 14, 2023 13:11:03 GMT -8
frufru
11,774
December 2003
frufru
|
Post by frufru on Sept 30, 2009 13:04:17 GMT -8
Oh, I understand That has cleared that error, just one more error now, Parse error: syntax error, unexpected T_STRING in /home/mikewhis/public_html/formindb.php on line 12
If you could spot what the error is, that would help! Line 12; $time zone=mysql_real_escape_string($_POST['time zone']); //This value has to be the same as in the HTML form fileI'll check the to see if the form names are the same. Not sure if it's the source of the error, but there seems to be an inconsistency between using the name 'timezone' and 'time zone' in here and in the form itself. Might want to use 'timezone' in all spots, especially in your next line with the query where inserting into a field that contains a space looks kind of questionable to me.
|
|
Linny
Junior Member
Posts: 263
inherit
115575
0
Jul 30, 2012 13:11:24 GMT -8
Linny
263
December 2007
linny58
|
Post by Linny on Sept 30, 2009 13:22:41 GMT -8
Yay! It now works Thanks for that, I'm going to properly learn PHP so I don't have to come onto here every time. Once again, thank you
|
|