Ignoring an emtpy field

How can I make this sql statement ignore the variable strImage if it is empty so that it won't overwrite what is in the db with an empty value?

$SQL = mysql_query("UPDATE tblAdspace SET "
       . "strProviderservice = '" . $strProviderservice . "', "
     . "strCompanyname='" . $strCompanyname . "', "
     . "strOwner='" . $strOwner . "', "
       . "strAddress='" . $strAddress . "', "
     . "strTown='" . $strTown . "', "
       . "strZipcode='" . $strZipcode . "', "
       . "strPhone='" . $strPhone . "', "
     . "str2ndphone='" . $str2ndphone . "', "
     . "strMobile='" . $strMobile . "', "
     . "strPager='" . $strPager . "', "
     . "strFax='" . $strFax . "', "
     . "strEmail='" . $strEmail . "', "
     . "strWebsite='" . $strWebsite . "', "
     . "strLicense='" . $strLicense . "', "
     . "strInsured='" . $strInsured . "', "
     . "strBonded='" . $strBonded . "', "
     . "strHours='" . $strHours . "', "
     . "str24houremerg='" . $str24houremerg . "', "
     . "strOtherservices='" . $strOtherservices . "', "
     . "strServicearea='" . $strServicearea . "', "
     . "strInbusiness_since='" . $strInbusiness_since . "', "
     . "strServicesoffered='" . $strServicesoffered . "', "
       . "strFreeestimate='" . $strFreeestimate . "', "
     . "strWorkguaranteed='" . $strWorkguaranteed . "', "
       . "strProvidertagline='" . $strProvidertagline . "', "
     . "strAd_size='" . $strAd_size . "', "
       . "strImage='" . $target_path . "'"
     . " WHERE strCompanyname = '" . $strCompanyname . "'");
LVL 1
pingeyegAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

steelseth12Commented:
$SQL = mysql_query("UPDATE tblAdspace SET "
       . "strProviderservice = '" . $strProviderservice . "', "
     . "strCompanyname='" . $strCompanyname . "', "
     . "strOwner='" . $strOwner . "', "
       . "strAddress='" . $strAddress . "', "
     . "strTown='" . $strTown . "', "
       . "strZipcode='" . $strZipcode . "', "
       . "strPhone='" . $strPhone . "', "
     . "str2ndphone='" . $str2ndphone . "', "
     . "strMobile='" . $strMobile . "', "
     . "strPager='" . $strPager . "', "
     . "strFax='" . $strFax . "', "
     . "strEmail='" . $strEmail . "', "
     . "strWebsite='" . $strWebsite . "', "
     . "strLicense='" . $strLicense . "', "
     . "strInsured='" . $strInsured . "', "
     . "strBonded='" . $strBonded . "', "
     . "strHours='" . $strHours . "', "
     . "str24houremerg='" . $str24houremerg . "', "
     . "strOtherservices='" . $strOtherservices . "', "
     . "strServicearea='" . $strServicearea . "', "
     . "strInbusiness_since='" . $strInbusiness_since . "', "
     . "strServicesoffered='" . $strServicesoffered . "', "
       . "strFreeestimate='" . $strFreeestimate . "', "
     . "strWorkguaranteed='" . $strWorkguaranteed . "', "
       . "strProvidertagline='" . $strProvidertagline . "', "
     . "strAd_size='" . $strAd_size . "', "
       . "strImage='" . (isset($target_path)?$target_path:"") . "'"
     . " WHERE strCompanyname = '" . $strCompanyname . "'");
0
gamebitsCommented:
Since this is an update statement you must be pulling the information from the db in the first place (probably in a form to edit the values and then resubmit to the updating script).

What I'm getting at, is the field strImage should not be empty to start with when you resubmit or if it is  then you do not replace anything with a empty value.
0
pingeyegAuthor Commented:
steelseth12, that didn't work.  It still overwrote the image name in the db.
0
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

