0

I am fairly new in this world and I still have a lot to learn. I am making a dynamic page where I have to load 7 images for the database and I'm not even getting

if anyone can help me. thanks

<?php require_once('../Connections/ligacao.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $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;
}
}

if (isset($_POST[projetos])) {

$uploadArray= array();
$uploadArray[] = $_POST['p_logo'];
$uploadArray[] = $_POST['p_img1'];
$uploadArray[] = $_POST['p_img2'];
$uploadArray[] = $_POST['p_img3'];
$uploadArray[] = $_POST['p_img4'];
$uploadArray[] = $_POST['p_img5'];
$uploadArray[] = $_POST['p_img6']; 

foreach($uploadArray as $file) {


$target_path = "fotoProjetos/";

$target_path = $target_path . basename( $_FILES['$file']['name']); 

if(move_uploaded_file($_FILES['$file']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['$file']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}
}

}

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

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO projetos (p_nome, p_logo, p_img1, p_img2, p_img3, p_img4, p_img5, p_img6) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['p_nome'], "text"),
                       GetSQLValueString($target_path, "text"),
                       GetSQLValueString($target_path, "text"),
                       GetSQLValueString($target_path, "text"),
                       GetSQLValueString($target_path, "text"),
                       GetSQLValueString($target_path, "text"),
                       GetSQLValueString($target_path, "text"),
                       GetSQLValueString($target_path, "text"));

  mysql_select_db($database_ligacao, $ligacao);
  $Result1 = mysql_query($insertSQL, $ligacao) or die(mysql_error());

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

mysql_select_db($database_ligacao, $ligacao);
$query_rsProjeto = "SELECT * FROM projetos";
$rsProjeto = mysql_query($query_rsProjeto, $ligacao) or die(mysql_error());
$row_rsProjeto = mysql_fetch_assoc($rsProjeto);
$totalRows_rsProjeto = mysql_num_rows($rsProjeto);
?>
<!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>Untitled Document</title>

<link href="../css/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div align="center" class="c_membro"><img src="../images/imw.png" /></div>
<div class="espaço"></div>
<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="form1" id="form1">
  <table width="300" align="center" cellspacing="5">
    <tr>
      <td>Nome do Cliente</td>
      <td><input type="text" name="p_nome" id="p_nome" /></td>
    </tr>
    <tr>
      <td>Logotipo</td>
      <td><input type="file" name="p_logo" id="p_logo" /></td>
    </tr>
    <tr>
      <td>Imagem 1</td>
      <td><input type="file" name="p_img1" id="p_img1" /></td>
    </tr>
    <tr>
      <td>Imagem 2</td>
      <td><input type="file" name="p_img2" id="p_img2" /></td>
    </tr>
    <tr>
      <td>Imagem 3</td>
      <td><input type="file" name="p_img3" id="p_img3" /></td>
    </tr>
    <tr>
      <td>Imagem 4</td>
      <td><input type="file" name="p_img4" id="p_img4" /></td>
    </tr>
    <tr>
      <td>Imagem 5</td>
      <td><input type="file" name="p_img5" id="p_img5" /></td>
    </tr>
    <tr>
      <td>Imagem 6</td>
      <td><input type="file" name="p_img6" id="p_img6" /></td>
    </tr>
    <tr>
      <td colspan="2">
      <input type="submit" name="button" id="button" value="Gravar" /></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1" />
</form>
</body>
</html>
<?php
mysql_free_result($rsProjeto);
?>

Edited by Nick Evan: Fixed formatting

3
Contributors
7
Replies
9
Views
5 Years
Discussion Span
Last Post by vibhaJ
0
<?php require_once('../Connections/ligacao.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $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;
}
}

