Jump to content

Adding Column And Insert Data MYSQL


Go to solution Solved by morrism35,

Recommended Posts

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()
Link to comment
https://forums.phpfreaks.com/topic/299648-adding-column-and-insert-data-mysql/
Share on other sites

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 by mac_gyver
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.