Forum Moderators: coopster

Message Too Old, No Replies

Trouble writing to MySQL DB

         

ffoeg

7:29 pm on Apr 24, 2006 (gmt 0)

10+ Year Member



Hey all. I'm having a spot of bother when trying to insert something into my MySQL database.

This is the code that I am using to insert it:


//GETTING THE FORM VARIABLES
$name = addslashes($_POST['name']);
$title = addslashes($_POST['title']);
$content = addslashes($_POST['content']);
$date = date("d-m-Y");
$url = addslashes($_POST['url']);
$descr = addslashes($_POST['descr']);
//SORTING OUT FROM WHERE EACH REQUEST COMES
$page = addslashes($_POST['page']);
switch ($page) {
case "links":
$query = mysql_query("INSERT INTO links(url,descr,name,date) VALUES ($url,$descr,$name,$date)");
echo mysql_error();
}

As you can see, I am first of all retrieving the values from the form, and then using those values to insert into the table.

This would work fine if it wasn't for one thing: I keep getting an error message. The error message goes something like this:
Unknown column 'fds' in 'field list', where 'fds' is the value that was inserted into the textbox.

I really need some help on this, as I soon will be without any hair due to my frustration.

Thanks in advance :)

eelixduppy

8:52 pm on Apr 24, 2006 (gmt 0)



Hello...

I would suggest making this line look like this:

$query = mysql_query("INSERT INTO links(url,descr,name,date) VALUES ('$url','$descr','$name','$date')");

MySQL is thinking that the values are column names and not text. Since that column name doesn't exist it comes up with an erorr. If adding this doesn't work please respond.

I hope this helps..

eelix

ffoeg

9:39 am on Apr 25, 2006 (gmt 0)

10+ Year Member



That worked just perfectly for me. Thanks soooo much :)