Jump to content

[SOLVED] Unknown column 'test' in 'field list'?!?


Recommended Posts

Ok, so I am having some user-inputed data inserted into the table "nav_links" and it outputs this error:

 

Unknown column 'h' in 'field list'

 

I have got the area down to this piece of code.

 

elseif($_GET['do'] == 'add_link')
{
$id = $_GET['cat'];
if($_GET['go']=='true')
	{
	$link_name = $_POST['link_name'];
	$url = $_POST['url'];

	if(empty($link_name))
		{
		$error_txt = 'Enter a link title.';
		}
	elseif(empty($url))
		{
		$error_txt = 'Enter a URL.';
		}
	else
		{
		$max = mysql_query('SELECT MAX(id) FROM nav_links');
		$max_array = mysql_fetch_array($max);
		$max_id = $max_array['MAX(id)'] +1;
		$query = mysql_query('INSERT INTO `nav_links` (`id` ,`cat_id` ,`url` ,`name`) VALUES ('.$max_id.', '.$id.', '.$url.', '.$link_name.')');
		if($query)
			{
			$error_txt = 'Link Added Successfully.';
			}
		else
			{
			$error_txt = mysql_error();
			}
		}
	}

 

Any help?

 

Thanks in advance,

 

~Shaun

Link to comment
https://forums.phpfreaks.com/topic/66044-solved-unknown-column-test-in-field-list/
Share on other sites

I don't see anything obvious with that particular snippet, except that the entire query is in single quotes while you have single quotes around the text elements in the query.  I'd try putting the query itself in double quotes.  

 

For troubleshooting purposes, it's also a good thing to do this:

 

$query = "insert into (COLUMN) VALUES (blah)";

$result = mysql_query($query);

echo"<BR>  The attempted query was $query";

 

That will let you see what is being sent to mysql.  You can comment out or delete the echo line once you verify the page is working as intended.

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.