Jump to content

trouble with inserting data the the database...


Noskiw

Recommended Posts

<?php

include('design/header.php');
require('connect.php');

$id = $_SESSION['id'];

$albumname = $_POST['albumname'];
$albumdescription = $_POST['albumdescription'];

if($albumdescription){
$create = mysql_query("INSERT INTO albums VALUES('','$id','$albumname','$albumdescription','0','images/nocover.jpg')");
echo "Album created!";
}

if($albumname){
echo "<table cellpadding='7' width='100%'>";
echo "<font face='arial'>";
echo "<tr>";
echo "<td>";
echo "Please give a description to the album: <b>" . $albumname . "</b>";
echo "<form action='createalbum.php' method='POST'>";
echo "<textarea name='description'></textarea><br />";
echo "<input type='submit' name='submit' value='Create Album' />";
echo "<input type='hidden' name'albumname' value='" . $albumname . "' />";
echo "</form>";
echo "</td>";
echo "</tr>";
echo "</font>";
echo "</table>";
}

include('design/footer.php');

?>

 

the problem is, is that nothing will go into my databse...

Is it printing out Album corrected to the screen? If not, the problem is with your condition IF statement. Although you shouldn't really be using that query style as it makes adding additional columns in the future a hazard. Do this:

 

$albumname = $_POST['albumname'];
$albumdescription = $_POST['albumdescription'];

if(strlen(trim($albumdescription)) > 0){
    $create = mysql_query("INSERT INTO albums VALUES('','$id','$albumname','$albumdescription','0','images/nocover.jpg')");
    echo "Album created!";
}

 

You should also be cleaning incoming POST variables with the function mysql_real_escape_string before inserting them into your query.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.