Jump to content

HTML Form Value returning null in PHP script? (basic question)


Jakesta42

Recommended Posts

Hello,

 

I'm trying to take the value from an HTML form and insert it into a database on a button click. It inserts a null value into the database. The script is called submitColumnDetails.php.

 

 

This is where I create the text field that I want to take the information from. This is in a separate file.

echo <<<END
<form action = "submitColumnDetails.php" method = "POST">
<input type = "text" name = "columnField"/>
</form>
END;

 

This is the submitColumnDetails.php file

 


<?php
//Submit Column Data
//-----------------------------------------------------//
//Connect to localhost server
$connector = mysql_connect("localhost", "root", "root");
if(!$connector){	//If user can't connect to database
die('Could not connect: ' . mysql_error()); //Throw an error
}			
//-----------------------------------------------------//

mysql_select_db("colin_db", $connector);

$newValue = $_POST["columnField"];	//Data from column field. THIS IS WHAT RETURNS NULL
$newColumnQuery = "INSERT INTO `colin_db`.`allColumnFields` (`DATA`) VALUES ('$newValue')";
mysql_query($newColumnQuery); //Query to add form to main table

$newColumnIntoMainTableQuery = "ALTER TABLE colin_table ADD ('$newValue' varchar(50))";
mysql_query($newColumnIntoMainTableQuery);	//Query to add column to main table


mysql_close($connector);	//Close database connection
echo "<script type = 'text/javascript'> window.location = 'index.php'</script>";
//Go back to original page
?>			

 

Even when I print out the $newValue, it does not print anything. What am I doing incorrectly?

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.