Jump to content

Problem inserting some data into database..


Patch^

Recommended Posts

Hi, I'm new here so please forgive me If i don't follow the protocol of this forum  :-\. Anyway I'm having some trouble with a piece of PHP and mySQL. The code I have at the moment creates directories (mkdir) and copys files into them. This seems to work, but I need the variables "$mypath" and "$newfile5" to be inserted into my database.

But it won't. It enters the other data such as name and description and creates the folder. I really need this to work and I will really appreciate it if someone can help me out :)

 

Here is my source for the page, with a few things "hidden":

<?php require_once('Connections/hidden.php'); ?> 
<?php 
//initialize the session 
if (!isset($_SESSION)) { 
  session_start(); 
} 

// ** Logout the current user. ** 
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true"; 
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){ 
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']); 
} 

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){ 
  //to fully log out a visitor we need to clear the session varialbles 
  $_SESSION['MM_Username'] = NULL; 
  $_SESSION['MM_UserGroup'] = NULL; 
  $_SESSION['PrevUrl'] = NULL; 
  unset($_SESSION['MM_Username']); 
  unset($_SESSION['MM_UserGroup']); 
  unset($_SESSION['PrevUrl']); 
     
  $logoutGoTo = "log.php"; 
  if ($logoutGoTo) { 
    header("Location: $logoutGoTo"); 
    exit; 
  } 
} 
?> 
<?php 
if (!isset($_SESSION)) { 
  session_start(); 
} 
$MM_authorizedUsers = "hidden"; 
$MM_donotCheckaccess = "true"; 

// *** Restrict Access To Page: Grant or deny access to this page 
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {  
  // For security, start by assuming the visitor is NOT authorized.  
  $isValid = False;  

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username.  
  // Therefore, we know that a user is NOT logged in if that Session variable is blank.  
  if (!empty($UserName)) {  
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login.  
    // Parse the strings into arrays.  
    $arrUsers = Explode(",", $strUsers);  
    $arrGroups = Explode(",", $strGroups);  
    if (in_array($UserName, $arrUsers)) {  
      $isValid = true;  
    }  
    // Or, you may restrict access to only certain users based on their username.  
    if (in_array($UserGroup, $arrGroups)) {  
      $isValid = true;  
    }  
    if (($strUsers == "") && true) {  
      $isValid = true;  
    }  
  }  
  return $isValid;  
} 

$MM_restrictGoTo = "log_error.php"; 
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {    
  $MM_qsChar = "?"; 
  $MM_referrer = $_SERVER['PHP_SELF']; 
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&"; 
  if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)  
  $MM_referrer .= "?" . $QUERY_STRING; 
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer); 
  header("Location: ". $MM_restrictGoTo);  
  exit; 
} 
?> 
<?php 
if (!function_exists("GetSQLValueString")) { 
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")  
{ 
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; 

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); 

  switch ($theType) { 
    case "text": 
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
      break;     
    case "long": 
    case "int": 
      $theValue = ($theValue != "") ? intval($theValue) : "NULL"; 
      break; 
    case "double": 
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; 
      break; 
    case "date": 
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
      break; 
    case "defined": 
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; 
      break; 
  } 
  return $theValue; 
} 
} 

$editFormAction = $_SERVER['PHP_SELF']; 
if (isset($_SERVER['QUERY_STRING'])) { 
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); 

} 

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "slideshowCreator")) { 
  $insertSQL = sprintf("INSERT INTO hidden (name, des, url, url2) VALUES (%s, %s, %s, %s)", 
                       GetSQLValueString($_POST['name'], "text"), 
                       GetSQLValueString($_POST['des'], "text"), 
                       GetSQLValueString($_POST['path'], "text"), 
                       GetSQLValueString($_POST['url2'], "text")); 

  mysql_select_db($database_hidden, $hidden); 
  $Result1 = mysql_query($insertSQL, $hidden) or die(mysql_error()); 

  $insertGoTo = "slides.php"; 
  if (isset($_SERVER['QUERY_STRING'])) { 
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; 
    $insertGoTo .= $_SERVER['QUERY_STRING']; 
  } 
  header(sprintf("Location: %s", $insertGoTo)); 
} 

