MySQL simple WHERE query .. cant find the mistake

Who could help me here. Am parsing values with Sessions … put them into vars and try to echo them …
It all works fine with :

$sql = "SELECT * FROM customers
WHERE c_company = ‘$cname’
";

but in the moment when I extend the WHERE-condition … the page stays blank !

$sql = " SELECT * FROM customers
WHERE
c_company = ‘$cname’ AND c_name = ‘$pname’
";

Here is the whole php-file:

<?php session_start(); $cname = $_SESSION["con"]; $fname = $_SESSION["fan"]; $pname = $_SESSION["prn"]; ?> Fast Fertig! <?php $server = 'www.website.at'; $user = 'user'; $pw = 'pw'; $db = 'database'; $verbindung = mysqli_connect($server, $user, $pw); if ($verbindung){ mysqli_select_db($verbindung, $db); if (mysqli_error($verbindung)){ echo 'Fehler: '.mysqli_error($verbindung); }else { $sql = " SELECT * FROM `customers` WHERE c_company = '$cname' AND c_name = '$pname' "; $abfrage = mysqli_query($verbindung, $sql); while($ev_rec = mysqli_fetch_assoc($abfrage)){ echo '
'; echo '
'; echo 'Kundennummer: 1963'.$ev_rec['iddb_customer'].'
'; echo '
Firma: '.$ev_rec['c_company'].'
'; echo '
Name: '.$ev_rec['c_famname']." ".$ev_rec['c_name'].'
'; echo '
'; echo '
'; echo '
'; } mysqli_free_result($abfrage); } }else { echo 'Verbindungsfehler: ' . mysqli_connect_error($verbindung); } mysqli_close($verbindung); /* echo 'Firma: '.$_POST['firmenname'].'
'; echo 'Name: '.$_POST['famname'].'
'; echo 'Vorname: '.$_POST['name'].'
'; */ session_destroy(); ?>

if the page is blank i suspect an error.
put this at the top
[php]<?php
ini_set(‘display_errors’, 1);
?>[/php]

or/and use
[php]<?php
or die(mysqli_error($verbindung))
?>[/php]
in the select query

Obviously these should not be left in on a live environment.
Red.

Edit:
On second glance i notice this:
[php]$sql = " SELECT * FROM customers[/php]

This ` and this ’ are not the same…
Unless you need to use backticks in your query, swap them for single quotes (or remove them completely) :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service