Ok... I have a noobie issue.
I am trying to upload a photo to specific directory on my server. (this is working correctly with the code below). However, I am also trying to rename the file and upload that filename to a mysql database (users.photo).
This is my code.. it shows no errors but it does not add it to my server.
HELP WOULD BE SO APPRECIATED!!\
I am trying to upload a photo to specific directory on my server. (this is working correctly with the code below). However, I am also trying to rename the file and upload that filename to a mysql database (users.photo).
This is my code.. it shows no errors but it does not add it to my server.
HELP WOULD BE SO APPRECIATED!!\
Code:
<?php require_once('../Connections/JMI10.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;
}
}
?>
<?php
$colname_Recordset1 = "-1";
if (isset($_SESSION['MM_Username'])) {
$colname_Recordset1 = $_SESSION['MM_Username'];
}
mysql_select_db($database_JMI10, $JMI10);
$query_Recordset1 = sprintf("SELECT * FROM `user` WHERE username = %s", GetSQLValueString($colname_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $JMI10) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<?
//This is the directory where images will be saved
$target = "/home/content/n/w/c/nwclark/html/jmi2/secure/idphotos/";
$target = $target . basename( $_FILES['photo']['name']);
//This gets all the other information from the form
$name=$_POST['username'];
$pic=($_FILES['photo']);
$width = 640;
$height = 480;
//Writes the information to the database
mysql_query("INSERT INTO `user` VALUES ('$name', '$pic')") ;
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{
//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
mysql_free_result($Recordset1);
?>
Comment