NULL and empty space
| From: | Craig Hoffman | Date: | Sun, 22 Aug 2004 14:59:50 +0000 |
| Subject: | NULL and empty space | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-35836@lists.php.net to get a copy of this message | ||
I have an form where someone can choose to upload a photo. If the person does not upload a photo, an emtpy string is inserted in the DB. How can I have it insert 'NULL' in the DB instead of an empty string when they choose NOT to upload a photo but complete the form anyway?
Any help is appreciated!
Much Thanks -- CH
Here is my code and query if it helps:
if($_POST["postback_upload"])
{
include "include/db.php";
//image uploader
$uploadpath = 'images/climbs/';
$source = $_FILES['photo']['tmp_name'];
$route_photo = $_FILES['photo']['name'];
$dest == '';
if (($source != 'none') && ($source != '')) {
$dest = $uploadpath.$route_photo;
if ($dest != '') {
if (move_uploaded_file($source, $dest)) {
echo ("<h2>Image and Climbing log has been successfully stored.</h2> ");
} else {
echo ("<h2>Image could not be stored.<h2>");
}
}
} else {
echo ("<h2>No new image supplied. Climbing long has been successfully stored.<h2>");
}
//photo uploader - make "route_photo" a varible for MySQL to work -- need to find out why.
$query = "INSERT INTO routes(user_id , date_climbed , route , pitchs , rating, area, outcrop, type, style, private_comments, public_comments, stars, route_photo)
VALUES('NULL', '$_POST[date_climbed]', '$_POST[route]', '$_POST[pitchs]', '$_POST[rating]',
'$_POST[area]', '$_POST[outcrop]', '$_POST[type]', '$_POST[style]', '$_POST[private_comments]','$_POST[public_comments]','$_POST[stars]', '$route_photo')";
echo $query;
$msg = "<span style='color:red'>Could not insert record</span>";
$result = mysql_query($query,$db) or die(mysql_error());