Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2006
    Posts
    1

    Unanswered: Beginner: Variable Column

    Hey there,
    I'm just new with MySQL & PHP; but I'm learning it.
    What I am trying to make will be a adress database;
    with a button for extra information per adres.
    This I want to create with a variInable Customer ID.

    In table.php
    Code:
    .
    .
    print("<td valign=\"top\">
    <form action=\"adressenviewextra.php\" method=\"Get\">
    <input type=hidden name=Customer value=\"$Rij[Customer]\">
    <INPUT TYPE=SUBMIT VALUE=\"$Rij[Companyname]\">
    </td>\n");
    .
    .
    In extrainformation.php
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    	<title>Adressen Bekijken</title>
    </head>
    <body>
    <?php
    
    ini_set('display_errors', 1); 
    error_reporting(E_ALL); 
    
    if ( !isset( $_GET['Customer'] ) ) 
    { 
      // je mist een belangrijke var, niet verder gaan 
    } 
    else 
    { 
    
    $Customer = $_GET['Customer']; 
    
    //verbinding maken met de database
    include("includes/connect.php");
    
    $Ophalenadressen = 'SELECT `Customer`,`Companyname`,`Contactpersoon`,`Adres`,`PostcodePlaats`,`Land`,`Telefoon`,`Mobiel`,`Email`,`Homepage`,`Extra` FROM `adressen` WHERE 1 AND `Customer` = $Customer LIMIT 0, 1'; 
    $Resultaat = mysql_query($Ophalenadressen) or die(mysql_error());
    
    //ophalen gegevens
    print("<b>$Rij[Companyname]</b>($Rij[Customer])<br><br>\n");
    
    mysql_close($Verbinding);
    }
    ?>
    </body>
    </html>
    Anyway it doesnt work.
    I get a Unknown column '$Customer' in 'where clause'

    What am I doing wrong?

    Thanks
    Leonie

  2. #2
    Join Date
    Oct 2002
    Location
    Plymouth UK
    Posts
    116
    Not too sure about MySql but in most other db's you need quotes around the item in the where clause. So

    Code:
    ... AND `Customer` = $Customer LIMIT ...
    should be

    Code:
    ... AND `Customer` = '$Customer' LIMIT ...

  3. #3
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    If you want to use variables inside of strings, you must use double quotes.

    PHP Code:
    $Ophalenadressen "SELECT `Customer`,`Companyname`,`Contactpersoon`,`Adres`,`PostcodePlaats`,`Land`,`Telefoon`,`Mobiel`,`Email`,`Homepage`,`Extra` FROM `adressen` WHERE 1 AND `Customer` = $Customer LIMIT 0, 1"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •