Connect to the mysql already?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Krista

    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>Cr eate 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.<b r>");
    }
    else
    {
    print("The connection to the server failed.<br>");
    }


    mysql_close($_G ET['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(Employ eeID 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($_G ET['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

    #2
    Re: Connect to the mysql already?

    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($re sultID) 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($li nkID);
    ?>
    </body>
    </html>

    "Krista" <ywan_ip@hotmai l.com> wrote in message
    news:eb97c972.0 312171532.3e585 a58@posting.goo gle.com...[color=blue]
    > 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>Cr eate 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.<b r>");
    > }
    > else
    > {
    > print("The connection to the server failed.<br>");
    > }
    >
    >
    > mysql_close($_G ET['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(Employ eeID 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($_G ET['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[/color]


    Comment

    • Tom

      #3
      Re: Connect to the mysql already?

      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($re sultID) or die("Create table Error: ". mysql_error()
      );


      if ($table) {
      echo "The table $TableName was successfully created";
      }







      "Tom" <lynchtf@nospam hotmail.com> wrote in message
      news:59iEb.4622 $Fg.4394@lakere ad01...[color=blue]
      > 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[/color]
      access[color=blue]
      > 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($re sultID) or die("Create table Error: ".[/color]
      mysql_error()[color=blue]
      > );
      >
      > #if table was created, echo a message to the screen
      > if ($resultID) {
      > echo "The table $TableName was successfully created";
      > }
      >
      > mysql_close($li nkID);
      > ?>
      > </body>
      > </html>
      >
      > "Krista" <ywan_ip@hotmai l.com> wrote in message
      > news:eb97c972.0 312171532.3e585 a58@posting.goo gle.com...[color=green]
      > > 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>Cr eate 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.<b r>");
      > > }
      > > else
      > > {
      > > print("The connection to the server failed.<br>");
      > > }
      > >
      > >
      > > mysql_close($_G ET['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(Employ eeID 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($_G ET['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[/color]
      >
      >[/color]


      Comment

      • Krista

        #4
        Re: Connect to the mysql already?

        "Tom" <lynchtf@nospam hotmail.com> wrote in message news:<59iEb.462 2$Fg.4394@laker ead01>...[color=blue]
        > 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[/color]
        [color=blue]
        > Unless you're passing variables through a form or a url, why not just access
        > the variables directly?
        >[/color]
        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 />";

        [color=blue]
        > 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($re sultID) 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($li nkID);
        > ?>
        > </body>
        > </html>
        >[/color]

        When i try your code as above, I still cannot get the result. The IE
        seems keeping load the php file.Cannot get it.
        [color=blue]
        > "Krista" <ywan_ip@hotmai l.com> wrote in message
        > news:eb97c972.0 312171532.3e585 a58@posting.goo gle.com...[color=green]
        > > 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>Cr eate 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.<b r>");
        > > }
        > > else
        > > {
        > > print("The connection to the server failed.<br>");
        > > }
        > >
        > >
        > > mysql_close($_G ET['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(Employ eeID 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($_G ET['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[/color][/color]

        Comment

        Working...