Jump to content

Function Error


minus84

Recommended Posts

Hi guys

 

im fairly new to php and im following a tutorial on youtube about how to set up a comminuity website, im using WAMP. i am trying to create a php page that creates a table in MySQL but i keep gettin the the error messages

 

Warning: mysql_query() [function.mysql-query]: Access denied for user 'SYSTEM'@'localhost' (using password: NO) in C:\wamp\www\scripts\create_Table.php on line 34

 

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\wamp\www\scripts\create_Table.php on line 34

 

i have set up a password on my localhost so i have no idea why this is happening can someone please explain to me what settings i need to change

 

thnx

Link to comment
Share on other sites

The error means that at the time or place in your code where you executed the mysql_query() statement, you did not have a valid connection to the mysql server.

 

You would need to troubleshoot why your code did not have a mysql connection at that time or place in your code.

 

If you want someone on a forum to help find the problem, you would need to post your actual code.

Link to comment
Share on other sites

it connects the database fine so i dont know y there would be an error

 

<?php

 

include_once"connect_to_mysql.php";

//Tell myself on screen that we have connected succesfully

print"success in database CONNECTION....<br/>";

//creates the members main table in your new database

$result = "CREATE TABLE myMemberstest(

id int(11)NOT NULL auto_increment,

firstname varchar(255)NOT NULL,

middlename varchar(255)NULL,

lastname varchar(255)NOT NULL,

country varchar(255)NOT NULL,

city varchar(255)NOT NULL,

county varchar(255)NOT NULL,

postcode varchar(255)NOT NULL,

phone varchar(255)NOT NULL,

email varchar(255)NOT NULL,

password varchar(255)NOT NULL,

sign_up_date date NOT NULL default '0000-00-00',

last_log_date NOT NULL default '0000-00-00',

bio_body text NULL,

website varchar(255) NULL,

youtube varchar(255) NULL,

account_type enum('a','b','c') NOT NULL default 'a',

email_activated enum('0','1') NOT NULL default '0',

PRIMARY KEY(id),

UNIQUE KEY email(email)

)";

if(mysql_query($result)){

print"success in TABLE creation!....

<br/><br/><b>That compleates the table setup, now delete the file <br/>

named'create_Table.php'and you are ready to move on Let us go</b>";

 

} else {

print"no TABLE created, You have problems in the system already back track and try again";

}

exit();

 

?>

Link to comment
Share on other sites

it connects the database fine

 

No it's not, or you would not be getting that error message.

 

Just because you have an include_once() statement that is supposed to cause your connection code to be executed, does not mean that it did.

 

What's your code in connect_to_mysql.php, because it is relevant to the problem as well.  xxxxx out any connection details, but otherwise post the while content of the file, including the opening php tag.

Link to comment
Share on other sites

<?php 

$db_host = "localhost";

// Place the username for the MySQL database here

$db_username = "root"; 

// Place the password for the MySQL database here

$db_pass = "xxxxxxxxxxxx"; 

// Place the name for the MySQL database here

$db_name = "communityDB";

 

@mysql_connect("$db_host","$db_username","$db_pass", "$db_name") or die ("could not connect to mysql");

?>

 

i double checked the code and added the last line u see there @mysql_connect, there are no longer any error messages, but the code will still will not create the tables in MySQL

Link to comment
Share on other sites

<?php 

// Place db host name. Sometimes "localhost" but 

// sometimes looks like this: >>      ???mysql??.someserver.net

$db_host = "localhost";

// Place the username for the MySQL database here

$db_username = "root"; 

// Place the password for the MySQL database here

$db_pass = "XXXXXXXXXXXXX"; 

// Place the name for the MySQL database here

//$db_name = "communityDB";

 

// Run the connection here 

@mysql_connect("$db_host","$db_username","$db_pass", "$db_name") or die ("could not connect to mysql"); 

@mysql_select_db("$communityDB") or die ("No Database");

?>

 

its styll being a pain,i have added the select_ db, what should i put in db name then?

Link to comment
Share on other sites

When posting code please use code tags.

 

Your code should look something like this:

 

@mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mysql");  
@mysql_select_db("$db_name") or die ("No Database");

 

1. You need to remove the database name from the 4th parameter of mysql_connect and 2. The variable that holds your database name that you want to pass to mysql_select_db is $db_name not $communityDB.

Link to comment
Share on other sites

yeah ok thanksfor your help ive got it working now, im not sure y but i needed to change it to an include function but it did not work with require_once

 

aswel as changing the db_name

 

for future reference how do i enclose in php code like that is it <html > then close < html />

Link to comment
Share on other sites

<html> 
<title>testing inserting php as code - do not reply</title> 
<body> 
<?php 
print "<h1>Congratulations, your server can process PHP!</h1>"; 
print "<h3>Here you can view the PHP configuration on your server</h3>"; 
phpinfo( ); 
exit(); 
?> 
<html/>
[code/]

Link to comment
Share on other sites

<?php 
session_start();
include_once"scripts/connect_to_mysql.php";

//build main navigation menu and gather page data here
$sql ="SELECT id, linklabel FROM pages ORDER BY pageorder ASC";
$query = mysql_query($sql) or die (mysqli_error());

$menuDisplay ="";
while($row= mysql_fetch_array($query)) {
	$pid = $row["id"];
	$linklabel = $row["linklabel"];

	$menuDisplay ='<a href="phpcustom.php?pid=' . $pid . '">' . $linklabel . '</a><br/>';
}		
mysql_result($query);
//mysqli_close($myConnection);

?>

 

my while loop doesnt seem to b working any idea why,

 

im also using dreamweaver 8 and mysqli function dont highlight or workin in my database where as mysql does is there any reason for this

Link to comment
Share on other sites

Instead of overwriting $menuDisplay every loop append to it:

 

$menuDisplay .= '<a href="phpcustom.php?pid=' . $pid . '">' . $linklabel . '</a><br/>';

 

Then after the loop echo it.

Link to comment
Share on other sites

keep getting the error message

 

Notice: Undefined index: pid in C:\wamp\www\phpcustom.php on line 6

 

not sure why

 

<?php 
session_start();
include_once"scripts/connect_to_mysql.php";

//query for body and determing which page id to use in our query below
if(!$_GET['pid']){
$pageid ='1';
} else {
$pageid = $_GET['pid'];
}
//query for the section coverd in body
$sql ="SELECT pagebody FROM pages WHERE id='$pageid' LIMIT 1";

$query = mysql_query($sql) or die (mysqli_error());
while($row= mysql_fetch_array($query)) {
	$body = $row["pagebody"];
}

mysql_free_result($query);

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.