472,990 Members | 2,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,990 software developers and data experts.

Connect to the mysql already?

Hi,
Hope you guys can help me out~~ I have a config.php file. I want to
conncet to my own mysql version. When i run the config.php file as
below, i get all successful message. However, when i take a look the
database information in doc environment, I don't see any database or
table created.

<html>
<head><title>Create Database and table</title></head>
<body>
<?php

//connect to the database, write, and execute the query
$linkID = mysql_connect("localhost", "", "") or die ('I cannot connect
to the
database because: ' . mysql_error());

if (!$_GET['linkID'])

{
print("The connection to the server was made successfully.<br>");
}
else
{
print("The connection to the server failed.<br>");
}
mysql_close($_GET['linkID']);

$DBName="Krista";
$TableName = "Employee";

//connect to the database, write, and execute the query
$Link = mysql_connect("localhost","","");

mysql_select_db("Krista", $_GET['Link']);

$resultID = mysql_query ("CREATE table Employee(EmployeeID INT
UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
Employee_Name TEXT",$_GET['Link']);

if(!$_GET['resultID']){
print("The query was successfully executed!<BR>\n");
}
else{
print("The query could not be executed!<BR>\n");
}

mysql_close($_GET['Link']);

?>
</body>
</html>

In addition, i change the global_register to on. However, I still need
to use $_GET['username'] like this. I want to use $username instead of
$_GET['xxx'].

Thanks,
Krista
Jul 17 '05 #1
3 3065
Tom
Not sure why you're:
* passing variables through GET when you're declaring them within your
script
* making and closing two connections to create one table

Unless you're passing variables through a form or a url, why not just access
the variables directly?

Therefore:
$linkID = mysql_connect("localhost", "", "") or die ('I cannot connect to
the database because: ' . mysql_error() );

if ($linkID) {
echo "The connection to the server was made successfully<br />";
}

$DBName="Krista";
$TableName = "Employee";

# create a database if one doesn't exist
mysql_create_db($DBName);
#select the database you just created
mysql_select_db($DBName);

#design your query
$resultID = "CREATE TABLE Employee(
EmployeeID int unsigned auto_increment not null,
Employee_Name text,
PRIMARY KEY(EmployeeID) )";

#run the query
$table = mysql_query($resultID) or die("Create table Error: ". mysql_error()
);

#if table was created, echo a message to the screen
if ($resultID) {
echo "The table $TableName was successfully created";
}

mysql_close($linkID);
?>
</body>
</html>

"Krista" <yw*****@hotmail.com> wrote in message
news:eb**************************@posting.google.c om...
Hi,
Hope you guys can help me out~~ I have a config.php file. I want to
conncet to my own mysql version. When i run the config.php file as
below, i get all successful message. However, when i take a look the
database information in doc environment, I don't see any database or
table created.

<html>
<head><title>Create Database and table</title></head>
<body>
<?php

//connect to the database, write, and execute the query
$linkID = mysql_connect("localhost", "", "") or die ('I cannot connect
to the
database because: ' . mysql_error());

if (!$_GET['linkID'])

{
print("The connection to the server was made successfully.<br>");
}
else
{
print("The connection to the server failed.<br>");
}
mysql_close($_GET['linkID']);

$DBName="Krista";
$TableName = "Employee";

//connect to the database, write, and execute the query
$Link = mysql_connect("localhost","","");

mysql_select_db("Krista", $_GET['Link']);

$resultID = mysql_query ("CREATE table Employee(EmployeeID INT
UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
Employee_Name TEXT",$_GET['Link']);

if(!$_GET['resultID']){
print("The query was successfully executed!<BR>\n");
}
else{
print("The query could not be executed!<BR>\n");
}

mysql_close($_GET['Link']);

?>
</body>
</html>

In addition, i change the global_register to on. However, I still need
to use $_GET['username'] like this. I want to use $username instead of
$_GET['xxx'].

Thanks,
Krista

Jul 17 '05 #2
Tom
Whoa, I was a little too quick on the submit key. The amended code should
read as follows:

$resultID = "CREATE TABLE $TableName(
EmployeeID int unsigned auto_increment not null,
Employee_Name text,
PRIMARY KEY(EmployeeID) )";

$table = mysql_query($resultID) or die("Create table Error: ". mysql_error()
);
if ($table) {
echo "The table $TableName was successfully created";
}



"Tom" <ly*****@nospamhotmail.com> wrote in message
news:59iEb.4622$Fg.4394@lakeread01...
Not sure why you're:
* passing variables through GET when you're declaring them within your
script
* making and closing two connections to create one table

Unless you're passing variables through a form or a url, why not just access the variables directly?

Therefore:
$linkID = mysql_connect("localhost", "", "") or die ('I cannot connect to
the database because: ' . mysql_error() );

if ($linkID) {
echo "The connection to the server was made successfully<br />";
}

$DBName="Krista";
$TableName = "Employee";

# create a database if one doesn't exist
mysql_create_db($DBName);
#select the database you just created
mysql_select_db($DBName);

#design your query
$resultID = "CREATE TABLE Employee(
EmployeeID int unsigned auto_increment not null,
Employee_Name text,
PRIMARY KEY(EmployeeID) )";

#run the query
$table = mysql_query($resultID) or die("Create table Error: ". mysql_error() );

#if table was created, echo a message to the screen
if ($resultID) {
echo "The table $TableName was successfully created";
}

mysql_close($linkID);
?>
</body>
</html>

"Krista" <yw*****@hotmail.com> wrote in message
news:eb**************************@posting.google.c om...
Hi,
Hope you guys can help me out~~ I have a config.php file. I want to
conncet to my own mysql version. When i run the config.php file as
below, i get all successful message. However, when i take a look the
database information in doc environment, I don't see any database or
table created.

<html>
<head><title>Create Database and table</title></head>
<body>
<?php

//connect to the database, write, and execute the query
$linkID = mysql_connect("localhost", "", "") or die ('I cannot connect
to the
database because: ' . mysql_error());

if (!$_GET['linkID'])

{
print("The connection to the server was made successfully.<br>");
}
else
{
print("The connection to the server failed.<br>");
}
mysql_close($_GET['linkID']);

$DBName="Krista";
$TableName = "Employee";

//connect to the database, write, and execute the query
$Link = mysql_connect("localhost","","");

mysql_select_db("Krista", $_GET['Link']);

$resultID = mysql_query ("CREATE table Employee(EmployeeID INT
UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
Employee_Name TEXT",$_GET['Link']);

if(!$_GET['resultID']){
print("The query was successfully executed!<BR>\n");
}
else{
print("The query could not be executed!<BR>\n");
}

mysql_close($_GET['Link']);

?>
</body>
</html>

In addition, i change the global_register to on. However, I still need
to use $_GET['username'] like this. I want to use $username instead of
$_GET['xxx'].

Thanks,
Krista


Jul 17 '05 #3
"Tom" <ly*****@nospamhotmail.com> wrote in message news:<59iEb.4622$Fg.4394@lakeread01>...
Not sure why you're:
* passing variables through GET when you're declaring them within your
script
* making and closing two connections to create one table Unless you're passing variables through a form or a url, why not just access
the variables directly?
You are right, I want to access the variables directly. However, when
i work as ur code in the following, I cannot display server was made
successfully.
If i do ($_GET['linkID']), i can show the successful message. is it my
config has problem, so i can access the varible directly? But the
global_register is on already. I dont know what is the problem

if ($linkID) {
echo "The connection to the server was made successfully<br />";

Therefore:
$linkID = mysql_connect("localhost", "", "") or die ('I cannot connect to
the database because: ' . mysql_error() );

if ($linkID) {
echo "The connection to the server was made successfully<br />";
}

$DBName="Krista";
$TableName = "Employee";

# create a database if one doesn't exist
mysql_create_db($DBName);
#select the database you just created
mysql_select_db($DBName);

#design your query
$resultID = "CREATE TABLE Employee(
EmployeeID int unsigned auto_increment not null,
Employee_Name text,
PRIMARY KEY(EmployeeID) )";

#run the query
$table = mysql_query($resultID) or die("Create table Error: ". mysql_error()
);

#if table was created, echo a message to the screen
if ($resultID) {
echo "The table $TableName was successfully created";
}

mysql_close($linkID);
?>
</body>
</html>

When i try your code as above, I still cannot get the result. The IE
seems keeping load the php file.Cannot get it.
"Krista" <yw*****@hotmail.com> wrote in message
news:eb**************************@posting.google.c om...
Hi,
Hope you guys can help me out~~ I have a config.php file. I want to
conncet to my own mysql version. When i run the config.php file as
below, i get all successful message. However, when i take a look the
database information in doc environment, I don't see any database or
table created.

<html>
<head><title>Create Database and table</title></head>
<body>
<?php

//connect to the database, write, and execute the query
$linkID = mysql_connect("localhost", "", "") or die ('I cannot connect
to the
database because: ' . mysql_error());

if (!$_GET['linkID'])

{
print("The connection to the server was made successfully.<br>");
}
else
{
print("The connection to the server failed.<br>");
}
mysql_close($_GET['linkID']);

$DBName="Krista";
$TableName = "Employee";

//connect to the database, write, and execute the query
$Link = mysql_connect("localhost","","");

mysql_select_db("Krista", $_GET['Link']);

$resultID = mysql_query ("CREATE table Employee(EmployeeID INT
UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
Employee_Name TEXT",$_GET['Link']);

if(!$_GET['resultID']){
print("The query was successfully executed!<BR>\n");
}
else{
print("The query could not be executed!<BR>\n");
}

mysql_close($_GET['Link']);

?>
</body>
</html>

In addition, i change the global_register to on. However, I still need
to use $_GET['username'] like this. I want to use $username instead of
$_GET['xxx'].

Thanks,
Krista

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Mr Dygi | last post by:
Hi, PHP 4.3.4 installed manually from package *.zip and Apache 2. I have a problem with this simple code: <?php $link = mysql_connect("127.0.0.1","","") or die("Could not connect: " ....
7
by: atlasyeo | last post by:
Hi, my first time posting on a newsgroup. anyway, let's cut to the chase. I'm trying to migrate mysql database form one server to another server. So I copied the data from /var/lib/mysql to the...
0
by: Mark Adams | last post by:
I really need some help with this. MySQL will not start on boot despite everything I've done to make sure that it is set to do so. When I start it as root from a terminal with...
4
by: Denis Labon | last post by:
I can't connect to mysql server using the mysql-connector-java-3.0.11. I was able to run the same program when I was running Suse 9.0 but since I install Suse 9.1, I can't connect. The error...
1
by: jiing | last post by:
Now let me describe what I have done and my purpose: Originally, I want to user ports to install phpBB But I found that phpBB doesn't support mysql 5.x (but the ports installed mySQL 5.0.0...
5
by: Shelly | last post by:
(also posted to alt.php.sql and comp.databases.mysql) This is an old problem. I extensively researched the postings on the internet and have found no solution. So, perhaps someone here can...
3
by: pc | last post by:
hi everyone, I am trying to connect to a new mysql installation. I have given root permission to connect to all databases from anywhere; GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY...
6
by: markodilore | last post by:
Hey Guys, you helped me once when I tryied to create a database : "Access denied for user ''@'localhost' ". On my Mac OS 10.4, I had no problem creating database and modifying it from the terminal....
2
by: swarajtnj | last post by:
Hi Friends, I am using MySql 5.0. With the Front end as ASP.NET 2.0. I am working a small concern. my company local server to connect the MySql is perfectly working. But when i Connect to the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.