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)

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";

}

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));

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.