PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > Newbieeeee
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Newbieeeee

Réponse
 
LinkBack Outils de la discussion
Vieux 15/09/2007, 14h06   #1
Reggie
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Newbieeeee

am trying to associate username and filename in my database.basically
am trying to create a script when users upload a file the file is then
associated with the user in the database.so when the user logon into
his account the database brings forward to file he or she uploaded.

I get this notice:

Notice: Undefined index: filename in /home/fhlinux169/c/clashoff.co.uk/
user/htdocs/upload.php on line 47
Could not insert data because Column count doesn't match value count
at row 1

this is the script. Am really stuck at the moment any will be
appreciated.

<?php
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$table=""; // Table name
$target = "upload/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;

//This is our size condition
$upload_size = $_FILES['uploaded']['size'];
if ($upload_size > 1000000000000)
{
echo "Your file is too large.<br>";
$ok=0;
}

//This is our limit file type condition
$upload_type = $_FILES['uploaded']['type'];
if ($upload_type =="text/php")
{
echo "No PHP files<br>";
$ok=0;
}

//Here we check that $ok was not set to 0 by an error
if ($ok==0)
{
Echo "Sorry your file was not uploaded";
}

//If everything is ok we try to upload it
else
{
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ".
basename( $_FILES['uploaded']['name']). " has been uploaded";
$filename=basename( $_FILES['uploaded']['name']);

mysql_connect("$host", "$username", "$password")or die("cannot
connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="update $table set filename = '$filename' WHERE
username='session_is_registered('username')' ";
mysql_query($sql);

$insert = mysql_query("insert into $table values ('NULL','".
$_POST['filename']."')")
or die("Could not insert data because ".mysql_error());

}
else
{
echo "Sorry, there was a problem uploading your file.";
}
}
?>

<html>
<body>
<a href="/user.php">Return to User Page</a> </form>
</body>
</html>

  Réponse avec citation
Vieux 15/09/2007, 15h08   #2
macca
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Newbieeeee

Show us your html form.

Where are you getting $_POST['filename'] from?

  Réponse avec citation
Vieux 15/09/2007, 15h33   #3
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Newbieeeee

Reggie wrote:
> am trying to associate username and filename in my database.basically
> am trying to create a script when users upload a file the file is then
> associated with the user in the database.so when the user logon into
> his account the database brings forward to file he or she uploaded.
>
> I get this notice:
>
> Notice: Undefined index: filename in /home/fhlinux169/c/clashoff.co.uk/
> user/htdocs/upload.php on line 47
> Could not insert data because Column count doesn't match value count
> at row 1
>
> this is the script. Am really stuck at the moment any will be
> appreciated.
>
> <?php
> $host=""; // Host name
> $username=""; // Mysql username
> $password=""; // Mysql password
> $db_name=""; // Database name
> $table=""; // Table name
> $target = "upload/";
> $target = $target . basename( $_FILES['uploaded']['name']) ;
> $ok=1;
>
> //This is our size condition
> $upload_size = $_FILES['uploaded']['size'];
> if ($upload_size > 1000000000000)
> {
> echo "Your file is too large.<br>";
> $ok=0;
> }
>
> //This is our limit file type condition
> $upload_type = $_FILES['uploaded']['type'];
> if ($upload_type =="text/php")
> {
> echo "No PHP files<br>";
> $ok=0;
> }
>
> //Here we check that $ok was not set to 0 by an error
> if ($ok==0)
> {
> Echo "Sorry your file was not uploaded";
> }
>
> //If everything is ok we try to upload it
> else
> {
> if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
> {
> echo "The file ".
> basename( $_FILES['uploaded']['name']). " has been uploaded";
> $filename=basename( $_FILES['uploaded']['name']);
>
> mysql_connect("$host", "$username", "$password")or die("cannot
> connect");
> mysql_select_db("$db_name")or die("cannot select DB");
> $sql="update $table set filename = '$filename' WHERE
> username='session_is_registered('username')' ";
> mysql_query($sql);
>
> $insert = mysql_query("insert into $table values ('NULL','".
> $_POST['filename']."')")
> or die("Could not insert data because ".mysql_error());
>
> }
> else
> {
> echo "Sorry, there was a problem uploading your file.";
> }
> }
> ?>
>
> <html>
> <body>
> <a href="/user.php">Return to User Page</a> </form>
> </body>
> </html>
>


Additionally, you have a SQL problem which you should follow up in
comp.databases.mysql.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 16h48.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11632 seconds with 11 queries