pingeyegAuthor Commented:
gamebits, the field strImage is a button that imports your image from your hdd and then inserts it into your database.  Well, when you already have one in the db, and I don't select another image, but I do make a change to the provider, the strImage field gets overwritten will a blank value.  I want to ignore that field if it is empty.
0
gamebitsCommented:
To make the changes you must have form, is it not?
0
pingeyegAuthor Commented:
Correct,

<tr><td align="right">
Select Custom Ad:
</td><td>
<input type="file" name="strImage">
</td></tr>
0
gamebitsCommented:
I don't kow how your application is set up but when I write a  application and I have to edit information in the db
I have a form who will pull all the information from the db, all the field are being displayed in the form, the ones that can be edited are displayed in a textbox (if applicable), the ones that cannot be edited (don't want them to be editable, like order numbers etc.) are displayed as regular text BUT they do have a hidden field to reinsert the info into the db upon submitting the update.

The other way around is to have only the fields you want to edit to be listed in your update statement

$SQL = mysql_query("UPDATE tblAdspace SET "
. "strZipcode='" . $strZipcode . "', "
 . " WHERE strCompanyname = '" . $strCompanyname . "'");


this would only change the zipcode in the db for this company nothing else would be touch, so if you know you will not change the strImage you can safely remove it from the list but if you ever have to change it this would not work.

0
pingeyegAuthor Commented:
Yea, see that's not what I want to have happen.  What I want is if the field is empty, because the user didn't select an image from their computer, for the UPDATE statement to not look at it and keep on truckin.  If there is a value in that field then I want the UPDATE statement to take action on that field.  Does that make since?
0
gamebitsCommented:
Since updating an image involve uploading the image to the server and inserting the path in the db, I think the easiest way to do so would be to have a separate form to do that, one form to update all the text field and one form to change the picture.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pingeyegAuthor Commented:
So then I would have to have two different action pages.
0
gamebitsCommented:
No you could have both on the same action page using a switch statement, let me know if you need an example.
0
pingeyegAuthor Commented:
I did what you said, but right now when I try to insert an image i get a blank page:

<?php
if ($_GET['text'] == "text") {

if ($_SERVER['REQUEST_METHOD'] == "POST") {

$conn = mysql_connect("127.0.0.1", "", "");
mysql_select_db("providers", $conn)
or die(mysql_error());

$strProviderservice = $_POST['strProviderservice'];
$strCompanyname = $_POST['strCompanyname'];
$strOwner = $_POST['strOwner'];
$strAddress = $_POST['strAddress'];
$strTown = $_POST['strTown'];
$strZipcode = $_POST['strZipcode'];
$strPhone = $_POST['strPhone'];
$str2ndphone = $_POST['str2ndphone'];
$strMobile = $_POST['strMobile'];
$strPager = $_POST['strPager'];
$strFax = $_POST['strFax'];
$strEmail = $_POST['strEmail'];
$strWebsite = $_POST['strWebsite'];
$strInbusiness_since = $_POST['strInbusiness_since'];
$strLicense = $_POST['strLicense'];
$strInsured = $_POST['strInsured'];
$strBonded = $_POST['strBonded'];
$strHours = $_POST['strHours'];
$str24houremerg = $_POST['str24houremerg'];
$strServicesoffered = $_POST['strServicesoffered'];
$strOtherservices = $_POST['strOtherservices'];
$strServicearea = $_POST['strServicearea'];
$strFreeestimate = $_POST['strFreeestimate'];
$strWorkguaranteed = $_POST['strWorkguaranteed'];
$strProvidertagline = $_POST['strProvidertagline'];
$strAd_size = $_POST['strAd_size'];

addslashes($strOtherservices);
addslashes($strServicesoffered);
addslashes($strProvidertagline);

$SQL = mysql_query("SELECT * FROM tblAdspace where strCompanyname = '" .$strCompanyname. "'")
or die(mysql_error());

if ($row = mysql_fetch_array($SQL)) {

$SQL = mysql_query("UPDATE tblAdspace SET "
       . "strProviderservice = '" . $strProviderservice . "', "
     . "strCompanyname='" . $strCompanyname . "', "
     . "strOwner='" . $strOwner . "', "
       . "strAddress='" . $strAddress . "', "
     . "strTown='" . $strTown . "', "
       . "strZipcode='" . $strZipcode . "', "
       . "strPhone='" . $strPhone . "', "
     . "str2ndphone='" . $str2ndphone . "', "
     . "strMobile='" . $strMobile . "', "
     . "strPager='" . $strPager . "', "
     . "strFax='" . $strFax . "', "
     . "strEmail='" . $strEmail . "', "
     . "strWebsite='" . $strWebsite . "', "
     . "strLicense='" . $strLicense . "', "
     . "strInsured='" . $strInsured . "', "
     . "strBonded='" . $strBonded . "', "
     . "strHours='" . $strHours . "', "
     . "str24houremerg='" . $str24houremerg . "', "
     . "strOtherservices='" . $strOtherservices . "', "
     . "strServicearea='" . $strServicearea . "', "
     . "strInbusiness_since='" . $strInbusiness_since . "', "
     . "strServicesoffered='" . $strServicesoffered . "', "
       . "strFreeestimate='" . $strFreeestimate . "', "
     . "strWorkguaranteed='" . $strWorkguaranteed . "', "
       . "strProvidertagline='" . $strProvidertagline . "', "
     . "strAd_size='" . $strAd_size . "'"
     . " WHERE strCompanyname = '" . $strCompanyname . "'");
                    
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n".
"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n".
"<head>\n".
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\" />\n".
"<title>Ask2bsure.com - (Admin Section) Edit Provider</title>\n".
"<link style=\"text/css\" href=\"/css/style.css\" rel=\"stylesheet\">\n".
"</head>\n".
"<body>\n".
"<table align=\"center\" id=\"admin\">\n".
"<tr><td align=\"center\" colspan=\"2\">\n".
"<img src=\"/images/sublogo_2.png\"><br />\n".
"<span style=\"font-size: 12px; color: #0000FF\">(Admin Section)</span>\n".
"</td></tr>\n".
"<tr><td valign=\"top\">\n".
"<div id=\"navlist\">\n".
"<a href=\"/admin/\">Home</a>\n".
"<a href=\"/admin/add_provider.php\">Add Provider</a>\n".
"<a href=\"/admin/list_providers.php?list=list\">Delete / Edit Provider</a>\n".
"<a href=\"/admin/list_providers.php?review=review\">Toggle / Edit Reviews</a>\n".
"<a href=\"/index.php\">Back To Website</a>\n".
"</div>\n".
"</td><td width=\"625\">\n".
"<table id=\"main_admin\" align=\"center\" border=\"0\">\n".
"<tr><td align=\"center\">\n".
"The selected provider has now been updated.\n".
"</td></tr>\n".
"</table>\n".
"</td></tr>\n".
"</table>\n".
"</body>\n".
"</html>";

} else {
    $SQL = mysql_query("INSERT INTO tblAdspace
(strProviderservice, strCompanyname, strOwner, strAddress, strTown, strZipcode, strPhone, str2ndphone, strMobile, strPager, strFax, strEmail, strWebsite, strLicense, strBonded, strHours, str24houremerg, strServicesoffered, strOtherservices, strServicearea, strFreeestimate, strWorkguaranteed, strProvidertagline, strAd_size, strImage)
VALUES
('$strProviderservice', '$strCompanyname', '$strOwner', '$strAddress', '$strTown', '$strZipcode', '$strPhone', '$str2ndphone', '$strMobile', '$strPager', '$strFax, $strEmail', '$strWebsite', '$strLicense', '$strBonded', '$strHours', '$str24houremerg', '$strServicesoffered', '$strOtherservices', '$strServicearea', '$strFreeestimate', '$strWorkguaranteed', '$strProvidertagline', '$strAd_size', 'strImage')")
or die ("Could not insert values into DB tblAdspace: " . mysql_error());

echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n".
"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n".
"<head>\n".
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\" />\n".
"<title>Ask2bsure.com - (Admin Section) Edit Provider</title>\n".
"<link style=\"text/css\" href=\"/css/style.css\" rel=\"stylesheet\">\n".
"</head>\n".
"<body>\n".
"<table align=\"center\" id=\"admin\">\n".
"<tr><td align=\"center\" colspan=\"2\">\n".
"<img src=\"/images/sublogo_2.png\"><br />\n".
"<span style=\"font-size: 12px; color: #0000FF\">(Admin Section)</span>\n".
"</td></tr>\n".
"<tr><td valign=\"top\">\n".
"<div id=\"navlist\">\n".
"<a href=\"/admin/\">Home</a>\n".
"<a href=\"/admin/add_provider.php\">Add Provider</a>\n".
"<a href=\"/admin/list_providers.php?list=list\">Delete / Edit Provider</a>\n".
"<a href=\"/admin/list_providers.php?review=review\">Toggle / Edit Reviews</a>\n".
"<a href=\"/index.php\">Back To Website</a>\n".
"</div>\n".
"</td><td width=\"625\">\n".
"<table id=\"main_admin\" align=\"center\" border=\"0\">\n".
"<tr><td align=\"center\">\n".
"The selected provider has now been updated.\n".
"</td></tr>\n".
"</table>\n".
"</td></tr>\n".
"</table>\n".
"</body>\n".
"</html>";

}
}

} elseif ($_GET['image'] == "image") {

if ($_SERVER['REQUEST_METHOD'] == "POST") {

$conn = mysql_connect("127.0.0.1", "", "");
mysql_select_db("providers", $conn)
or die(mysql_error());

$target_path = "/Library/WebServer/Documents/images/";
$target_path = basename( $_FILES['strImage']['name']);
$filename = basename($_FILES['strImage']['name']);
$_FILES['strImage']['$filename'];
move_uploaded_file($_FILES['strImage']['$filename'], $target_path);

$SQL = mysql_query("SELECT strImage FROM tblAdspace where strCompanyname = '" .$strCompanyname. "'")
or die(mysql_error());

if ($row = mysql_fetch_array($SQL)) {

$SQL = mysql_query("UPDATE tblAdspace SET strImage='" . $target_path . "' WHERE strCompanyname = '" . $strCompanyname . "'");

echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n".
"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n".
"<head>\n".
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\" />\n".
"<title>Ask2bsure.com - (Admin Section) Edit Provider</title>\n".
"<link style=\"text/css\" href=\"/css/style.css\" rel=\"stylesheet\">\n".
"</head>\n".
"<body>\n".
"<table align=\"center\" id=\"admin\">\n".
"<tr><td align=\"center\" colspan=\"2\">\n".
"<img src=\"/images/sublogo_2.png\"><br />\n".
"<span style=\"font-size: 12px; color: #0000FF\">(Admin Section)</span>\n".
"</td></tr>\n".
"<tr><td valign=\"top\">\n".
"<div id=\"navlist\">\n".
"<a href=\"/admin/\">Home</a>\n".
"<a href=\"/admin/add_provider.php\">Add Provider</a>\n".
"<a href=\"/admin/list_providers.php?list=list\">Delete / Edit Provider</a>\n".
"<a href=\"/admin/list_providers.php?review=review\">Toggle / Edit Reviews</a>\n".
"<a href=\"/index.php\">Back To Website</a>\n".
"</div>\n".
"</td><td width=\"625\">\n".
"<table id=\"main_admin\" align=\"center\" border=\"0\">\n".
"<tr><td align=\"center\">\n".
"The selected provider has now been updated.\n".
"</td></tr>\n".
"</table>\n".
"</td></tr>\n".
"</table>\n".
"</body>\n".
"</html>";
}
}
}
?>      
0
pingeyegAuthor Commented:
Ok, I added the insert query as well, but now when I try to insert the image only the variable gets uploaded instead of the name of the image.

} elseif ($_GET['image'] == "image") {

if ($_SERVER['REQUEST_METHOD'] == "POST") {

$conn = mysql_connect("127.0.0.1", "", "");
mysql_select_db("providers", $conn)
or die(mysql_error());

$target_path = "/Library/WebServer/Documents/images/";
$target_path = basename( $_FILES['strImage']['name']);
$filename = basename($_FILES['strImage']['name']);
$_FILES['strImage']['$filename'];
move_uploaded_file($_FILES['strImage']['$filename'], $target_path);

$SQL = mysql_query("SELECT strImage FROM tblAdspace where strCompanyname = '" .$strCompanyname. "'")
or die(mysql_error());

if ($row = mysql_fetch_array($SQL)) {

$SQL = mysql_query("UPDATE tblAdspace SET strImage='" . $target_path . "' WHERE strCompanyname = '" . $strCompanyname . "'");

echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n".
"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n".
"<head>\n".
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\" />\n".
"<title>Ask2bsure.com - (Admin Section) Edit Provider</title>\n".
"<link style=\"text/css\" href=\"/css/style.css\" rel=\"stylesheet\">\n".
"</head>\n".
"<body>\n".
"<table align=\"center\" id=\"admin\">\n".
"<tr><td align=\"center\" colspan=\"2\">\n".
"<img src=\"/images/sublogo_2.png\"><br />\n".
"<span style=\"font-size: 12px; color: #0000FF\">(Admin Section)</span>\n".
"</td></tr>\n".
"<tr><td valign=\"top\">\n".
"<div id=\"navlist\">\n".
"<a href=\"/admin/\">Home</a>\n".
"<a href=\"/admin/add_provider.php\">Add Provider</a>\n".
"<a href=\"/admin/list_providers.php?list=list\">Delete / Edit Provider</a>\n".
"<a href=\"/admin/list_providers.php?review=review\">Toggle / Edit Reviews</a>\n".
"<a href=\"/index.php\">Back To Website</a>\n".
"</div>\n".
"</td><td width=\"625\">\n".
"<table id=\"main_admin\" align=\"center\" border=\"0\">\n".
"<tr><td align=\"center\">\n".
"The selected provider has now been updated.\n".
"</td></tr>\n".
"</table>\n".
"</td></tr>\n".
"</table>\n".
"</body>\n".
"</html>";

} else {

$SQL = mysql_query("INSERT INTO tblAdspace (strImage) VALUES ('strImage')")
or die (mysql_error());

echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n".
"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n".
"<head>\n".
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\" />\n".
"<title>Ask2bsure.com - (Admin Section) Edit Provider</title>\n".
"<link style=\"text/css\" href=\"/css/style.css\" rel=\"stylesheet\">\n".
"</head>\n".
"<body>\n".
"<table align=\"center\" id=\"admin\">\n".
"<tr><td align=\"center\" colspan=\"2\">\n".
"<img src=\"/images/sublogo_2.png\"><br />\n".
"<span style=\"font-size: 12px; color: #0000FF\">(Admin Section)</span>\n".
"</td></tr>\n".
"<tr><td valign=\"top\">\n".
"<div id=\"navlist\">\n".
"<a href=\"/admin/\">Home</a>\n".
"<a href=\"/admin/add_provider.php\">Add Provider</a>\n".
"<a href=\"/admin/list_providers.php?list=list\">Delete / Edit Provider</a>\n".
"<a href=\"/admin/list_providers.php?review=review\">Toggle / Edit Reviews</a>\n".
"<a href=\"/index.php\">Back To Website</a>\n".
"</div>\n".
"</td><td width=\"625\">\n".
"<table id=\"main_admin\" align=\"center\" border=\"0\">\n".
"<tr><td align=\"center\">\n".
"The selected provider has now been updated.\n".
"</td></tr>\n".
"</table>\n".
"</td></tr>\n".
"</table>\n".
"</body>\n".
"</html>";

}
}
}
?>      
0
pingeyegAuthor Commented:
Right now I have the image's name being inserted finally, but it is wanting to insert on a separate row other than on the row of the provider.
0
pingeyegAuthor Commented:
Any ideas?
0
pingeyegAuthor Commented:
Alright, I figured it out.  You guys probably knew I would huh?
0
gamebitsCommented:
Thanks for the points and the grade, sorry if I couldn't follow up, familly obligations, glad you figure it out though.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.