!!!!! Posted June 8, 2007 Share Posted June 8, 2007 Okay, so, I have done this: mysql_connect("localhost","---myUsername---","---myPassword---"); And yet, it won't let me connect and gives me errors. I don't think it's my username or password that is messing this up, I think it might be the localhost part. I don't know which port to use, or what to put there. So, I would appreciate it if somebody could tell me how to find out what to put, or what to put. Also, I am using PHPMyAdmin, so if this does not work with mysql queries then please tell me and I will try to figure out how to download a new MySQL database. Thanks, Zach Link to comment https://forums.phpfreaks.com/topic/54828-mysql-connect-not-working/ Share on other sites More sharing options...
per1os Posted June 9, 2007 Share Posted June 9, 2007 What are the errors, what server are you using? Also are you using mysql_select_db("databasename"); to connect to the database. Link to comment https://forums.phpfreaks.com/topic/54828-mysql-connect-not-working/#findComment-271192 Share on other sites More sharing options...
!!!!! Posted June 9, 2007 Author Share Posted June 9, 2007 What are the errors, what server are you using? Also are you using mysql_select_db("databasename"); to connect to the database. <html> <body> <?php $con = mysql_connect(); if(!$con) { die('Could not connect: '. mysql_error()); } if(mysql_query("CREATE DATABASE dudes",$con) { echo "Database created."; } else { echo "Error creating database: ". mysql_error(); } mysql_select_db("dudes",$con); $sql = "CREATE TABLE person ( firstname varchar(25); lastname varchar(25); age int; )"; mysql_query("INSERT INTO person(firstname,lastname,age) VALUES('$_POST[firstname]', '$_POST[lastname]', '$_POST[age]'); echo "New person added."; mysql_query($sql,$con); mysql_close($con); </body> </html> Link to comment https://forums.phpfreaks.com/topic/54828-mysql-connect-not-working/#findComment-271193 Share on other sites More sharing options...
flappy_warbucks Posted June 9, 2007 Share Posted June 9, 2007 <html> <body> <?php $host = "Your Host"; $user = "Your User Name"; $pass = "your passoword"; $con = mysql_connect($host,$user,$pass); if(!$con) { die('Could not connect: '. mysql_error()); } if(mysql_query("CREATE DATABASE dudes",$con) { echo "Database created."; } else { echo "Error creating database: ". mysql_error(); } mysql_select_db("dudes",$con); $sql = "CREATE TABLE person ( firstname varchar(25); lastname varchar(25); age int; )"; mysql_query("INSERT INTO person(firstname,lastname,age) VALUES('$_POST[firstname]', '$_POST[lastname]', '$_POST[age]'); echo "New person added."; mysql_query($sql,$con); mysql_close($con); </body> </html> should do it (providing you have the MYSQL extension set up on your PHP Install ) Link to comment https://forums.phpfreaks.com/topic/54828-mysql-connect-not-working/#findComment-271195 Share on other sites More sharing options...
!!!!! Posted June 9, 2007 Author Share Posted June 9, 2007 <html> <body> <?php $host = "Your Host"; $user = "Your User Name"; $pass = "your passoword"; $con = mysql_connect($host,$user,$pass); if(!$con) { die('Could not connect: '. mysql_error()); } if(mysql_query("CREATE DATABASE dudes",$con) { echo "Database created."; } else { echo "Error creating database: ". mysql_error(); } mysql_select_db("dudes",$con); $sql = "CREATE TABLE person ( firstname varchar(25); lastname varchar(25); age int; )"; mysql_query("INSERT INTO person(firstname,lastname,age) VALUES('$_POST[firstname]', '$_POST[lastname]', '$_POST[age]'); echo "New person added."; mysql_query($sql,$con); mysql_close($con); </body> </html> should do it (providing you have the MYSQL extension set up on your PHP Install ) Parse error: parse error, unexpected '{' in /home/neomoonc/public_html/mysql.php on line 14 Mmm... Proving tougher than I thought lol. Thanks for trying, anymore help please? ? Link to comment https://forums.phpfreaks.com/topic/54828-mysql-connect-not-working/#findComment-271197 Share on other sites More sharing options...
flappy_warbucks Posted June 9, 2007 Share Posted June 9, 2007 <html> <body> <?php $host = "Your Host"; $user = "Your User Name"; $pass = "your passoword"; $con = mysql_connect($host,$user,$pass); if(!$con) { die('Could not connect: '. mysql_error()); } if(mysql_query("CREATE DATABASE dudes",$con)) { echo "Database created."; } else { echo "Error creating database: ". mysql_error(); } you missed out a ")" on your second "if" statement... that shoudl work now Link to comment https://forums.phpfreaks.com/topic/54828-mysql-connect-not-working/#findComment-271199 Share on other sites More sharing options...
!!!!! Posted June 9, 2007 Author Share Posted June 9, 2007 <html> <body> <?php $host = "Your Host"; $user = "Your User Name"; $pass = "your passoword"; $con = mysql_connect($host,$user,$pass); if(!$con) { die('Could not connect: '. mysql_error()); } if(mysql_query("CREATE DATABASE dudes",$con)) { echo "Database created."; } else { echo "Error creating database: ". mysql_error(); } you missed out a ")" on your second "if" statement... that shoudl work now Sorry bout this... I already fixed that. Saw that a minute ago. Is there anything else you could think of that might be wrong? Link to comment https://forums.phpfreaks.com/topic/54828-mysql-connect-not-working/#findComment-271201 Share on other sites More sharing options...
per1os Posted June 9, 2007 Share Posted June 9, 2007 What are the errors, what server are you using? Also are you using mysql_select_db("databasename"); to connect to the database. <html> <body> <?php $con = mysql_connect(); if(!$con) { die('Could not connect: '. mysql_error()); } if(mysql_query("CREATE DATABASE dudes",$con) { echo "Database created."; } else { echo "Error creating database: ". mysql_error(); } mysql_select_db("dudes",$con); $sql = "CREATE TABLE person ( firstname varchar(25); lastname varchar(25); age int; )"; mysql_query("INSERT INTO person(firstname,lastname,age) VALUES('$_POST[firstname]', '$_POST[lastname]', '$_POST[age]'); echo "New person added."; mysql_query($sql,$con); mysql_close($con); </body> </html> Yes what are the errors? I failed to see them in that post. Link to comment https://forums.phpfreaks.com/topic/54828-mysql-connect-not-working/#findComment-271214 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.