morrism35 Posted December 5, 2015 Share Posted December 5, 2015 I have imported my database from my localserver into my instructors web server. I want to add a column called pageLink and insert data. I'm getting a "Error: INSERT INTO artist_table (pageLink) VALUES ('jkljk') Unknown column 'pageLink' in 'field list'". As a test I tested my code on other columns and was successfuly able to insert data. My code to add the pageLink column does say successfull but like stated inserting data is saying that pageLink does not exist. Below is my code to add the pageLink column and to insert the pageLink column Adding a column code: $r="ALTER TABLE artist_table ADD COLUMN (pageLink VARCHAR(200))"; $QueryResult=@mysql_query($r, $conn); if($QueryResult===FALSE) echo"Unable to execute the query".mysql_errno($conn).mysql_error($conn); else echo"Success created"; mysqli_close($conn); Inserting data into that column: $sql = "INSERT INTO artist_table (pageLink) VALUES ('jkljk')"; if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } $conn->close() Quote Link to comment https://forums.phpfreaks.com/topic/299648-adding-column-and-insert-data-mysql/ Share on other sites More sharing options...
Barand Posted December 5, 2015 Share Posted December 5, 2015 you cannot mix mysql and mysqli. $QueryResult=@mysql_query($r, $conn); Quote Link to comment https://forums.phpfreaks.com/topic/299648-adding-column-and-insert-data-mysql/#findComment-1527571 Share on other sites More sharing options...
mac_gyver Posted December 5, 2015 Share Posted December 5, 2015 (edited) your alter table query is using the php mysql function to run the query. you are however apparently using either the mysqli or the PDO classes for your connection and the rest of your code. as was stated in one of your previous threads, you cannot mix the different php database functions together for a single connection. if your mysql based statements appear to be running without producing database errors, it's because most of the all-in-one xAMP packages set up default mysql database credentials that allow mysql statements to make a database connection if there isn't already one. also, please do NOT suppress any errors in your code. remove any @ error suppressors and make sure that php's error_reporting is set to E_ALL and display_errors is set to ON in the php.ini on your development system. if you are tyring to learn php or learn anything new in php, developing php code, or trying to debug problems in php code, you want ALL THE HELP YOU CAN GET from php. you don't want to hide any of the php errors. Edited December 5, 2015 by mac_gyver Quote Link to comment https://forums.phpfreaks.com/topic/299648-adding-column-and-insert-data-mysql/#findComment-1527573 Share on other sites More sharing options...
morrism35 Posted December 5, 2015 Author Share Posted December 5, 2015 I've changed it to mysqli_query, but it didn't make any difference. It is only with this column that it becomes a problem. I'm able to add data with the columns that are already there. Quote Link to comment https://forums.phpfreaks.com/topic/299648-adding-column-and-insert-data-mysql/#findComment-1527574 Share on other sites More sharing options...
morrism35 Posted December 5, 2015 Author Share Posted December 5, 2015 ok I only changed mysqli_query in my insertData script, i'm assuming it needs to be also in my addColumns script. Quote Link to comment https://forums.phpfreaks.com/topic/299648-adding-column-and-insert-data-mysql/#findComment-1527576 Share on other sites More sharing options...
Solution morrism35 Posted December 5, 2015 Author Solution Share Posted December 5, 2015 It worked thanks Quote Link to comment https://forums.phpfreaks.com/topic/299648-adding-column-and-insert-data-mysql/#findComment-1527579 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.