if (isset($_POST['projetos'])) {
 
$uploadArray= array();
$uploadArray[] = $_POST['p_logo'];
$uploadArray[] = $_POST['p_img1'];
$uploadArray[] = $_POST['p_img2'];
$uploadArray[] = $_POST['p_img3'];
$uploadArray[] = $_POST['p_img4'];
$uploadArray[] = $_POST['p_img5'];
$uploadArray[] = $_POST['p_img6']; 
 
foreach($uploadArray as $file) {
 
 
$target_path = "fotoProjetos/";
 
$target_path = $target_path . basename( $_FILES['$file']['name']); 
 
if(move_uploaded_file($_FILES['$file']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['$file']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}
}
 
}

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

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO projetos (p_nome, p_logo, p_img1, p_img2, p_img3, p_img4, p_img5, p_img6) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['p_nome'], "text"),
                       GetSQLValueString($_POST['p_logo'], "text"),
                       GetSQLValueString($_POST['p_img1'], "text"),
                       GetSQLValueString($_POST['p_img2'], "text"),
                       GetSQLValueString($_POST['p_img3'], "text"),
                       GetSQLValueString($_POST['p_img4'], "text"),
                       GetSQLValueString($_POST['p_img5'], "text"),
                       GetSQLValueString($_POST['p_img6'], "text"));

  mysql_select_db($database_ligacao, $ligacao);
  $Result1 = mysql_query($insertSQL, $ligacao) or die(mysql_error());

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

mysql_select_db($database_ligacao, $ligacao);
$query_rsProjeto = "SELECT * FROM projetos";
$rsProjeto = mysql_query($query_rsProjeto, $ligacao) or die(mysql_error());
$row_rsProjeto = mysql_fetch_assoc($rsProjeto);
$totalRows_rsProjeto = mysql_num_rows($rsProjeto);
?>
<!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>Untitled Document</title>

<link href="../css/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div align="center" class="c_membro"><img src="../images/imw.png" /></div>
<div class="espaço"></div>
<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="form1" id="form1">
  <table width="300" align="center" cellspacing="5">
    <tr>
      <td>Nome do Cliente</td>
      <td><input type="text" name="p_nome" id="p_nome" /></td>
    </tr>
    <tr>
      <td>Logotipo</td>
      <td><input type="file" name="p_logo" id="p_logo" /></td>
    </tr>
    <tr>
      <td>Imagem 1</td>
      <td><input type="file" name="p_img1" id="p_img1" /></td>
    </tr>
    <tr>
      <td>Imagem 2</td>
      <td><input type="file" name="p_img2" id="p_img2" /></td>
    </tr>
    <tr>
      <td>Imagem 3</td>
      <td><input type="file" name="p_img3" id="p_img3" /></td>
    </tr>
    <tr>
      <td>Imagem 4</td>
      <td><input type="file" name="p_img4" id="p_img4" /></td>
    </tr>
    <tr>
      <td>Imagem 5</td>
      <td><input type="file" name="p_img5" id="p_img5" /></td>
    </tr>
    <tr>
      <td>Imagem 6</td>
      <td><input type="file" name="p_img6" id="p_img6" /></td>
    </tr>
    <tr>
      <td colspan="2">
      <input type="submit" name="button" id="button" value="Gravar" /></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1" />
</form>
</body>
</html>
<?php
mysql_free_result($rsProjeto);
?>
0

Don't use $_POST for file input field.
You need to use $_FILES for file name. and store that name in database.
When you want to display image fetch filename from database and concate with $target_path.
e.g. <img src="<?php echo $target_path.$file_name;?>" />

0

hello again, wanted to thank you for this help and interest shown, thanks

0

I've done the change but when I enter, these errors appears

-------------------------------------------------------------

Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in C:\wamp\www\whatdesign\admin\inserir_progetos.php on line 10

Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in C:\wamp\www\whatdesign\admin\inserir_progetos.php on line 10

Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in C:\wamp\www\whatdesign\admin\inserir_progetos.php on line 10

Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in C:\wamp\www\whatdesign\admin\inserir_progetos.php on line 10

Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in C:\wamp\www\whatdesign\admin\inserir_progetos.php on line 10

Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in C:\wamp\www\whatdesign\admin\inserir_progetos.php on line 10

Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in C:\wamp\www\whatdesign\admin\inserir_progetos.php on line 10
Column 'p_logo' cannot be null


this is on line 10

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

pardon my ignorance, and thanks again

0

I think you are passing null to "GetSQLValueString" function.
Debug your code. Add below form when form is submitted. Which will show all form posted variable.

echo '<pre>';
print_r($_POST);
exit;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.