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?

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.