tags:

views:

32

answers:

1
    CREATE TABLE IF NOT EXISTS `Channels` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(30) NOT NULL,
  `commercial` tinyint(1) NOT NULL DEFAULT '0',
  `usrid` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;


INSERT INTO `Channels` (`id`, `name`, `commercial`, `usrid`) VALUES
(2, 'ORF 1', 0, 0);

PHP:

<?php
  if (isset($_POST['name'])){
    mysql_connect("localhost", "test", "test") or die(mysql_error());
    mysql_select_db("test") or die(mysql_error());
    $tmp = mysql_query("SELECT commercial 
                          FROM Channels 
                         WHERE name='".mysql_real_escape_string($_POST['name'])."'");
    $row = mysql_fetch_row($tmp);
    echo $row['commercial'];
  }
  else
  {
    ?>
    <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
      <input name="name" type="text">
      <input type="submit" name="submit" value="submit" >
    </form>
    <?php
  }
?>

There is no output when I submit "ORF 1".

A: 

It's vital that you learn to employ basic debugging techniques:

Instead of this:

$tmp = mysql_query("SELECT commercial FROM Channels WHERE 
    name='".mysql_real_escape_string($_POST['name'])."'");
$row = mysql_fetch_row($tmp);
echo $row['commercial'];

do this:

$tmp = mysql_query("SELECT commercial FROM Channels WHERE 
    name='".mysql_real_escape_string($_POST['name'])."'");

// Make sure the query was successful
if (false === $tmp) {
   die("Query failed: " . mysql_error());
}

$row = mysql_fetch_row($tmp);

// Don't assume a row was returned
var_dump($row);
meagar