Avatar billede tobrukDk Novice
10. februar 2012 - 21:23 Der er 12 kommentarer og
1 løsning

Ville ikke tildele at upload det til database eller komme videre

Hej

Det er sådan at jeg få en fejlmeddelse når jeg prøve at køre det her kode færdig eller hvordan man skal sige det .. :)



<?php
include("include/database/database.php");

//Infomation
$brugernavn = $_POST["brugernavn"];
$password = $_POST["password"];
$gentag = $_POST["gentag"];
$facebook = $_POST["facebook"];
$soundcloud = $_POST["soundcloud"];
$land = $_POST["land"];
$profiltekst = $_POST["profiltekst"];
$djnavn = $_POST["djnavn"];
$email = $_POST["email"];
$site = $_POST["site"];
$fk_id = $_POST["kategori"];
$errorCount = 0;

include("include/class.upload.php");

$handle = new Upload($_FILES['file']);

if($handle->uploaded){

//lidt mere store billeder
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_x = 220;
$handle->Process("picthumb/storeimg");

//til profil billede lign..
$handle->image_resize = true;
$handle->image_ratio_crop = true;
$handle->image_y = 75;
$handle->image_x = 75;
$handle->Process("picthumb");

$billedefilnavn = $handle->file_dst_name;

echo "Dit billede blev upload";

}else {
echo "Fejl; Du skal uploade en fil";
}

if($brugernavn == "")
{
echo "Du skal indtaste et brugernavn.<br>";
$errorCount++;
}
if($password == "")
{
echo "Du skal indtaste et password.<br>";
$errorCount++;
}
if($gentag == "" || $gentag != $password)
{
echo "De to passwordfelter skal have ens indhold.<br>";
$errorCount++;
}

include("include/database/database.php");


$password = sha1($password);
$insert = mysql_query("INSERT INTO brugere (brugernavn,password,facebook,soundcloud,land,profiltekst,djnavn,email,site,fk_musik_info,profilbillede) VALUES ('$brugernavn','$password','$facebook','$soundcloud','$land','$profiltekst','$djnavn','$email','$site','$fk_id','$billedefilnavn')");

if(!$insert) {
echo "<a href='index.php'>forside</a>";
}
else {
echo "<a href='index.php'>forside</a>";
}

?>



sådan her så min database ud før i tiden :)

http://d.localhostr.com/file/aKVoqOH/capture.png

håber du kan hjælp mig frem til en rigtigt godt svar :)
Avatar billede Broxigar Praktikant
10. februar 2012 - 22:57 #1
Hvilken fejlmeddelelser får du ? evt et screendump
Avatar billede tobrukDk Novice
10. februar 2012 - 23:58 #2
Sorry havde glemt at skrive dem :

Notice: Undefined index: file in C:xampphtdocsdjinfoopretbruger_info.php on line 20
Fejl; Du skal uploade en fil
Notice: Undefined variable: billedefilnavn in C:xampphtdocsdjinfoopretbruger_info.php on line 65
Avatar billede Broxigar Praktikant
11. februar 2012 - 16:54 #3
Prøv og sætte dette ind på linje 65 istedet for det forrige:

$query = sprintf("INSERT INTO brugere(brugernavn, password, facebook, soundcloud, land, profiltekst, djnavn, email, site, fk_musik_info, profilbillede) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", mysql_real_escape_string($brugernavn), mysql_real_escape_string($password), mysql_real_escape_string($facebook), mysql_real_escape_string($soundcloud), mysql_real_escape_string($land), mysql_real_escape_string($profiltekst), mysql_real_escape_string($djnavn), mysql_real_escape_string($email), mysql_real_escape_string($site), mysql_real_escape_string($fk_id), mysql_real_escape_string($billedefilnavn));

Dette sørger for at al data du sender til databasen er renset.


Derudover så ser det ud til at problemet ligget på linje 20, hvor du siger:
$handle = new Upload($_FILES['file']);


