Jump to content

Archived

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

lordphate

Data Entered in MYSQL only one letter?

Recommended Posts

Okay so i'm trying to set up categories  on a "download" page of mine and when the file is uploaded the category selected only comes up as the first letter of the value...any suggestions here's the code :| [code]<?php include 'header.php'; include './library/db.php'; include './library/sessions.php'; include './library/valid.php'; include 'sidebar.php';?>
<div id="main">
<html>
<head>
<title>LONGLIVEPS.COM</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.box {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
    border: 1px solid #000000;
}
-->
</style>
</head>

<body>
<?
// you can change this to any directory you want
// as long as php can write to it
$uploadDir = './storage/upload/';


if(isset($_POST['upload']))
{
    $fileName = $_FILES['userfile']['name'];
    $tmpName  = $_FILES['userfile']['tmp_name'];
    $fileSize = $_FILES['userfile']['size'];
    $fileType = $_FILES['userfile']['type'];
    $category = $_POST['category']['value'];
    // get the file extension first
    $ext      = substr(strrchr($fileName, "."), 1);

    // generate the random file name
    $randName = md5(rand() * time());

    // and now we have the unique file name for the upload file
    $filePath = $uploadDir . $randName . '.' . $ext;

    // move the files to the specified directory
    // if the upload directory is not writable or
    // something else went wrong $result will be false
    $result    = move_uploaded_file($tmpName, $filePath);
    if (!$result) {
        echo "Error uploading file";
        include 'footer.php';
        exit;
    }



    if(!get_magic_quotes_gpc())
    {
        $fileName  = addslashes($fileName);
        $filePath  = addslashes($filePath);
        $category = addslashes($category);
    }

    $query = "INSERT INTO upload (name, size, type, path, uploader, category ) ".
            "VALUES ('$fileName', '$fileSize', '$fileType', '$filePath', '$member','$category')";

    mysql_query($query) or die('Error, query failed : ' . mysql_error());


    echo "<br>File uploaded<br>";
}
?>
<form action="" method="post" enctype="multipart/form-data" name="uploadform">
  <table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
    <tr>
      <td width="246"><input type="hidden" name="MAX_FILE_SIZE" value="4000000000"><input name="userfile" type="file" class="box" id="userfile">
        </td> <td width="350" border="0" cellpadding="1" cellspacing="1">
        <select name="category" size="5">
<option value="movie">Movie</option>
<option value="hacks">Hacking</option>
<option value="audio">Music</option>
<option value="apps">Applications</option>
<option value="windows">\/\/  ! /\/ |) () \/\/ S</option>
<option value="papers">White Pepers</option>
<option value="inone">All in Ones</option>
</select></td>
      <td width="80"><input name="upload" type="submit" class="box" id="upload" value="  Upload  "></td>
        </tr>
  </table>
</form>
</body>
</html>
</div>              <? include 'footer.php'; ?>[/code]

Share this post


Link to post
Share on other sites
try changing

$category = $_POST['category']['value'];

to

$category = $_POST['category'];

Share this post


Link to post
Share on other sites
that did the trick...gosh i'm stupid :| here's another question though, how would i create a drop-down menu that has the categories listed and if the user clicks on one it would automatically change to show only that category?

Share this post


Link to post
Share on other sites
maybe I'm not following you on this one but it should change to show the selected category already.

does it reset itself or something?

Share this post


Link to post
Share on other sites
That code was actually for the upload section sorry...thinking ahead...now i can't figure out how to SHOW the categories...

Share this post


Link to post
Share on other sites
[quote author=lordphate link=topic=99159.msg390362#msg390362 date=1151818101]
that did the trick...gosh i'm stupid :| here's another question though, how would i create a drop-down menu that has the categories listed and if the user clicks on one it would automatically change to show only that category?
[/quote]
you would need to use ajax for that.  php is server side. javascript is client side.  ajax is js method that will post the info to a target php script that you can have run a query based on the selection and return the results, and then have js update the selections, without having to reload the whole page.

Share this post


Link to post
Share on other sites

×

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.