Jump to content

image into a database


garydt

Recommended Posts

I'm trying to put an image into the same record as the logged-on username and other data by using 'update' but, from what i read i have to use the 'upload' command. Can you tell me if i can upload an image into the same record as the logged-on username, and if so, how?

 

Heres my code to update the record

<?php

session_start();

?>

<?php require_once('Connections/elvisdb.php'); ?>

<?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;

}

}

 

$user = $_SESSION['MM_Username'];

 

 

$editFormAction = $_SERVER['PHP_SELF'];

if (isset($_SERVER['QUERY_STRING'])) {

  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);

}

 

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {

  $updateSQL = sprintf("UPDATE userinformation SET why=%s, howlong=%s, decade=%s, song=%s, album=%s, pictur=%s, aboutu=%s WHERE usernm='$user'",

                      GetSQLValueString($_POST['why'], "text"),

                      GetSQLValueString($_POST['sincewhen'], "text"),

                      GetSQLValueString($_POST['decad'], "text"),

                      GetSQLValueString($_POST['favsong'], "text"),

                      GetSQLValueString($_POST['favealbum'], "text"),

                      GetSQLValueString($_POST['file'], "text"),

                      GetSQLValueString($_POST['textarea'], "text"),

                      GetSQLValueString($_POST['hiddenField'], "text"));

 

  mysql_select_db($database_elvisdb, $elvisdb);

  $Result1 = mysql_query($updateSQL, $elvisdb) or die(mysql_error());

 

  $updateGoTo = "userpage.php";

  if (isset($_SERVER['QUERY_STRING'])) {

    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";

    $updateGoTo .= $_SERVER['QUERY_STRING'];

  }

  header(sprintf("Location: %s", $updateGoTo));

}

?><!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=iso-8859-1" />

<title>Untitled Document</title>

<style type="text/css">

<!--

.style1 {font-family: Arial, Helvetica, sans-serif}

.style5 {font-family: Helvetica, Arial, "Times New Roman"}

-->

</style>

</head>

 

<body>

<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="form1" id="form1">

  <label></label>

  <table width="550" border="0" align="center" cellpadding="5">

    <tr>

      <td bgcolor="#FFFFFF"><div align="left" class="style5">Why do you like/love Elvis </div>

          <span class="style5">

          <label> </label>

          </span> <span class="style5">

          <label></label>

          </span>

          <label>

          <div align="left" class="style5">

            <textarea name="why" id="why"></textarea>

          </div>

        </label>      </td>

    </tr>

    <tr>

      <td bgcolor="#FFFFFF"><div align="left" class="style5">How long have you been an Elvis fan </div>

          <span class="style5">

          <label> </label>

          </span> <span class="style5">

          <label></label>

          </span>

          <label>

          <div align="left" class="style5">

            <input name="sincewhen" type="text" id="sincewhen" />

          </div>

        </label>      </td>

    </tr>

    <tr>

      <td bgcolor="#FFFFFF"><div align="left" class="style5">Which Elvis decade is your favourite? </div>

          <span class="style5">

          <label> </label>

          </span> <span class="style5">

          <label></label>

          </span>

          <label>

          <div align="left" class="style5">

            <select name="decad" size="1" id="decad">

              <option selected="selected">1950's</option>

              <option>1960's</option>

              <option>1970's</option>

              <option>All 3 decades</option>

            </select>

          </div>

        </label>      </td>

    </tr>

    <tr>

      <td bgcolor="#FFFFFF"><div align="left" class="style5">

          <p>

            <label> Your favourite Elvis song<br />

            <input name="favsong" type="text" id="favsong" />

            </label>

          </p>

      </div></td>

    </tr>

    <tr>

      <td bgcolor="#FFFFFF"><div align="left" class="style5">

          <p>Your favourite Elvis album

            <label><br />

              <input name="favealbum" type="text" id="favealbum" />

              </label>

          </p>

      </div></td>

    </tr>

    <tr>

      <td bgcolor="#FFFFFF"><label> Upload a photo <br />

        <input name="file" type="file" maxlength="1400000" />

      </label></td>

    </tr>

    <tr>

      <td bgcolor="#FFFFFF"><div align="left"><span class="style1"><span class="style5"></span></span>

              <label></label>

              <label> About you <br />

              <textarea name="textarea"></textarea>

          </label>

      </div></td>

    </tr>

    <tr>

      <td bgcolor="#FFFFFF"><label>

        <input type="submit" name="Submit" value="Submit" />

      </label></td>

    </tr>

  </table>

  <p>

    <input name="hiddenField" type="hidden" value="$user" />

  </p>

  <p>

    <label></label>

  </p>

  <input type="hidden" name="MM_update" value="form1">

</form>

</body>

</html>

 

Link to comment
https://forums.phpfreaks.com/topic/40414-image-into-a-database/
Share on other sites

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.