I have my index code which is basically the page that appear and if a user is public can so the cd database but not modify it, if they want to modify it they have to register or login if the already have an account. My problem is on my send code where the new details for the cd are not being inserted in the table although i am already logged in my account (the user table is created and the details for the users are inserted in the way they have to be). It's like it doesnt get the username and the artist i post. When i echo the variables to see their values i get undefine variables errors. Any help would be extremely appreciated.
index
<?php
include 'header.php';
if ( isset( $_SESSION[ 'username' ] ) ) {
?>
<h2>New cd</h2>
<form action="send.php" method="post">
<div class="text">
Artist <br/>
<textarea name="artist"></textarea>
<br/>
Title <br/>
<textarea name="title"></textarea>
</div>
<input type="submit" value="OK" class='submit' />
</form>
<?php
}
else {
?>
<p>
To modify the database, <a href="login.php">login</a>.
</p>
<p>
To create a new account, <a href="register.php">register</a>.
</p>
<?php
}
?>
for some reason i cant upload the rest of this file but basically it shows the table with the details of the cds, if the user is logged in can see the usernames column too, if they are public then they can see only the cd artist and title columns.
send code
<?php
include 'prelude.php';
if ( isset( $_SESSION[ 'username' ] ) && isset( $_POST[ 'cdartist' ] )) {
$cdartist = $_POST[ 'cdartist' ];
$cdtitle= $_POST['cdtitle'];
$userid=$_SESSION['userid'];
$res=mysql_query(
" SELECT *
FROM cds
WHERE cdartist='".$cdartist."' AND cdtitle='".$cdtitle."';"
);
if (mysql_num_rows($res)!=0){
mysql_query(
"DELETE FROM cds
WHERE cdartist='".$cdartist."' AND cdtitle='".$cdtitle."' AND userid='".$userid."';");
header ('Location: index.php');
}
else{
mysql_query(
"INSERT INTO cds
SET
cdartist = '" . $cdartist . "',
cdtitle = '". $cdtitle . "',
userid = '" . $userid . "';"
);
}
header( 'Location: index.php' );
}
else {
?> To have this right you need to login. <?php
}
?>