Hello all and Happy New Year!
I am a relatively novice PHP user so please bear with me.
I am working on a shopping cart project, partially to help me learn and finally to actually use on a demo site. I have a addnew.php page and on it among other fields are two text fields for the user to add the name of an image to use for a thumbnail view and a large view. I am using an include file that allows me to set the base url to the images folder and include it wherever I need it. This works fine with the addnew function. However, with the update function, an issue arises where I have to use the include file so that if the person had not entered an image name for one or both small or large images, when they do that now, the base url would be prepended to the filename they enter. As a design note here, I know I could just have the use enter the entire path themselves but I figured that most average users would not really know that info and so I want them to simply have to enter the filename. Anyway, because this is an update form, the data is read from the table and the two fields in question get filled in (if they have corresponding data in the table) with the entire path to the image. Therefore, if the user does not re-enter the filename, the base url gets prepend again to the already complete path like so: /path/to/images/image.jpg//path/to/images/image.jpg. Not a good thing. So, my thought was to use the strpos() function to find the location of the last '/' and then the substr() function to pull out just the image file name. Then I would attach the baseurl to that (again) before saving it to the DB. My code for this is as follows: (I am using DreamWeaverMX for this stuff but trying to do a lot by hand to learn more):
if ((isset($HTTP_POST_VARS["MM_update"])) && ($HTTP_POST_VARS["MM_update"] == "update")) {
$str1=$POST['itemImage'];
$str2=$POST['itemImgLrg'];
$pos1=strpos($str1, "/");
echo "position of / is at char $pos1";?>
<br>
<?php
$pos2=strpos($str2, "/");
echo "position of / in str2 is at char $pos2"; ?> <br>
<?php
if (!$pos1 === false) {
$smImgPath=substr("$str1", $pos1);
}
If (!$pos2 === false) {
$lrgImgPath=substr("str2", $pos2);
}
echo "image 1 path is $smImgPath"; ?><br>
<?php
echo "image 2 path is $lrgImgPath"; ?> <br>
<?php
$updateSQL = sprintf("UPDATE items SET itemName=%s, itemDesc=%s, itemDescLong=%s, itemPrice=%s, itemImage=%s, itemImgLrg=%s WHERE itemSku=%s",
GetSQLValueString($HTTP_POST_VARS['itemName'], "text"),
GetSQLValueString($HTTP_POST_VARS['itemDesc'], "text"),
GetSQLValueString($HTTP_POST_VARS['itemDescLong'], "text"),
GetSQLValueString($HTTP_POST_VARS['itemPrice'], "double"),
GetSQLValueString($smImgPath),
GetSQLValueString($lrgImgPath),
GetSQLValueString($HTTP_POST_VARS['itemSku'], "text"));
This is not working. I get no value to the $str1 and $str2 vars. I am not sure I guess, how or if I can pull the contents of the text fields from the form after the submit(Update) button is pressed and before the $UpdateSQL function is implemented.
$str1=$POST['itemImage'];
$str2=$POST['itemImgLrg'];
Also, does anyone know anything about the function GetSQLValueString ? Is that a DreamWeaver only function or a phKat function? I can't find any real info on it.
Sorry about the length and rambling nature of this post. If anyone understands what I am trying to say and do here, I would sincerely appreciate any help or alternative (and most like better) methods of achieving this.
Regards,
Dave