$colname_hidden = "-1"; 
if (isset($_GET['id'])) { 
  $colname_hidden = $_GET['id']; 
} 
mysql_select_db($database_hidden, $hidden); 
$query_hidden = sprintf("SELECT * FROM hidden WHERE id = %s", GetSQLValueString($colname_hidden, "int")); 
$hidden = mysql_query($query_hidden, $hidden) or die(mysql_error()); 
$row_hidden = mysql_fetch_assoc($hidden); 
$totalRows_hidden = mysql_num_rows($hidden); 

mysql_select_db($database_hidden, $hidden); 
$query_user = "SELECT * FROM users"; 
$user = mysql_query($query_user, $hidden) or die(mysql_error()); 
$row_user = mysql_fetch_assoc($user); 
$totalRows_user = mysql_num_rows($user); 
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<title>campbell & Rowley Slide Show Creator Prototype.</title> 
<link href="css.css" rel="stylesheet" type="text/css" /> 
</head> 

<body> 
<div id="centre_site"> 
<div id="site_header2"></div> 

<?php  

$name=$_POST['name']; 
$des=$_POST['des']; 
$url=$_POST['url']; 

?> 

<?php 

/*function dircopy($srcdir, $dstdir, $verbose = false) { 
  $num = 0; 
  if(!is_dir($dstdir)) mkdir($dstdir); 
  if($curdir = opendir($srcdir)) { 
    while($file = readdir($curdir)) { 
      if($file != '.' && $file != '..') { 
        $srcfile = $srcdir . 'imgs' . $file; 
        $dstfile = $dstdir . 'slides/'time(); . $file; 
        if(is_file($srcfile)) { 
          if(is_file($dstfile)) $ow = filemtime($srcfile) - filemtime($dstfile); else $ow = 1; 
          if($ow > 0) { 
            if($verbose) echo "Copying '$srcfile' to '$dstfile'..."; 
            if(copy($srcfile, $dstfile)) { 
              touch($dstfile, filemtime($srcfile)); $num++; 
              if($verbose) echo "OK\n"; 
            } 
            else echo "Error: File '$srcfile' could not be copied!\n"; 
          }                    
        } 
        else if(is_dir($srcfile)) { 
          $num += dircopy($srcfile, $dstfile, $verbose); 
        } 
      } 
    } 
    closedir($curdir); 
  } 
  return $num; 
}*/ 

/////not too sure about this bit here, how to get it to create a directory when I click submit etc..///// 

//if (slideshowCreator !=""){ 

//if($_POST["copyFiles"] == "yes"){ 

//if($_POST['name'] && $_POST['des'] == true){ 

//if($_SERVER['QUERY_STRING'] == true){ 

