I'm working on a insert form for my movie database and I have some code working and will be adding more to it, but I wanted to know if there was a better way to go about doing some of this or if I have made a huge coding error. I'm still learning php and haven't gotten that far into my studies of php yet, but I know this code works at the moment. So I would appreciate any feedback.
Thanks for the help.
form:
<html>
<head>
<title>Form Input Data</title>
</head>
<body>
<table border="1">
<tr>
<td align="center">Form Input Data</td>
</tr>
<tr>
<td>
<table>
<form method="post" action="VER2.php">
<tr>
<td>Code</td>
<td><input type="text" name="Code" size="10">
</td>
</tr>
<tr>
<td>Title</td>
<td><input type="text" name="Title" size="128">
</td>
</tr>
<tr>
<td>Alt_Title</td>
<td><input type="text" name="Alt_Title" size="128">
</td>
</tr>
<tr>
<td>Type</td>
<td><input type="text" name="Type" size="10">
</td>
</tr>
<tr>
<td>Synopis</td>
<td><input type="text" name="Synopis" size="128">
</td>
</tr>
<tr>
<td>Num_Eps</td>
<td><input type="int" name="Num_Eps" size="12">
</td>
</tr>
<tr>
<td>Duration</td>
<td><input type="time" name="Duration" size="">
</td>
</tr>
<tr>
<td>Total_Duration</td>
<td><input type="time" name="Total_Duration" size="">
</td>
</tr>
<tr>
<td>Catagory</td>
<td><input type="text" name="Catagory" size="25">
</td>
</tr>
<tr>
<td>Year</td>
<td><input type="year" name="Year" size="4">
</td>
</tr>
<input type="checkbox" name="GenCode[]" value="Action"> Action <br />
<input type="checkbox" name="GenCode[]" value="Comedy"> Comedy <br />
<input type="checkbox" name="GenCode[]" value="Adven"> Adventure <br />
<tr>
<td></td>
<td align="right"><input type="submit"
name="submit" value="Sent"></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
insert:
<?php
mysql_connect("localhost","root","root");//database connection
mysql_select_db("test");
$Code = $_GET['Code'];
//inserting data order
$order = "INSERT INTO MOVIES
(Code, Title, Alt_Title, Type, Synopsis, Num_Eps, Duration, Total_Duration, Catagory, Year)
VALUES
('" .addslashes( $_POST['Code'] ). "',
'" .addslashes( $_POST['Title'] )."',
'" .addslashes( $_POST['Alt_Title'] )."',
'" .addslashes( $_POST['Type'] )."',
'" .addslashes( $_POST['Synopsis'] )."',
'" .addslashes( $_POST['Num_Eps'] )."',
'" .addslashes( $_POST['Duration'] )."',
'" .addslashes( $_POST['Total_Duration'] )."',
'" .addslashes( $_POST['Catagory'] )."',
'" .addslashes( $_POST['Year'] )."')";
//declare in the order variable
echo "order: $order";
$result = mysql_query($order); //order executes
if($result){
echo("<br>Input data is succeed");
} else{
echo("<br>Input data is fail");
}
mysql_close($mysql_connect);
$con = mysql_connect("localhost","root","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test");
$Code = $_GET['Code'];
if(isset($_POST['GenCode']))
{
foreach($_POST['GenCode'] as $value) {
$insert="INSERT INTO MOVIEGENRES (MovieCode, GenCode) VALUES ('" .addslashes( $_POST['Code'] ). "','$value')";
mysql_query($insert);
}
echo $insert;
echo " ";
}
mysql_close($con);
?>