Trouble in accessing the database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rodeoval
    New Member
    • May 2007
    • 15

    Trouble in accessing the database

    hi!
    I'm completely new to PHP and MySQL and I am using WAMP 5.This is something I extracted from a web tutorial. Although it is to create a table called students in a database named College it does not create one.
    Can someone pls show me where I have gone wrong in the following codings?
    [code=php]
    <?
    $username="root ";
    $password="";
    $database="Coll ege";

    $name=$_POST['name'];
    $dob=$_POST['dob'];


    mysql_connect(l ocalhost,$usern ame,$password);
    @mysql_select_d b($database) or die( "Unable to select database");


    if (mysql_is_table ('localhost', $username, $password, $database, 'Students')) {
    $query="CREATE TABLE Students (index int(6) NOT NULL auto_increment, Name varchar(20) NOT NULL,DoB varchar(15) NOT NULL)";
    } else {
    $query = "INSERT INTO Students VALUES ('','$name','$d ob')";
    }

    mysql_query($qu ery);

    mysql_close();
    ?>[/code]

    [Please use CODE tags when posting source code. Thanks! --pbmods]
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    Do you get back any error messages?

    Originally posted by rodeoval
    hi!
    I'm completely new to PHP and MySQL and I am using WAMP 5.This is something I extracted from a web tutorial. Although it is to create a table called students in a database named College it does not create one.
    Can someone pls show me where I have gone wrong in the following codings?

    <?
    $username="root ";
    $password="";
    $database="Coll ege";

    $name=$_POST['name'];
    $dob=$_POST['dob'];


    mysql_connect(l ocalhost,$usern ame,$password);
    @mysql_select_d b($database) or die( "Unable to select database");


    if (mysql_is_table ('localhost', $username, $password, $database, 'Students')) {
    $query="CREATE TABLE Students (index int(6) NOT NULL auto_increment, Name varchar(20) NOT NULL,DoB varchar(15) NOT NULL)";
    } else {
    $query = "INSERT INTO Students VALUES ('','$name','$d ob')";
    }

    mysql_query($qu ery);

    mysql_close();
    ?>

    Comment

    • rodeoval
      New Member
      • May 2007
      • 15

      #3
      Originally posted by Motoma
      Do you get back any error messages?
      Hi!,
      I could fix it. Thanx!
      Now I have some more problems.
      1) Is there a way like u enter the name of the table that u need to create in the dbase to a textbox and when u submit it, a table with that name is created in the dbase?

      2)U create an HTML form with a table and in one column of it, u have text boxes to enter data.After entering data to those text boxes when u submit it data must be added to a particular table in the db?

      Comment

      • Motoma
        Recognized Expert Specialist
        • Jan 2007
        • 3236

        #4
        Originally posted by rodeoval
        Hi!,
        I could fix it. Thanx!
        Now I have some more problems.
        1) Is there a way like u enter the name of the table that u need to create in the dbase to a textbox and when u submit it, a table with that name is created in the dbase?

        2)U create an HTML form with a table and in one column of it, u have text boxes to enter data.After entering data to those text boxes when u submit it data must be added to a particular table in the db?
        Take a look at this article written by yours truly.

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          Originally posted by rodeoval
          1) Is there a way like u enter the name of the table that u need to create in the dbase to a textbox and when u submit it, a table with that name is created in the dbase?

          2)U create an HTML form with a table and in one column of it, u have text boxes to enter data.After entering data to those text boxes when u submit it data must be added to a particular table in the db?
          You mean like phpMyAdmin?

          Comment

          • ak1dnar
            Recognized Expert Top Contributor
            • Jan 2007
            • 1584

            #6
            Originally posted by rodeoval
            Now I have some more problems.
            1) Is there a way like u enter the name of the table that u need to create in the dbase to a textbox and when u submit it, a table with that name is created in the dbase?

            2)U create an HTML form with a table and in one column of it, u have text boxes to enter data.After entering data to those text boxes when u submit it data must be added to a particular table in the db?
            If it not phpmyadmin, and it is your own script.
            try to send the values from a form to the $result then you can make it.
            Try over here

            Comment

            • rodeoval
              New Member
              • May 2007
              • 15

              #7
              Well,This is another problem I am having.
              I am doing a web application using PHP/MySQL and Dreamweaver.I ve created a database and some tables in it.But when I pass data to a table through a form(using POST method), the actual data does not go to the table.Say I entered the data 5 times.Then it indicates that 5 rows are there,but it does not show the actual data that I entered....Ny guesses y it happens..Someho w I feel like the problem is in the connection of database(I m not sure though)..I will be really glad if someone can help me.

              Comment

              • Motoma
                Recognized Expert Specialist
                • Jan 2007
                • 3236

                #8
                Originally posted by rodeoval
                Well,This is another problem I am having.
                I am doing a web application using PHP/MySQL and Dreamweaver.I ve created a database and some tables in it.But when I pass data to a table through a form(using POST method), the actual data does not go to the table.Say I entered the data 5 times.Then it indicates that 5 rows are there,but it does not show the actual data that I entered....Ny guesses y it happens..Someho w I feel like the problem is in the connection of database(I m not sure though)..I will be really glad if someone can help me.
                Perhaps you could post the relevant code, and list any error messages you are getting.

                Comment

                Working...