Noskiw Posted August 27, 2009 Share Posted August 27, 2009 <?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... Link to comment https://forums.phpfreaks.com/topic/172210-trouble-with-inserting-data-the-the-database/ Share on other sites More sharing options...
waynew Posted August 27, 2009 Share Posted August 27, 2009 Debug your queries! $create = mysql_query("INSERT INTO albums VALUES('','$id','$albumname','$albumdescription','0','images/nocover.jpg')") or trigger_error(mysql_error()); Also, I wouldn't advise you to use that style of INSERT. Link to comment https://forums.phpfreaks.com/topic/172210-trouble-with-inserting-data-the-the-database/#findComment-907980 Share on other sites More sharing options...
gamesmstr Posted August 27, 2009 Share Posted August 27, 2009 For one, you need to tell it what fields to fill with those values. $create = mysql_query("INSERT INTO albums (field1,id,albumname,field2,image) VALUES ('','$id','$albumname','$albumdescription','0','images/nocover.jpg')"); Link to comment https://forums.phpfreaks.com/topic/172210-trouble-with-inserting-data-the-the-database/#findComment-907981 Share on other sites More sharing options...
Noskiw Posted August 27, 2009 Author Share Posted August 27, 2009 Still not working... I've done everything i can but it just will not work for me... Link to comment https://forums.phpfreaks.com/topic/172210-trouble-with-inserting-data-the-the-database/#findComment-907983 Share on other sites More sharing options...
gamesmstr Posted August 27, 2009 Share Posted August 27, 2009 have you set up the database? if so, you might want to list your table fields and the type of data it is expecting. For example: id = int albumname = varchar(20) etc. Link to comment https://forums.phpfreaks.com/topic/172210-trouble-with-inserting-data-the-the-database/#findComment-907984 Share on other sites More sharing options...
waynew Posted August 28, 2009 Share Posted August 28, 2009 Still not working... I've done everything i can but it just will not work for me... 1: Did you get any MySQL errors? 2: Is $albumdescription true (aka 1) when it's supposed to be? Link to comment https://forums.phpfreaks.com/topic/172210-trouble-with-inserting-data-the-the-database/#findComment-907986 Share on other sites More sharing options...
Noskiw Posted August 28, 2009 Author Share Posted August 28, 2009 no erros whatsoever... i'm going to rewrite it and see if this way works... Link to comment https://forums.phpfreaks.com/topic/172210-trouble-with-inserting-data-the-the-database/#findComment-907989 Share on other sites More sharing options...
waynew Posted August 28, 2009 Share Posted August 28, 2009 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. Link to comment https://forums.phpfreaks.com/topic/172210-trouble-with-inserting-data-the-the-database/#findComment-907991 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.