misdanzigfits
New member
I am trying to create a form that a user can fill out and some of the fields are optional. I just can't figure out the best way to do this.
My Code:
<?php
if(count($_POST) > 0) {
$image_title = $_FILES['image']['name'];
$image_temp = $_FILES['image']['tmp_name'];
$title = $_POST['title'];
$month = $_POST['month'];
$day = $_POST['day'];
$year = $_POST['year'];
$link = $_POST['link'];
$link_name = $_POST['link_name'];
$content = $_POST['content'];
$image_upload = '../uploads/';
if(move_uploaded_file($image_temp, $image_upload.$image_title)) {
//Connect To Database
mysql_connect('server', 'user', 'pwd');
mysql_select_db('dbName');
$sql = "INSERT INTO ggNews ";
$sql .= "SET image='$image_title', title='$title', month='$month', day='$day', year='$year', link='$link', link_name='$link_name', content='$content' ";
if(mysql_query($sql)) {
header("location: index.php");
}
else {
die(mysql_error());
}
}
}
?>
I want the $image, $link, and $link_url to all be optional and the rest to be required.
I have a basic form for the html.
My Code:
<?php
if(count($_POST) > 0) {
$image_title = $_FILES['image']['name'];
$image_temp = $_FILES['image']['tmp_name'];
$title = $_POST['title'];
$month = $_POST['month'];
$day = $_POST['day'];
$year = $_POST['year'];
$link = $_POST['link'];
$link_name = $_POST['link_name'];
$content = $_POST['content'];
$image_upload = '../uploads/';
if(move_uploaded_file($image_temp, $image_upload.$image_title)) {
//Connect To Database
mysql_connect('server', 'user', 'pwd');
mysql_select_db('dbName');
$sql = "INSERT INTO ggNews ";
$sql .= "SET image='$image_title', title='$title', month='$month', day='$day', year='$year', link='$link', link_name='$link_name', content='$content' ";
if(mysql_query($sql)) {
header("location: index.php");
}
else {
die(mysql_error());
}
}
}
?>
I want the $image, $link, and $link_url to all be optional and the rest to be required.
I have a basic form for the html.