gathos Posted December 8, 2008 Share Posted December 8, 2008 ok so i have a database setup and running, i have the correct username and password. and all variables can be echoed and they are correct. every time i try to add a new entry to the database it says "An error occured during insert!" i made it say that when the data would not enter, but i can't see WHY it's not entering. please help, i am so confused as to why this isn't working <?php $_COOKIE['cookiename']; $pass = $_COOKIE['cookiename']; $name = $_POST['name']; $sdesc = $_POST['sdesc']; $desc = $_POST['desc']; if ($pass == mypassword) { mysql_connect("localhost", "username", "mypassword") or die(mysql_error()); mysql_select_db("imgdb") or die(mysql_error()); $sql = "INSERT INTO img (name, sdesc, desc) VALUES ('$name', '$sdesc', '$desc')"; $result = mysql_query($sql); if ($result) { echo "Your entry was added to the database!<br/>"; } else { echo "An error occured during insert!<br/>"; } } else { echo 'sorry you have not entered the correct password to access the databse <br> please go back to the <a href="login.php">login page</a>'; }; ?> i am really confused, please help Link to comment https://forums.phpfreaks.com/topic/136105-solved-problem-adding-entry-to-database/ Share on other sites More sharing options...
wildteen88 Posted December 8, 2008 Share Posted December 8, 2008 To see why your query failed use mysql_error after this line: echo "An error occured during insert!<br/>"; However looking at you code, it could be failing because you're using a MySQL reserved word within your query which is desc. But until we see the true error we cant suggest a fix. Link to comment https://forums.phpfreaks.com/topic/136105-solved-problem-adding-entry-to-database/#findComment-709690 Share on other sites More sharing options...
Brian W Posted December 8, 2008 Share Posted December 8, 2008 please try ... else { echo "An error occured during insert!<br/>"; echo $sql."<br/>"; } that might help in trouble shooting cuz it will show you what is trying to ran. Link to comment https://forums.phpfreaks.com/topic/136105-solved-problem-adding-entry-to-database/#findComment-709693 Share on other sites More sharing options...
gathos Posted December 8, 2008 Author Share Posted December 8, 2008 yeah the desc was the problem. when you mentioned it, i remembered that i had the same problem 6 months ago, and i completely forgot that it was a reserved word. thank you very much. later days, gathos Link to comment https://forums.phpfreaks.com/topic/136105-solved-problem-adding-entry-to-database/#findComment-709716 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.