$submit = $_POST['Submit']; 

    if ( $submit )  
    { 
     
        $mypath='slides/'.time(); 
        $mypath2='slides/'.time().'/imgs'; 
        $mypath3='slides/'.time().'/images'; 
        $mypath4='slides/'.time().'/images/thumbs'; 
         
        mkdir($mypath, 0777,true); 
        mkdir($mypath2, 0777, true); 
        mkdir($mypath3, 0777, true); 
        mkdir($mypath4, 0777, true); 
         
        //$user_name =$row_user['username']; ; 
         
        //chown($mypath, $user_name); 
         
         
        $file1 = 'templates/gallery.swf'; 
        $file2 = 'templates/images.xml'; 
        $file3 = 'templates/index.html'; 
        $file4 = 'templates/AC_RunActiveContent.js'; 
        $file5 = 'templates/imageForm+xml.php'; 
        $file6 = 'templates/css.css'; 
        //$file7 = 'templates/imgs'; 
        $file8 = 'imgs/accept_icon.gif'; 
        $file9 = 'imgs/error_icon.gif'; 
        $file10 = 'imgs/img_icon.gif'; 
        $file11 = 'imgs/warn_icon.gif'; 
        $file12 = 'imgs/write_icon.gif'; 
        $file13 = 'imgs/header2.gif'; 
        $file14 = 'imgs/header.gif'; 
         
        $newfile1 = $mypath.'/gallery.swf'; 
        $newfile2 = $mypath.'/images.xml'; 
        $newfile3 = $mypath.'/index.html'; 
        $newfile4 = $mypath.'/AC_RunActiveContent.js'; 
        $newfile5 = $mypath.'/imageForm+xml.php'; 
        $newfile6 = $mypath.'/css.css'; 
        //$newfile7 = $mypath.'/imgs'; 
        $newfile8 = $mypath2.'/accept_icon.gif'; 
        $newfile9 = $mypath2.'/error_icon.gif'; 
        $newfile10 = $mypath2.'/img_icon.gif'; 
        $newfile11 = $mypath2.'/warn_icon.gif'; 
        $newfile12 = $mypath2.'/write_icon.gif'; 
        $newfile13 = $mypath2.'/header2.gif'; 
        $newfile14 = $mypath2.'/header.gif'; 
         
        /*chmod($mypath, 777); 
         
        chmod($mypath.'/gallery.swf', 777); 
        chmod($mypath.'/images.xml', 777); 
        chmod($mypath.'/index.html', 777); 
        chmod($mypath.'/AC_RunActiveContent.js', 777); 
        chmod($mypath.'/imageForm+xml.php', 777); 
        chmod($mypath.'/css.css', 777); 
         
        chmod($mypath.'/imgs/accept_icon.gif', 777); 
        chmod($mypath.'/imgs/error_icon.gif', 777); 
        chmod($mypath.'/imgs/img_icon.gif', 777); 
        chmod($mypath.'/imgs/warn_icon.gif', 777); 
        chmod($mypath.'/imgs/write_icon.gif', 777); 
        chmod($mypath.'/imgs/header2.gif', 777); 
        chmod($mypath.'/imgs/header.gif', 777); 
         
        */ 
         
         
        if (!copy($file1, $newfile1)) 
        { 
            echo "failed to copy $file1... \n"; 
        } 
         
        if (!copy($file2, $newfile2)) 
        { 
            echo "failed to copy $file2... \n"; 
        } 
         
        if (!copy($file3, $newfile3)) 
        { 
            echo "failed to copy $file3... \n"; 
        } 
         
        if (!copy($file4, $newfile4)) 
        { 
            echo "failed to copy $file4... \n"; 
        } 
         
        if (!copy($file5, $newfile5)) 
        { 
            echo "failed to copy $file5... \n"; 
        } 
        if (!copy($file6, $newfile6)) 
        { 
            echo "failed to copy $file6... \n"; 
        } 
        /*if (!copy($file7, $newfile7)) 
        { 
            echo "failed to copy $file7... \n"; 
        }*/ 
        if (!copy($file8, $newfile8)) 
        { 
            echo "failed to copy $file7... \n"; 
        } 
        if (!copy($file9, $newfile9)) 
        { 
            echo "failed to copy $file10... \n"; 
        } 
        if (!copy($file10, $newfile10)) 
        { 
            echo "failed to copy $file10... \n"; 
        } 
        if (!copy($file11, $newfile11)) 
        { 
            echo "failed to copy $file11... \n"; 
        } 
        if (!copy($file12, $newfile12)) 
        { 
            echo "failed to copy $file12... \n"; 
        } 
        if (!copy($file13, $newfile13)) 
        { 
            echo "failed to copy $file13... \n"; 
        } 
        if (!copy($file14, $newfile14)) 
        { 
            echo "failed to copy $file14... \n"; 
        } 
    } 
?> 

<p align="left"><a href="slides.php">View current Slideshows</a></p><p align="right"><a href="<?php echo $logoutAction ?>">Log out</a></p> 

<div id="form_centre"> 
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" name="slideshowCreator"> 
            <label>Name of Slide Show:</label><input name="name" type="text" value="" /><br /><div id="input_help">Make sure that this name is unique!"</div> 
            <label>Description of Slide Show:</label><textarea name="des" cols="26" rows="10" wrap="virtual"></textarea> 
            <br /> 
            <input name="path" type="hidden" value="<? echo $mypath ?>" /> 
            <input name="url2" type="hidden" value="<? echo $newfile5 ?>" /> 
             
            <label></label><input name="Submit" type="submit" value="Submit" /> 
            <input type="hidden" name="MM_insert" value="slideshowCreator" /> 
    </form> 
<br /> 

</div><br /> 
<div id="copyright" align="center">hidden</div> 
</div> 

</body> 
</html> 
<?php 
mysql_free_result($hidden); 

mysql_free_result($user); 
?>

 

I made this with Adobe Dreamweaver, so it produces a load of crap as well, so it may be a little hard to read lol.

 

Thanks in advance!!

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.