mysql - html textbox posted to php create table columns -
i new php , trying learn. example not going live!
i have html textbox , posted php. trying break string using explode function , want add seperate strings select database , table database "columns". or advice great thanks
$getmessage = $_post["dbmessages"]; $questions = $_post["dbmessagesname"]; $answers = $_post["dbmessages"]; $combined = array_combine($questions, $answers); $dbconnectiont = mysqli_connect($host, $user, $password, $dbname); // create loop assign input boxes foreach($combined $question => $answer) { // create tables , columns message text box $sqlcreatetable = "create table " . $question . "( add answer column names )"; $answersplit = explode(" ", implode($getmessage)); // if connection , sql query true echo debugging if ($dbconnectiont->query($sqlcreatetable) == true) { echo "created table"; print "{$question} = {$answer} "; echo "</br>"; } }
above code, answer in same text box seperated white space, trying add answers columns in created tables form.
thanks in advance
per comments-
if column names in string, separated spaces, there no need use explode. replace spaces varchar(60),
$columns = "`".str_replace(" ", "` varchar(60), `", $answers)."` varchar(60)"; // wrap column names ` prevent issues reserved words
then use in query
$sqlcreatetable = "create table " . $question . "( ". $columns. " )";