Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
Straterra
Forum Regular
Posts: 527 Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:
Post
by Straterra » Sun Jan 11, 2004 5:49 pm
I have the following code. When I try to input a song that already exists in the database, the screen should display " You have tried to add a song that is already in the Music Database..." and redirect back to the form page...but instead, all it does is display a white screen. When I try to input a song that hasn't already been entered into the database, everything works fine. Please have a look at me code and tell me what is wrong...
Code: Select all
<?php
include('banned.php');
?>
<?php
$tester = isset($_SESSION["username"]);
if ( $tester == false ) {
header("Location: loginform.php");
}
$dbname = 'eckmusic';
$artist = $_POST['artist'];
$artist = sqlite_escape_string($artist);
$songname = $_POST['songname'];
$songname = sqlite_escape_string($songname);
$user = $_SESSION["username"];
$user = sqlite_escape_string($user);
$dte = date("F j, Y, g:i a");
$dte = sqlite_escape_string($dte);
$url = $_POST['url'];
$url = sqlite_escape_string($url);
$cookiename = $artist.$songname;
if ($db = sqlite_open($dbname, 0666, $sqliteerror)){
$sql = "SELECT cookiename FROM music2 WHERE cookiename = '$cookiename'";
$sql_result = sqlite_query($db, $sql);
if (sqlite_num_rows($sql_result) != 1) {
sqlite_query($db, "insert into music2
(artist, songname, url, cookiename, dte, whoadded)
values ('$artist', '$songname', '$url', '$cookiename', '$dte', '$user')");
?>
<meta http-equiv="REFRESH" content=".1;URL=addmusic.php">
<?php
} else {
die ($sqliteerror);
}
} else {
?>
<body bgcolor="black">
<font color="white">
You have tried to add a song that is already in the Music Database...
<meta http-equiv="REFRESH" content="3;URL=addmusic.php">
<?php
}
?>
Last edited by
Straterra on Sun Jan 11, 2004 6:13 pm, edited 1 time in total.
microthick
Forum Regular
Posts: 543 Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC
Post
by microthick » Sun Jan 11, 2004 6:02 pm
Probably because the page won't show the error message since you haven't added <html><head><body> etc etc.
Also, since <meta> tags normally go strictly in the <head>, if you do display the error in <body> then add the <meta> it might not work.
Straterra
Forum Regular
Posts: 527 Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:
Post
by Straterra » Sun Jan 11, 2004 6:03 pm
I don't have ANY tags like those in any of my websites, and they load up just fine.
Straterra
Forum Regular
Posts: 527 Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:
Post
by Straterra » Sun Jan 11, 2004 6:13 pm
I have solved the problem. It was the if statements. I had them in the wrong order. Here is the working code if anyone in the future searches for something related to this topic...
Code: Select all
<?php
include('banned.php');
?>
<?php
$tester = isset($_SESSION["username"]);
if ( $tester == false ) {
header("Location: loginform.php");
}
$dbname = 'eckmusic';
$artist = $_POST['artist'];
$artist = sqlite_escape_string($artist);
$songname = $_POST['songname'];
$songname = sqlite_escape_string($songname);
$user = $_SESSION["username"];
$user = sqlite_escape_string($user);
$dte = date("F j, Y, g:i a");
$dte = sqlite_escape_string($dte);
$url = $_POST['url'];
$url = sqlite_escape_string($url);
$cookiename = $artist.$songname;
if ($db = sqlite_open($dbname, 0666, $sqliteerror)){
$sql = "SELECT cookiename FROM music2 WHERE cookiename = '$cookiename'";
$sql_result = sqlite_query($db, $sql);
if (sqlite_num_rows($sql_result) != 1) {
sqlite_query($db, "insert into music2
(artist, songname, url, cookiename, dte, whoadded)
values ('$artist', '$songname', '$url', '$cookiename', '$dte', '$user')");
?>
<meta http-equiv="REFRESH" content=".1;URL=addmusic.php">
<?php
} else {
?>
<body bgcolor="black">
<font color="white">
You have tried to add a song that is already in the Music Database...
<meta http-equiv="REFRESH" content="3;URL=addmusic.php">
<?php
}
} else {
die ($sqliteerror);
}
?>
?>
d3ad1ysp0rk
Forum Donator
Posts: 1661 Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA
Post
by d3ad1ysp0rk » Sun Jan 11, 2004 7:14 pm
Code: Select all
<?php
include('banned.php');
?>
<?php
$tester = isset($_SESSION["username"]);
any reason to go out and in of php like that?
and you can echo the meta tag so u can stay in php most of (or the whole time if you echo the rest too) your page..
Straterra
Forum Regular
Posts: 527 Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:
Post
by Straterra » Sun Jan 11, 2004 8:03 pm
Well, I build programs and add onto them..The ban thing came later..So at the top of all of my documents, I added the
<?php
include('banned.php');
?>
So that it would work very easily on all of my sites. Also, its easier for me to do that, than to escape and characters and stuff like that.