pixeltrace Posted July 28, 2007 Share Posted July 28, 2007 hi, i need help, i have a edit form with the upload file function everything is working fine except that i cant get the fiilename to be updated in my database i echo the $filename and its not giving me any values. hope you could help me solve this. below is my current code <? session_start(); if (session_is_registered("username")){ $username = $_SESSION['username']; $bid = $_GET['bid']; include 'db_connect.php'; $query = mysql_query("SELECT brand_name, brand_details, brand_url, brand_logo FROM engsoon_brands WHERE bid= '$bid'") or die(mysql_error()); $row = mysql_fetch_array( $query ); $brand_name = $row["brand_name"]; $brand_details = $row["brand_details"]; $brand_url = $row["brand_url"]; $brand_logo = $row["brand_logo"]; if ($_GET['upload'] == 'yes'){ //uses $_FILES[] global array //see manual for older PHP version info //This function will be used to get the extension from the filename function get_extension($file,$length=-1){ $p = strrpos($file,"."); $p++; if($length!=-1){ $ext = substr($file,$p,$length); } if($length==-1){ $ext = substr($file,$p); } $ext = strtolower($ext); return $ext; } //Not good practice, but here anyway //change to suit your needs //also some have to be set in the ini //for this to correctly work //2meg max ini_set("upload_max_filesize","200K"); //turn on file uploads ini_set("file_uploads","1"); //set your temp dir ini_set("upload_tmp_dir","/tmp/"); //set post size large enough to accomidate //3 2meg files and some overhead ini_set("post_max_size","200K"); } ?> <? //check to see if we have submited yet if($_POST["submit"]!="submit"){ //not yet so lets make the form ?> <table width="100" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="6" align="left"><img src="../images/spacer.gif" width="6" height="10" /></td> <td width="100%"><table width="216" border="0" cellspacing="0" cellpadding="0"> <tr> <td colspan="3" valign="top" bgcolor="#3261BB"><img src="images/spacer.gif" width="1" height="1" /></td> </tr> <tr> <td align="left" bgcolor="#3261BB" width="1"><img src="images/spacer.gif" width="1" height="1" /></td> <td width="214" valign="top"> <form name="fileup" method="post" enctype="multipart/form-data" action="<? echo $PHP_SELF; ?>"> <table width="515" border="0" cellspacing="2" cellpadding="3"> <tr> <td colspan="4" valign="top"><img src="images/spacer.gif" width="10" height="1" /></td> </tr> <tr> <td colspan="4" bgcolor="#999999" class="text2">BRAND INFORMATION</td> </tr> <tr> <td colspan="4" valign="top"><img src="images/spacer.gif" width="10" height="10" /></td> </tr> <tr> <td width="126" align="right" valign="top" class="text6">brand name : </td> <td> </td> <td colspan="2" class="text7"><input name="brand_name" type="text" size="40" value="<? echo "$brand_name"; ?>" readonly></td> </tr> <tr> <td align="right" valign="top" class="text6">details: </td> <td width="6"> </td> <td colspan="2"><textarea name="brand_details" cols="40" rows="5"><? echo "$brand_details"; ?></textarea></td> </tr> <tr> <td align="right" valign="top" class="text6">URL : </td> <td width="6"> </td> <td colspan="2"><span class="text7"> <input name="brand_url" type="text" size="40" value="<? echo "$brand_url"; ?>"> </span></td> </tr> <tr> <td align="right" valign="top" class="text6">current logo :</td> <td> </td> <td width="102"><img src=" <? if ($brand_logo == "") { echo "../images/nopic.gif"; }else{ echo "../images/brandlogo/$brand_logo"; } ?>" width="100" height="100" style="border:solid; border-color:#0000FF; border-width:1px"></td> <td width="247" align="left" valign="bottom"><a href="brandsmngr.php?id=3&bid=<? echo "$bid"; ?>&upload=yes" class="link1">upload new logo</a> </td> </tr> <? if ($_GET['upload'] == 'yes'){ echo " <tr> <td align='right' valign='top' class='text6'>update logo : </td> <td> </td> <td colspan='2'><input type='file' name='userfiles[]'></td> </tr> <tr> <td align='right' valign='top' class='text6'> </td> <td> </td> <td colspan='2' class='text6'>upload jpg or gif files only (max size 200K) </td> </tr> "; } ?> <tr> <td rowspan="2"> </td> <td rowspan="2"> </td> <td colspan="2"> <input type="hidden" name="MAX_FILE_SIZE" value="200000"> <input type="submit" value="submit" name="submit"> <input type="hidden" name="username" value="<? echo "$username"; ?>"> <input type=hidden value=http://www. name=redirect> <input type="hidden" value="<? echo "$brand_logo"; ?>" name="brand_logo" /> <input type="hidden" value="<? echo "$bid"; ?>" name="bid" /></td> </tr> <tr> <td colspan="2"> </td> </tr> </table> </form> </td> <td align="right" bgcolor="#3261BB" width="1"><img src="images/spacer.gif" width="1" height="1" /></td> </tr> <tr> <td colspan="3" valign="top" bgcolor="#3261BB"><img src="images/spacer.gif" width="1" height="1" /></td> </tr> </table></td> <td width="6" align="right"><img src="../images/spacer.gif" width="6" height="10" /></td> </tr> </table> <? } ?> <? if ($_GET['upload'] =='yes'){ //see if we have submited and that the files array has been set if(($_POST["submit"]=="submit")&&(is_array($_FILES['userfiles']))){ $ftp_user_name="user"; //change to ftp username $ftp_user_pass="pass"; //change to ftp password $ftp_server="domain"; //change to ftp url $ftp_dump_dir="/location/"; //change to destination directory //go through all the files for($x=0;$x<count($_FILES['userfiles']['name']);$x++){ //now we do some file checking //check to see if file is there if($_FILES['userfiles']['name'][$x]!="none"){ //file has a name //check filesize if($_FILES['userfiles']['size'][$x]!=0){ //file is larger than 0 bytes //Check to see if it is uploaded if(is_uploaded_file($_FILES['userfiles']['tmp_name'][$x])){ //file has been uploaded! //let the user know their file has be uploaded echo "file ".$_FILES['userfiles']['name'][$x]." uploaded!<br>"; //conect to ftp server $conn_id = ftp_connect($ftp_server); // login with username and password $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); // check connection if ((!$conn_id) || (!$login_result)) { echo "FTP connection has failed!<br>"; echo "Attempted to connect to $ftp_server for user $ftp_user_name"; exit; } else { echo "Connected to $ftp_server! <br>"; //set PASV mode if(!ftp_pasv($conn_id,TRUE)){ echo "Could not enter PASV mode!"; } //rename to file#_date.ext //$filename = "file".($x+1)."_".date("MdY"); $filename = $brand_name; $filename.= ".".get_extension($_FILES['userfiles']['name'][$x],3); //change directory if (@ftp_chdir($conn_id, $ftp_dump_dir)) { //maybe you want to make sure we are in the correct directory echo "Current directory is now : ", ftp_pwd($conn_id), "\n"; } else { //you want to know if it didn't work echo "Couldn't change directory\n"; } //upload the file and let the user know what happened if(ftp_put($conn_id,$filename,$_FILES['userfiles']['tmp_name'][$x],FTP_BINARY)){ echo "File ".$_FILES['userfiles']['name'][$x]." was sent successfully<br>"; echo "File was named ".$filename."<br>"; }else{ echo "There was a problem sending file ".$_FILES['userfiles']['name'][$x]."<br>";; } } // close the FTP stream ftp_close($conn_id); } else echo"brand was not added!<br>"; } } echo "<br>"; }//end for loop $brand_name = $_POST['brand_name']; $brand_details = $_POST['brand_details']; $brand_url = $_POST['brand_url']; $brand_name = stripslashes($brand_name); $brand_details = stripslashes($brand_details); $brand_url = stripslashes($brand_url); $sql="UPDATE engsoon_brands SET brand_name='$brand_name', brand_details='$brand_details', brand_url='$brand_url', brand_logo='$filename' WHERE bid='$bid'"; mysql_query($sql) or die("error:".mysql_error()); echo '<script language=javascript> alert("brand has been updated1!");top.location = "brandsmngr.php?id=2";</script>'; } } if(($_POST["submit"]=="submit")&&($upload !== 'yes')){ $brand_name = $_POST['brand_name']; $brand_details = $_POST['brand_details']; $brand_url = $_POST['brand_url']; $brand_logo = $_POST['brandlogo']; $brand_name = stripslashes($brand_name); $brand_details = stripslashes($brand_details); $brand_url = stripslashes($brand_url); $sql="UPDATE engsoon_brands SET brand_name='$brand_name', brand_details='$brand_details', brand_url='$brand_url', brand_logo='$brand_logo' WHERE bid='$bid'"; mysql_query($sql) or die("error:".mysql_error()); echo '<script language=javascript> alert("brand has been updated2!");top.location = "brandsmngr.php?id=2";</script>'; } }else{ echo "<font face=\"Arial\">You are not authorized to access this page ... Please <a href='../index.php'>Login</a></font>"; } ?> thanks so much! Link to comment https://forums.phpfreaks.com/topic/62196-solved-need-help-in-updating-in-my-edit-page/ Share on other sites More sharing options...
pixeltrace Posted July 28, 2007 Author Share Posted July 28, 2007 hi, i already echo the $filename and i can get the value. however when it is executing the query already. $sql="UPDATE engsoon_brands SET brand_name='$brand_name', brand_details='$brand_details', brand_url='$brand_url', brands_logo='$brands_logo' WHERE bid='$bid'"; brands_logo is the only field that is not being updated in my database table. i dont know what is wrong. hope you could help me fix this. thanks so much! Link to comment https://forums.phpfreaks.com/topic/62196-solved-need-help-in-updating-in-my-edit-page/#findComment-309580 Share on other sites More sharing options...
pixeltrace Posted July 28, 2007 Author Share Posted July 28, 2007 hi, another thing. its kinda weird because even if i replace the value of the filename into letters. this is what i did $sql="UPDATE engsoon_brands SET brands_logo='sdasdasdasda', brand_name='$brand_name', brand_details='$brand_details', brand_url='$brand_url' WHERE bid='$bid'"; it still doesnt update that specific field in my database table eventhough i already put a value for brands_logo. is there something that needs to be set on that field? currently that field type is set to varchar(125) hope you could help me fix this thanks! Link to comment https://forums.phpfreaks.com/topic/62196-solved-need-help-in-updating-in-my-edit-page/#findComment-309584 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.