1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP newbie in trouble - who can help

Discussion in 'PHP' started by antpeks, Apr 8, 2011.

  1. #1
    i get this error:

    Notice: Undefined index: product in /home/XXXXX/domains/XXXX/public_html/procces/proc_add_product.php on line 38
    Error, query failed : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') VALUES ('', 'Sauzen', 'Heinz', ' at line 1

    this is the line:

    <?php
    $result = @mysql_query("SELECT categorie FROM producten_categorie");
    
    echo  '<label for="categorie">Categorie</label>';
    echo '<select name="categorie">'.PHP_EOL;
    while ($row = mysql_fetch_assoc($result))
    {
    	  echo '<option value="'.$row['categorie'].'">'.$row['categorie'].'</option>'.PHP_EOL;
    }        
    echo '</select>'.PHP_EOL;
    echo '</p>'.PHP_EOL;
    ?>
    
    PHP:
    thanks in advance....
     
    antpeks, Apr 8, 2011 IP
    b.devroey likes this.
  2. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #2
    this isn't whole script, because you're inserting somewhere
     
    G3n3s!s, Apr 8, 2011 IP
  3. Sepehr

    Sepehr Peon

    Messages:
    568
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #3
    As the message says the problem is here:

    /home/XXXXX/domains/XXXX/public_html/procces/proc_add_product.php on line 38

    Also it seems to be an SQL problem rather than a PHP one.
     
    Sepehr, Apr 9, 2011 IP
    b.devroey likes this.
  4. b.devroey

    b.devroey Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    This is the complete source code, I have been able to solve the previous error.
    but I stuck with this message:
    Error, query failed: Column Count Does not match value count at row 1

    form file
    -------------
    
    <link href="formstijl.css" rel="stylesheet" type="text/css">
    <h1>
      <legend>Nieuw Product:</legend>
    </h1>
    <?php
    include 'db_config.php';
    ?>
    <div id="stylized" class="formstyle-1">
    <form action="/procces/proc_add_product.php" method="POST" enctype="multipart/form-data">
      <p>Velden gemarkeerd met <em>*</em> zijn verplicht!</p>
      <fieldset>
             <label for="product">Naam het product<em>*</em>
                      <span class="small">Verplicht veld</span></label>
                      <input id="product" name="product" />
    
    <?php
    $result = @mysql_query("SELECT categorie FROM producten_categorie");
    
    echo  '<label for="categorie">Categorie</label>';
    echo '<select name="categorie">'.PHP_EOL;
    while ($row = mysql_fetch_assoc($result))
    {
          echo '<option value="'.$row['categorie'].'">'.$row['categorie'].'</option>'.PHP_EOL;
    }        
    echo '</select>'.PHP_EOL;
    echo '</p>'.PHP_EOL;
    ?>
          
     <?php
    $result = @mysql_query("SELECT leverancier FROM producten_leverancier");
    
    echo  '<label for="leverancier">Leverancier</label>';
    echo '<select name="leverancier">'.PHP_EOL;
    while ($row = mysql_fetch_assoc($result))
    {
          echo '<option value="'.$row['leverancier'].'">'.$row['leverancier'].'</option>'.PHP_EOL;
    }        
    echo '</select>'.PHP_EOL;
    echo '</p>'.PHP_EOL;
    ?>
    
                      
            <label for="beschrijving">Beschrijving</label>
                      <textarea id="beschrijving" name="beschrijving"></textarea>
                      
    <?php
    $result = @mysql_query("SELECT verpakking FROM producten_verpakking");
    
    echo  '<label for="verpakking">Verpakking</label>';
    echo '<select name="verpakking">'.PHP_EOL;
    while ($row = mysql_fetch_assoc($result))
    {
          echo '<option value="'.$row['verpakking'].'">'.$row['verpakking'].'</option>'.PHP_EOL;
    }        
    echo '</select>'.PHP_EOL;
    echo '</p>'.PHP_EOL;
    ?>
    
    <?php
    $result = @mysql_query("SELECT eenheid FROM producten_eenheid");
    
    echo  '<label for="eenheid">E&eacute;nheid</label>';
    echo '<select name="eenheid">'.PHP_EOL;
    while ($row = mysql_fetch_assoc($result))
    {
          echo '<option value="'.$row['eenheid'].'">'.$row['eenheid'].'</option>'.PHP_EOL;
    }        
    echo '</select>'.PHP_EOL;
    echo '</p>'.PHP_EOL;
    ?>
    
    
            <label for="opmerking">Opmerking</label>
                      <textarea id="opmerking" name="opmerking"></textarea>
        
            <label for="product_url">Meer info<em></em>
                      <span class="small">voorafgaande van http://</span></label>      
                      <input id="product_url" name="product_url" />
    
            <label for="order_url">Bestellen<em></em>
                      <span class="small">voorafgaande van http://</span></label>
                      <input id="order_url" name="order_url" />
    
            <label for="file">Logo<em></em>
                      <span class="small">Max. 4mb</span></label>
                       <input name="userfile" type="file" id="userfile">
    
        <input name="upload" type="submit" class="box" id="upload" value=" Verzenden ">
        <div class="spacer"></div>
      </fieldset>
    </form>
    </div> 
    
    Code (markup):


    Procces file
    -------------
    
    <?php
    ini_set('display_errors', 'On');
    error_reporting(E_ALL | E_STRICT);
    if ($_SERVER['REQUEST_METHOD'] == "POST") 
     // Configuratie
    $allowed_filetypes = array('.jpg','.jpeg','.gif','.bmp','.png');
    $max_filesize = 4194304; // 4mb
    $upload_path = '../images/producten/'; 
    
    $filename = $_FILES['userfile']['name']; // Verkrijg userfilesnaam en extentie.
    $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Verkrijg userfile extentie.
     
    // Bekijk of het bestandsextentie is toegelaten.
    if(!in_array($ext,$allowed_filetypes))
    	die('Bestandsextentie is niet toegelaten.');
    
    // Nakijken van de max_filesize.
    if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
    	die('Het bestand is te groot.');
    
    // nakijken of de doelmap schrijfbaar is.
    if(!is_writable($upload_path))
    	die('Doelmap is niet schrijfbaar, gelieven de CHMOD te veranderen naar 777.');
    
    // Bestandscontrole op identieke namen.
    if (file_exists("$upload_path" . "$filename")) { 
    $random_digit=rand(0000,9999);
    $filename=$random_digit.$filename;
    }
    else {
    $filename = $_FILES['userfile']['name'];
    }
    // Directory target.
    $target = $upload_path .$filename;
    
    // Schrijf data naar mysql database.
    include '../db_config.php';
    	$fileName = $_FILES['userfile']['name'];
    	$tmpName = $_FILES['userfile']['tmp_name'];
    	$fileSize = $_FILES['userfile']['size'];
    	$fileType = $_FILES['userfile']['type'];
    	$query = "INSERT INTO producten_leverancier (product, categorie, leverancier, beschrijving, eenheid, verpakking, opmerking, product_url, order_url, name, size, type, path)".
    	 	     "VALUES ('".mysql_real_escape_string($_POST['product'])."',
    				   	  '".mysql_real_escape_string($_POST['categorie'])."',
    					  '".mysql_real_escape_string($_POST['leverancier'])."',
    					  '".mysql_real_escape_string($_POST['beschrijving'])."',
    					  '".mysql_real_escape_string($_POST['opmerking'])."',
    					  '".mysql_real_escape_string($_POST['verpakking'])."'
    					  '".mysql_real_escape_string($_POST['eenheid'])."'
    					  '".mysql_real_escape_string($_POST['product_url'])."'
    					  '".mysql_real_escape_string($_POST['order_url'])."'
    					  '".mysql_real_escape_string($fileName)."',
                  		  '".mysql_real_escape_string($fileSize)."',
                  		  '".mysql_real_escape_string($fileType)."',
                  		  '".mysql_real_escape_string($upload_path . $filename)."')";  
    
    		mysql_query($query) or die('Error, query failed : ' . mysql_error());
    include '../db_close.php';
    
    // Upload het bestand.
    if(move_uploaded_file($_FILES['userfile']['tmp_name'], $target))
    {
    
    // Slot besluit.
    echo "De ingevoerde gegevens zijn correct verstuurd.";
    }
    else {
      echo "<p>Er heeft zich een onbekende fout voorgedaan!</p>\n";
      }
    ?>
    
    Code (markup):
    I hope someone sees the problem ...
    Thanks in advance.
    Bart and Antpeks
     
    Last edited: Apr 9, 2011
    b.devroey, Apr 9, 2011 IP
  5. Sepehr

    Sepehr Peon

    Messages:
    568
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Are you the same guy? What's with the duplicate accounts?! :D

    Anyway your SQL has 9 columns but 12 variables! you probably forgot to put 3 of the columns!
     
    Sepehr, Apr 9, 2011 IP
  6. b.devroey

    b.devroey Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    No sorry, we are working together on the script and i follow the topic :rolleyes:
     
    b.devroey, Apr 9, 2011 IP
  7. b.devroey

    b.devroey Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    indeed i did missed some insert fields but i'm stil stuck with the same error: Error, query failed: Column Count Does not match value count at row 1...

    And al the fields are also in the form!

    I update the source above.
     
    b.devroey, Apr 9, 2011 IP
  8. Sepehr

    Sepehr Peon

    Messages:
    568
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I don't see any insert query in the updated code!
     
    Sepehr, Apr 9, 2011 IP
  9. b.devroey

    b.devroey Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Procces source updates (sorry)
     
    b.devroey, Apr 9, 2011 IP
  10. b.devroey

    b.devroey Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Sorry found the probleme i missed some ,,,,,,,,,,,,,,

    Kind regards,

    Thanxxx
     
    b.devroey, Apr 9, 2011 IP
  11. b.devroey

    b.devroey Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    SOLVED Thankx
     
    b.devroey, Apr 15, 2011 IP