Hey,
I'm having a problem in PHP with mysqli. I'm working under Ubuntu 14.04.
I need to fill a table with data of a DB.
This is how the DB is created:
And this is my PHP code.
But somehow it doesn't work, I don't know why, i could just figure it out that after execute() the php-script crashes because nothing gets displayed out, I also tried echos after $stmt->execute(); but nothing gets printed out, thats why I think that the php-script crashes.
I hope you can help me.
I'm having a problem in PHP with mysqli. I'm working under Ubuntu 14.04.
I need to fill a table with data of a DB.
This is how the DB is created:
Code:
DROP DATABASE IF EXISTS premiere;
CREATE DATABASE premiere;
USE premiere;
-- DROP TABLE IF EXISTS sender;
CREATE TABLE sender (
sname VARCHAR(255),
logo VARCHAR(255),
PRIMARY KEY (sname)
) ENGINE = INNODB;
INSERT INTO sender VALUES ('13TH STREET', NULL);
INSERT INTO sender VALUES ('MGM', NULL);
INSERT INTO sender VALUES ('PREMIERE 1', NULL);
INSERT INTO sender VALUES ('PREMIERE 2', NULL);
INSERT INTO sender VALUES ('PREMIERE 3', NULL);
INSERT INTO sender VALUES ('PREMIERE 4', NULL);
INSERT INTO sender VALUES ('PREMIERE FILMCLASSICS', NULL);
INSERT INTO sender VALUES ('PREMIERE FILMFEST', NULL);
INSERT INTO sender VALUES ('PREMIERE KRIMI', NULL);
INSERT INTO sender VALUES ('PREMIERE NOSTALGIE', NULL);
INSERT INTO sender VALUES ('PREMIERE SERIE', NULL);
INSERT INTO sender VALUES ('PREMIERE START', NULL);
INSERT INTO sender VALUES ('SCI FI', NULL);
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>channels.php</title>
</head>
<body>
<h1 style="font-size: 30px;">Channels</h1>
<table style="font-size: 15px;" border="1">
<tr>
<th><a href="channels.php?order=1&dir=<?php if($_GET['dir'] == 'ASC'){ $_GET['dir'] = 'DESC';}else{ $_GET['dir'] = 'ASC';} echo $_GET['dir'];?>">Sendername</a></th>
<th><a href="channels.php?order=2&dir=<?php if($_GET['dir'] == 'ASC'){ $_GET['dir'] = 'DESC';}else{ $_GET['dir'] = 'ASC';} echo $_GET['dir'];?>">Logo</a></th>
</tr>
<?php
$db = new mysqli('localhost', 'username', 'password', 'premiere');
if(isset($_GET['order']) && isset($_GET['dir']))
{
if($_GET['order'] == '1')
{
$sql = 'SELECT * FROM sender ORDER BY sname '.$_GET['dir'].' FOR UPDATE;';
}elseif($_GET['order'] == '2')
{
$sql = 'SELECT * FROM sender ORDER BY logo '.$_GET['dir'].' FOR UPDATE;';
}
}else
{
$sql = 'SELECT * FROM sender FOR UPDATE;';
}
$stmt = $db->prepare($sql);
$stmt->execute();
$stmt->bind_result($senderName, $logo);
while($stmt->fetch())
{
echo '<tr>';
echo '<td>'.$senderName.'</td>';
echo '<td>'.$logo.'</td>';
echo '</tr>';
}
$stmt->close();
?>
</table>
</body>
</html>
I hope you can help me.