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"); ?>
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);
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'].
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();
?>
Bookmarks