Shaun13 Posted August 21, 2007 Share Posted August 21, 2007 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 More sharing options...
lemmin Posted August 21, 2007 Share Posted August 21, 2007 Do you have an INSERT statement where you insert into a column named "h" somewhere? I don't see one in the code you posted. Link to comment https://forums.phpfreaks.com/topic/66044-solved-unknown-column-test-in-field-list/#findComment-330297 Share on other sites More sharing options...
jcanker Posted August 21, 2007 Share Posted August 21, 2007 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. Link to comment https://forums.phpfreaks.com/topic/66044-solved-unknown-column-test-in-field-list/#findComment-330299 Share on other sites More sharing options...
Shaun13 Posted August 21, 2007 Author Share Posted August 21, 2007 No, thats what I inputed as $link_name. Sorry, should have explained that. Link to comment https://forums.phpfreaks.com/topic/66044-solved-unknown-column-test-in-field-list/#findComment-330300 Share on other sites More sharing options...
lemmin Posted August 21, 2007 Share Posted August 21, 2007 jcanker is right. That string is being translated without quotes around the input values because of the single quotes. Changing the outside ones to double quotes would fix it, or putting slashes in front of the inner single quotes would work too. Link to comment https://forums.phpfreaks.com/topic/66044-solved-unknown-column-test-in-field-list/#findComment-330303 Share on other sites More sharing options...
Shaun13 Posted August 21, 2007 Author Share Posted August 21, 2007 Ok, now its inputing the literally "$id" into the database. How do I fix it? Link to comment https://forums.phpfreaks.com/topic/66044-solved-unknown-column-test-in-field-list/#findComment-330309 Share on other sites More sharing options...
lemmin Posted August 21, 2007 Share Posted August 21, 2007 You don't need the periods with double quotes: "INSERT INTO `nav_links` (`id` ,`cat_id` ,`url` ,`name`) VALUES ('$max_id', '$id', '$url', '$link_name.')" Link to comment https://forums.phpfreaks.com/topic/66044-solved-unknown-column-test-in-field-list/#findComment-330312 Share on other sites More sharing options...
Shaun13 Posted August 21, 2007 Author Share Posted August 21, 2007 Finally! It works. Many thanks to lemmin and janker. ~Shaun Link to comment https://forums.phpfreaks.com/topic/66044-solved-unknown-column-test-in-field-list/#findComment-330315 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.