Jump to content

Recommended Posts

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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.