Thank you, SoN9ne! It works now! I have some other trouble with the functionality but I think I can fix it. :) If not, I'm gonna post it in this thread so we padawans can learn something. :)
EDIT: About the sanitization, I'm gonna work something out, thanks for pointing that out. :) I'm still learning that concept and don't know how to use it properly.
Again, thank you.
EDIT 2:
I have another bug in the process of creating a new album:
Quote
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in (the bold line below in the code)
Here's the code:
// Create a new album
public static function create_new_album(){
// Albums new name
$album_name = addslashes(htmlentities(htmlspecialchars($_REQUEST ['album_name'])));
// If there's nothing entered, display an error
if ($album_name == "")
{
die ("Please enter your album's name!");
}
$sql = "SELECT * FROM albums WHERE name ' ".mysql_real_escape_string ($album_name). "'";
$query = mysql_query ($sql);
// Check if there any albums named like this
[B]if (mysql_num_rows($query)>0) [/B]
{
die ("This name is already in use! Please choose another name.");
}
else {
// if the name is not in use, insert into db
$sql = "INSERT INTO albums (name) VALUES ('".$album_name."')";
$query = mysql_query($sql);
if (!$query) {
die ("Cannot create a new album");
}
else {
$sql= "SELECT * FROM albums WHERE name=' ".mysql_real_escape_string($album_name)."'";
$query = mysql_query($sql);
if (!$query) {
die (mysql_error());
}
else {
$row = mysql_fetch_array($query);
$album_id = $row ['id'];
}
// if album was successfully create, display message
echo "Album Create! <a href='album_panel.php?act=view&id=".$id."'>View</a>";
}
album_name is entered via HTML form:
Album name: <input type='text' name='album_name' /><input type='submit' value='Create' />
But, the table in the DB is
albums and the name row is
name, not album_name. I've tried changing it, supposing that's the problem, but still doesn't work.
Thanks.
Edited by Padawan, 12 December 2011 - 09:30 AM.