Jump to content

MySQL connect not working


!!!!!

Recommended Posts

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

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>

<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 :))

<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? :)?

<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

<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?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.