gabrielkolbe Posted January 15, 2007 Share Posted January 15, 2007 Hi, I have an uploading script that uploads a business card. It works in one place of my website but when I copy and paste the code onto another place the script runs, but does not add the new business card name on the database, the file get's copied to the server thou.Here is the code that works.....[code]if ($_POST['action'] == "add_bcard") { $status="";if (preg_match ("/jpg/i", $_FILES['bcard']['name'])) { $type="jpg"; $status="ok"; }if (preg_match ("/jpeg/i", $_FILES['bcard']['name'])) { $type="jpeg"; $status="ok"; }if (preg_match ("/gif/i", $_FILES['bcard']['name'])) { $type="gif"; $status="ok"; }if (preg_match ("/png/i", $_FILES['bcard']['name'])) { $type="png"; $status="ok"; }if($status=="ok"){ $keychars = "abcdefghijklmnopqrstuvwxyz0123456789"; $length = 3; $randkey = ""; for ($i=0;$i<$length;$i++) $randkey .= substr($keychars, rand(1, strlen($keychars) ), 1); $file = time().$randkey.".".$type; $uploadfile="../logos/".$file;if ((move_uploaded_file($_FILES['bcard']['tmp_name'], $uploadfile))or die("Couldn't copy the file!".$_FILES['bcard']['tmp_name'])){sv_image_small($uploadfile, $uploadfile, $_FILES['bcard']['type']);$sql="SELECT card FROM cardtable where userid = '".$_SESSION['userid']."'"; $resultcheck = mysql_query($sql) or die("<b>ERROR:</b> " . mysql_error());if (mysql_num_rows($resultcheck) == 1) { $query="SELECT card FROM cardtable where userid = '".$_SESSION['userid']."'"; $result = mysql_query($query) or die(mysql_error());while ($row = mysql_fetch_object($result)) { if($row->card <> ""){unlink("../logos/".$row->card); }}$sql="UPDATE cardtable set card = '$file' WHERE userid = '".$_SESSION['userid']."'"; mysql_query($sql) or die(mysql_error());} }}}[/code]HERE is the code that does NOT work[code]if ($_POST['action'] == "add_agentbcard") {//$a_id is in comes from the form in the form of a hidden field - to make sure we get the variable../// like so ///<input name="a_id" type="hidden" value="<?=$a_id?>">$a_id = $_POST['a_id'];$status="";if (preg_match ("/jpg/i", $_FILES['bcard']['name'])) { $type="jpg"; $status="ok"; }if (preg_match ("/jpeg/i", $_FILES['bcard']['name'])) { $type="jpeg"; $status="ok"; }if (preg_match ("/gif/i", $_FILES['bcard']['name'])) { $type="gif"; $status="ok"; }if (preg_match ("/png/i", $_FILES['bcard']['name'])) { $type="png"; $status="ok"; }if($status=="ok"){ $keychars = "abcdefghijklmnopqrstuvwxyz0123456789"; $length = 3; $randkey = ""; for ($i=0;$i<$length;$i++) $randkey .= substr($keychars, rand(1, strlen($keychars) ), 1); $file = time().$randkey.".".$type; $uploadfile="../logos/".$file;if ((move_uploaded_file($_FILES['bcard']['tmp_name'], $uploadfile))or die("Couldn't copy the file!".$_FILES['bcard']['tmp_name'])){sv_image_small($uploadfile, $uploadfile, $_FILES['bcard']['type']);$sql="SELECT cardFROM cardtable where userid = '".$a_id."'"; $resultcheck = mysql_query($sql) or die("<b>ERROR:</b>with ".$sql." " . mysql_error());if (mysql_num_rows($resultcheck) == 1) { $query="SELECT card FROM cardtable where userid = ".$a_id.""; $result = mysql_query($query) or die("<b>ERROR:</b>with ".$query." " . mysql_error());while ($row = mysql_fetch_object($result)) { if($row->card <> ""){unlink("../logos/".$row->card); }}$sql="UPDATE cardtable set card = ".$file." WHERE userid = ".$a_id.""; mysql_query($sql) or die("<b>ERROR:</b>with ".$sql." " . mysql_error());} }}}[/code]I have at one piont copied the code from the one that works and replace only the ".$_SESSION['userid']."'"; with ".$a_id.""; And still get a problem...Then i tried to hard code the ".$a_id.""; to something like '201';and still it does not work...I would really appreciate any help(please take no notice of table names and field names - these are fictional) Link to comment https://forums.phpfreaks.com/topic/34279-uploading-image-script-is-driving-me-nuts/ Share on other sites More sharing options...
micah1701 Posted January 15, 2007 Share Posted January 15, 2007 do you get an error message from the SQL statement? Where in your script do you call the mysql connection string? is it in an include file and if so, perhaps when you copied the script it no longer references the correct path? Link to comment https://forums.phpfreaks.com/topic/34279-uploading-image-script-is-driving-me-nuts/#findComment-161258 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.