Page 1 of 1

[SOLVED]Checking Existance

Posted: Sun Jan 11, 2004 5:49 pm
by Straterra
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
     }
?>

Posted: Sun Jan 11, 2004 6:02 pm
by microthick
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.

Posted: Sun Jan 11, 2004 6:03 pm
by Straterra
I don't have ANY tags like those in any of my websites, and they load up just fine.

Posted: Sun Jan 11, 2004 6:13 pm
by Straterra
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);
  }
?>
?>

Posted: Sun Jan 11, 2004 7:14 pm
by d3ad1ysp0rk

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..

Posted: Sun Jan 11, 2004 8:03 pm
by Straterra
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.