Jump to content

add details into existing column


ferlicia

Recommended Posts

"i have a existing table and let the user add another column in the table"

 

You mean you let the user alter you database tables?

 

i  can create the column but do not know how to insert the user input.

 

Maybe and INSERT

 

INSERT INTO tableName(your_fields) VALUES(your_values)

Link to comment
Share on other sites

lets say i have a table inside the database, name database. i have id, name, price. after that i decide to let the user add a column name quantity, i can create the column already. however, i tried to insert the user input data into the column, it cannot be done because there is an error message. the message is, Column count doesn't match value count at row 1. this is my code,

 

<?php

 

include 'dbFunctions.php';

 

$coulmnname = $_POST['columnname'];

$addname = $_POST['addname'];

$query = "INSERT INTO table ($columnname) VALUES ('".$addname."')";

$status = mysqli_query($link,$query) or die(mysqli_error($link));

 

if($status){

    $message = " addded sucessfully";

}

else{

    $message = "Unable to add";

}

Link to comment
Share on other sites

My guess is ferlicia wants to add a row of data, for 2 reasons:

 

1. Because ferlicia said "i  can create the column but do not know how to insert the user input. "

2. because letting users freely add columns do tables is such a bad idea that I'd rather think option 1 is the correct one.  :o

 

So what you need ferlicia, (as said before by irkevin) is something like: mysql_query("INSERT INTO `tableName` (`field1`,`field2`,`filed3`) values ('$value1','$value2','$value3')");

and make sure you have the correct table name:

$field = trim($_POST['columnname']);
$addname = trim($_POST['addname']);
$query = "INSERT INTO `CHANGE_THIS_TO_YOUR_TABLE_NAME` ($field) VALUES ('$addname')";
$status = mysqli_query($link,$query) or die(mysqli_error($link));

Link to comment
Share on other sites

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.