For at kunne sige hvad der er galt, er du nødt til at lige at skrive din form der sender data.
Avatar billede tobrukDk Novice
11. februar 2012 - 17:27 #4
Frem siger staden den sammem fejl :(


<form action="opretbruger_info.php" method="post" onsubmit="return validatePasswords()">
            <div id="boxinfo">
                <!-- bruger infomation-->
                <p>Brugerinfomation</p>
                <input type="text" name="brugernavn" placeholder="Brugernavn" id="formboxprofil">
                <br>
                <input type="password" id="password" name="password" placeholder="Password">
                <br />
                <input type="password" id="gentag" name="gentag" placeholder="Gentag password">
                <br />
                <input type="text" name="email" placeholder="Email til Booking" id="formboxprofil">
            </div>
            <div id="boxinfo2">
                <!-- Dj infomation-->
                    <p>Dj infomation</p>
                    <input type="text" name="site" placeholder="Website Navn" id="formboxprofil">
                    <br>
                    <input type="text" name="facebook" placeholder="Facebook" id="formboxprofil">
                    <br>
                    <input type="text" name="soundcloud" placeholder="Soundcloud" id="formboxprofil">
                    <br>
                    <input type="text" name="djnavn" placeholder="Dj Navn" id="formboxprofil">
                    <br>
                    <input type="text" name="land" placeholder="Hvor kommer du fra" id="formboxprofil">
                    <br>
                            <?php
                                    $sql = 'SELECT * FROM musik_info';
                                    $res = mysql_query($sql) or die (mysql_error());
                                    $select = '<select name="kategori">';
                                    while ($row=mysql_fetch_assoc($res)) {
                                    $select .= '<option value="'.$row['musikid'].'">'.$row['navn_musik'].'</option>';
                                    }
                                    $select .= '</select>';
                                    print $select;
                            ?>
            </div>
        <!-- Profil Tekst-->
            <div id="boxinfo3">
                <p>Profil Tekst</p>
                <textarea name="profiltekst" id="profiltekst" style="width:410px; height:155px;"></textarea>
                <input type="file" name="file" id="uploadfile"><br>
                <input type="submit" value="Godkendt & Opret Bruger" id="godkendt_bruger">
            </div>
    </form> 







<?php
include("include/database/database.php");

//Infomation
$brugernavn = $_POST["brugernavn"];
$password = $_POST["password"];
$gentag = $_POST["gentag"];
$facebook = $_POST["facebook"];
$soundcloud = $_POST["soundcloud"];
$land = $_POST["land"];
$profiltekst = $_POST["profiltekst"];
$djnavn = $_POST["djnavn"];
$email = $_POST["email"];
$site = $_POST["site"];
$fk_id = $_POST["kategori"];
$errorCount = 0;

include("include/class.upload.php");

$handle = new Upload($_FILES['file']);

if($handle->uploaded){
   
        //lidt mere store billeder
        $handle->image_resize = true;
        $handle->image_ratio_y = true;
        $handle->image_x = 220;
        $handle->Process("picthumb/storeimg");
       
        //til profil billede lign..
            $handle->image_resize = true;
            $handle->image_ratio_crop = true;
            $handle->image_y = 75;
            $handle->image_x = 75;
            $handle->Process("picthumb");
                       
$billedefilnavn = $handle->file_dst_name;

    echo "Dit billede blev upload";
   
}else {
    echo "Fejl; Du skal uploade en fil";
}

if($brugernavn == "")
{
    echo "Du skal indtaste et brugernavn.<br>";
    $errorCount++;
}
if($password == "")
{
    echo "Du skal indtaste et password.<br>";
    $errorCount++;
}
if($gentag == "" || $gentag != $password)
{
    echo "De to passwordfelter skal have ens indhold.<br>";
    $errorCount++;
}

include("include/database/database.php");

         
    $password = sha1($password);
$insert = mysql_query("INSERT INTO brugere (brugernavn,password,facebook,soundcloud,land,profiltekst,djnavn,email,site,fk_musik_info,profilbillede) VALUES ('$brugernavn','$password','$facebook','$soundcloud','$land','$profiltekst','$djnavn','$email','$site','$fk_id','$billedefilnavn')");
   
    if(!$insert) {
        echo "<a href='index.php'>forside</a>";
    }
    else {
      echo "<a href='index.php'>forside</a>";
    }

?>           
Avatar billede Broxigar Praktikant
11. februar 2012 - 18:18 #5
Når man laver fil-upload gennem en html form, så skal formen have: enctype="multipart/form-data"

så din form skal starte med
<form action="opretbruger_info.php" enctype="multipart/form-data"  method="post" onsubmit="return validatePasswords()">

Prøv og se om det fixer det
Avatar billede tobrukDk Novice
11. februar 2012 - 21:14 #6
sådan her nu

<form action="opretbruger_info.php" enctype="multipart/form-data"  method="post" onsubmit="return validatePasswords()">
            <div id="boxinfo">
                <!-- bruger infomation-->
                <p>Brugerinfomation</p>
                <input type="email" id="email" name="email" placeholder="Email til Booking">
                <br>
                <input type="password" id="password" name="password" placeholder="Password">
                <br />
                <input type="password" id="gentag" name="gentag" placeholder="Gentag password">
            </div>
            <div id="boxinfo2">
                <!-- Dj infomation-->
                    <p>Dj infomation</p>
                    <input type="text" name="site" placeholder="Website Navn" id="formboxprofil">
                    <br>
                    <input type="text" name="facebook" placeholder="Facebook" id="formboxprofil">
                    <br>
                    <input type="text" name="djnavn" placeholder="Dj Navn" id="formboxprofil">
                    <br>
                    <input type="text" name="land" placeholder="Hvor kommer du fra" id="formboxprofil">
                    <br>
                            <?php
                                    $sql = 'SELECT * FROM musik_info';
                                    $res = mysql_query($sql) or die (mysql_error());
                                    $select = '<select name="kategori">';
                                    while ($row=mysql_fetch_assoc($res)) {
                                    $select .= '<option value="'.$row['musikid'].'">'.$row['navn_musik'].'</option>';
                                    }
                                    $select .= '</select>';
                                    print $select;
                            ?>
            </div>
        <!-- Profil Tekst-->
            <div id="boxinfo3">
                <p>Profil Tekst</p>
                <textarea name="profiltekst" id="profiltekst" style="width:410px; height:155px;"></textarea>
                <input type="file" name="file" id="uploadfile"><br>
                <input type="submit" value="Godkendt & Opret Bruger" id="godkendt_bruger">
            </div>
    </form>


<?php
include("include/database/database.php");

//Infomation
$password = $_POST["password"];
$gentag = $_POST["gentag"];
$facebook = $_POST["facebook"];
$land = $_POST["land"];
$profiltekst = $_POST["profiltekst"];
$djnavn = $_POST["djnavn"];
$email = $_POST["email"];
$site = $_POST["site"];
$fk_id = $_POST["kategori"];
$errorCount = 0;

include("include/class.upload.php");

$handle = new Upload($_FILES['file']);

if($handle->uploaded){
   
        //lidt mere store billeder
        $handle->image_resize = true;
        $handle->image_ratio_y = true;
        $handle->image_x = 220;
        $handle->Process("picthumb/storeimg");
       
        //til profil billede lign..
            $handle->image_resize = true;
            $handle->image_ratio_crop = true;
            $handle->image_y = 75;
            $handle->image_x = 75;
            $handle->Process("picthumb");
                       
$billedefilnavn = $handle->file_dst_name;

    echo "Dit billede blev upload";
   
}else {
    echo "Fejl; Du skal uploade en fil";
}

if($email == "")
{
    echo "Du skal indtaste et brugernavn.<br>";
    $errorCount++;
}
if($password == "")
{
    echo "Du skal indtaste et password.<br>";
    $errorCount++;
}
if($gentag == "" || $gentag != $password)
{
    echo "De to passwordfelter skal have ens indhold.<br>";
    $errorCount++;
}

include("include/database/database.php");

         
$password = sha1($password);
$insert = mysql_query("INSERT INTO brugere (email,password,facebook,land,profiltekst,email,site,fk_musik_info,profilbillede) VALUES ('$email','$password','$facebook','$land','$profiltekst','$djnavn','$site','$fk_id','$billedefilnavn')");
   
    if(!$insert) {
        echo "<a href='index.php'>forside</a>";
    }
    else {
      echo "<a href='index.php'>forside</a>";
    }

?>
Avatar billede Broxigar Praktikant
11. februar 2012 - 21:15 #7
Ja, jeg vil tro at det virker. Sig lige til hvis det ikke fungerer.
Avatar billede tobrukDk Novice
11. februar 2012 - 21:27 #8
Det virker fint nok lige nu men det er sådan at den ikke gider lige sig ind på databasen altså email og password og billedet osv... :(

sådan her ser min database ude ;

http://jesperbok.dk/skoleopgave/db.png
Avatar billede Broxigar Praktikant
11. februar 2012 - 21:35 #9
Du har 2 x email i
"INSERT INTO brugere (email,password,facebook,land,profiltekst,email,site,fk_musik_info,profilbillede)

prøv og sætte dette efter din $insert-linje:

or die(mysql_error());

således at du får en fejlmeddelelse når den laver fejl i dit query.
Avatar billede tobrukDk Novice
11. februar 2012 - 22:00 #10

$password = sha1($password);
$insert = mysql_query("INSERT INTO brugere (email,password,facebook,land,profiltekst,email,site,fk_musik_info,profilbillede) VALUES ('$email','$password','$facebook','$land','$profiltekst','$djnavn','$site','$fk_id','$billedefilnavn')") or die (mysql_errno());


Fejl siger ;


Fejl; Du skal uploade en filDu skal indtaste et brugernavn.

Notice: Undefined variable: billedefilnavn in C:\xampp\htdocs\djinfo\opretbruger_info.php on line 63
Avatar billede tobrukDk Novice
12. februar 2012 - 00:45 #11

<?php
  include("include/database/database.php");
 
  //Infomation
  $email = $_POST["email"];
  $password = $_POST["password"];
  $gentag = $_POST["gentag"];
  $facebook = $_POST["facebook"];
  $land = $_POST["land"];
  $profiltekst = $_POST["profiltekst"];
  $djnavn = $_POST["djnavn"];
  $site = $_POST["site"];
  $fk_id = $_POST["kategori"];
  $errorCount = 0;
 
  $billedefilnavn = null;
 
  include("include/class.upload.php");
 
  $handle = new Upload($_FILES['file']);
 
  if($handle->uploaded){
     
          //lidt mere store billeder
          $handle->image_resize = true;
          $handle->image_ratio_y = true;
          $handle->image_x = 220;
          $handle->Process("picthumb/storeimg");
         
          //til profil billede lign..
              $handle->image_resize = true;
              $handle->image_ratio_crop = true;
              $handle->image_y = 75;
              $handle->image_x = 75;
              $handle->Process("picthumb");
                         
  $billedefilnavn = $handle->file_dst_name;
 
      echo "Dit billede blev upload<br>";
     
  }else {
      echo "Fejl; Du skal uploade en fil<br>";
  }
 
  if($email == "")
  {
      echo "Du skal indtaste et Email som brugernavn.<br>";
      $errorCount++;
  }
  if($password == "")
  {
      echo "Du skal indtaste et password.<br>";
      $errorCount++;
  }
  if($gentag == "" || $gentag != $password)
  {
      echo "De to passwordfelter skal have ens indhold.<br>";
      $errorCount++;
  }
 
  include("include/database/database.php");
 
           
  $password = sha1($password);
  $insert = mysql_query("INSERT INTO brugere (email,password,facebook,land,profiltekst,email,site,fk_musik_info,profilbillede) VALUES ('$email','$password','$facebook','$land','$profiltekst','$djnavn','$site','$fk_id','$billedefilnavn')") or die (mysql_errno());
     
      if(!$insert) {
          echo "<a href='index.php'>forside</a>";
      }
      else {
        echo "<a href='index.php'>forside</a>";
      }
 
  ?>


har selv klart den! :
Avatar billede Broxigar Praktikant
12. februar 2012 - 10:23 #12
Prøv nu lige at se hvad der bliver lagt i databasen, for med den kode som du har stående i sidste post, så bliver det forkert.

1: Du ved ikke om $billedefilnavn er null eller det rigtige navn når du sætter det ind i databasen

2: Du sætter $email ind i email, og $djnavn ind i email i din query.
Du kan evt. bruge mit forslag til et nyt query længere oppe. Der får du renset alt input således at SQL injections ikke er mulige.
Avatar billede tobrukDk Novice
12. februar 2012 - 20:14 #13
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester