|
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 | |
Share:
|
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 | | |
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
| | |
"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 | | This discussion thread is closed Replies have been disabled for this discussion. Similar topics
20 posts
views
Thread by Mr Dygi |
last post: by
|
7 posts
views
Thread by atlasyeo |
last post: by
|
reply
views
Thread by Mark Adams |
last post: by
|
4 posts
views
Thread by Denis Labon |
last post: by
|
1 post
views
Thread by jiing |
last post: by
|
5 posts
views
Thread by Shelly |
last post: by
|
3 posts
views
Thread by pc |
last post: by
| | | | | | | | | | | | |