minus84 Posted July 30, 2010 Share Posted July 30, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/209300-function-error/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 30, 2010 Share Posted July 30, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/209300-function-error/#findComment-1092885 Share on other sites More sharing options...
minus84 Posted July 30, 2010 Author Share Posted July 30, 2010 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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/209300-function-error/#findComment-1092890 Share on other sites More sharing options...
PFMaBiSmAd Posted July 30, 2010 Share Posted July 30, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/209300-function-error/#findComment-1092895 Share on other sites More sharing options...
minus84 Posted July 30, 2010 Author Share Posted July 30, 2010 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/209300-function-error/#findComment-1092908 Share on other sites More sharing options...
PFMaBiSmAd Posted July 30, 2010 Share Posted July 30, 2010 The 4th parameter of mysql_connect() is NOT the database name. You must have a separate mysql_select_db() function call or specify the database name in your query along with the table name. Quote Link to comment https://forums.phpfreaks.com/topic/209300-function-error/#findComment-1092909 Share on other sites More sharing options...
minus84 Posted July 30, 2010 Author Share Posted July 30, 2010 <?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? Quote Link to comment https://forums.phpfreaks.com/topic/209300-function-error/#findComment-1092916 Share on other sites More sharing options...
Alex Posted July 30, 2010 Share Posted July 30, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/209300-function-error/#findComment-1092921 Share on other sites More sharing options...
minus84 Posted July 30, 2010 Author Share Posted July 30, 2010 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 /> Quote Link to comment https://forums.phpfreaks.com/topic/209300-function-error/#findComment-1093038 Share on other sites More sharing options...
minus84 Posted July 30, 2010 Author Share Posted July 30, 2010 <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/] Quote Link to comment https://forums.phpfreaks.com/topic/209300-function-error/#findComment-1093160 Share on other sites More sharing options...
TOA Posted July 30, 2010 Share Posted July 30, 2010 <html/> Notice something wrong here?? Quote Link to comment https://forums.phpfreaks.com/topic/209300-function-error/#findComment-1093167 Share on other sites More sharing options...
minus84 Posted July 30, 2010 Author Share Posted July 30, 2010 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/209300-function-error/#findComment-1093247 Share on other sites More sharing options...
Alex Posted July 30, 2010 Share Posted July 30, 2010 What do you mean "not working"? What do you expect it to do? All you're doing is overwriting $menuDisplay every loop. Quote Link to comment https://forums.phpfreaks.com/topic/209300-function-error/#findComment-1093252 Share on other sites More sharing options...
minus84 Posted July 30, 2010 Author Share Posted July 30, 2010 i want it to render different rows of information from a mysql database in ascending order but its only bringing out the one, do you know another way to loop it Quote Link to comment https://forums.phpfreaks.com/topic/209300-function-error/#findComment-1093254 Share on other sites More sharing options...
Alex Posted July 30, 2010 Share Posted July 30, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/209300-function-error/#findComment-1093255 Share on other sites More sharing options...
minus84 Posted July 30, 2010 Author Share Posted July 30, 2010 works beautofully, nice one Quote Link to comment https://forums.phpfreaks.com/topic/209300-function-error/#findComment-1093258 Share on other sites More sharing options...
minus84 Posted August 2, 2010 Author Share Posted August 2, 2010 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); Quote Link to comment https://forums.phpfreaks.com/topic/209300-function-error/#findComment-1094031 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.