Alright here we go.
My mysql database “records” table looks like this.
id
Author_id
Title
Category_id
City
Province
Country
Path
Created(Date)
Note that from all the above fields, i was only able to make the id, Title and Category_id work. As well I have done resize image and upload to database path before in different session, so i know that’ll work.
So I need help with the rest.
Functions.php
[php]function get_cat() {
$data = mysql_query(“SELECT * FROM categories”);
while($cat = mysql_fetch_array($data)) {
echo ‘’ .$cat[‘Title’] . ‘’;
}
}
function add_record($title, $category, $user_id) {
$user_id = (int)$user_id;
$title = $_POST[‘title’];
$category = $_POST[‘category’];
$query = mysql_query("INSERT INTO records VALUES(null, '$user_id', '$title', '$category', '', '', '', '', '')");
}[/php]
add.php
[php]<?php
include “core/init.php”;
ob_start();
include “includes/overall/header.php”;
if (empty($_POST) === false) {
$required_fields = array(‘title’, ‘category’, ‘country’, ‘province’, ‘city’);
foreach($_POST as $key=>$value) {
if (empty($value) && in_array($key, $required_fields) === true) {
$errors[] = 'Please fill in all fields.';
break 1;
}
}
if (empty($errors) === true) {
if (!isset($_POST['title']) === true) {
$errors[] = 'Please enter a title.';
}
if (!isset($_POST['category']) === true) {
$errors[] = 'Please select a category.';
}
if (!isset($_POST['city']) === true) {
$errors[] = 'Please select a city.';
}
if (!isset($_POST['province']) === true) {
$errors[] = 'Please select a province.';
}
}
}
?>
<?php
if(isset($_GET['success']) === true && empty($_GET['success']) === true) {
echo "Your record has been uploaded.";
} else {
if (empty($_POST) === false && empty($errors) === true) {
add_record($title, $category, $user_id);
header('Location: add.php?success');
exit();
} else if (empty($errors) === false) {
echo output_errors($errors);
}
?>
<form action="" method="post" enctype="multipart/form-data">
<ul>
<li>
Record Title:<br>
<input type="text" name="title" >
</li>
<li>
Select Category:<br>
<select name='category' id="category" >
<?php get_cat(); ?>
</select>
</li><br>
<li>
<select name='country' id="country" >
<option>Canada</option>
</select><br>
<!-- The first select list -->
<select name="province" id="province" onchange="SList.getSelect('city', this.value);">
<option value="select_province">Select Province</option>
<option value="Alberta">Alberta</option>
<option value="British Columbia">British Columbia</option>
<option value="Manitoba">Manitoba</option>
<option value="New Brunswick">New Brunswick</option>
<option value="Newfoundland">Newfoundland</option>
<option value="Northwest Territories">Northwest Territories</option>
<option value="Nova Scotia">Nova Scotia</option>
<option value="Nunavut">Nunavut</option>
<option value="Ontario">Ontario</option>
<option value="Prince Edward Island">Prince Edward Island</option>
<option value="Quebec">Quebec</option>
<option value="Saskatchewan">Saskatchewan</option>
<option value="Yukon">Yukon</option>
</select><br>
<!-- Tag for the second dropdown list-->
<span id="city"></span><br>
</li>
<li>
Upload image:<br>
<input type="file" name="image" >
</li><br>
<li>
<input type="submit" name="submit" value="Add Deal" >
</li>
</ul>
</form>
<?php
}
include “includes/overall/footer.php”; ?>[/php]
Btw, I know I’m using old Mysql that is depreciated. Truth is, it’s been a great ice breaker. I will switch over to Mysqli or PDO after i am done with this project.