www.webdeveloper.com
Results 1 to 4 of 4

Thread: php create mysql table

Hybrid View

  1. #1
    Join Date
    Mar 2013
    Location
    Winnipeg, Canada
    Posts
    12

    php create mysql table

    Not sure what I am doing wrong here but when I create a mysql table the table is created but when I enter the information into the fields and it populates the table it is skipping records. It will create a table with IDs of 1 then 3 then 5 then 7 and so on. Here is the code I am using to create my table:

    <?php include ("db_connect.php"); ?>
    <?php
    //select the database in which to add a table
    mysql_select_db("final_exam_db",$con);
    $sql = "CREATE TABLE tablename
    (id int NOT NULL AUTO_INCREMENT,
    PRIMARY KEY(id),
    fn varchar(15),
    ln varchar(15),
    month varchar(9),
    day int,
    year int,
    photo varchar(30),
    email varchar(40)
    )";
    mysql_query($sql,$con);
    echo mysql_error();
    ?>
    <?php include ("db_close.php"); ?>

    Thank you in advance.

  2. #2
    Join Date
    Mar 2013
    Location
    Winnipeg, Canada
    Posts
    12

    Addition to question regarding mysql table and php

    I have something to add to my question above. It might not be in creating the table but in populating the table with my php code. Attached is my code that I am using to upload my information. Please take a look and let me know where I went wrong and why my database has so many extra records.

    <?php include("db_connect.php");?>
    <?php // select the database in which to add a table
    mysql_select_db("final_exam_db",$con);



    $sql ="INSERT INTO drivers_0115061 (ln,fn,month,day,year,name,email)
    VALUES ('".$_POST["ln"]."',
    '".$_POST["fn"]."',
    '".$_POST["month"]."',
    '".$_POST["day"]."',
    '".$_POST["year"]."',
    '".$_POST['file']['name']."',
    '".$_POST["email"]."'
    )";

    mysql_query($sql, $con);
    echo mysql_error();
    ?>


    <?php include("image_upload.php");?>

    <?php include("db_close.php");?>

    Thank you in advance.

  3. #3
    Join Date
    Mar 2013
    Location
    Iasi, Romania
    Posts
    53
    First of all, use trim($_POST[]) and that variable $_POST['file']['name'] is not correct.
    If your input field is called "file name", change it to "file_name" and get it with $_POST['file_name'].

  4. #4
    Join Date
    Mar 2013
    Location
    Winnipeg, Canada
    Posts
    12
    Where do I use the trim($_POST[])

    The variable $_POST['file']['name'] is supposed to be for the person's image. 'file' is for the image upload and 'name' was supposed to upload the image name in database. I am able to upload the image to the folder but I can't get the image name to upload to the database.

    Here is the code I used to create the table. The example I had put above had a mistake:

    (id int NOT NULL AUTO_INCREMENT,
    PRIMARY KEY(id),
    fn varchar(15),
    ln varchar(15),
    month varchar(9),
    day int,
    year int,
    photo varchar(30),
    email varchar(40)
    )";
    mysql_query($sql,$con);
    echo mysql_error();
    ?>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles