Jeremy P. Beasley
Jeremy P. Beasley

Reputation: 709

Basic PHP MYSQL form not submitting

I'm a php beginner. Trying to submit bit of data to a MYSQL database.

When I submit the form, a row is created in the table but only containing the AUTOINT column, not my data. Any help?

index.php:

<form method="post" action="form.php">

    <input id="name" name="name"  value="Stuffff">
    <input id="limite" name="limite"  value="100.00">
    <input type="submit" name="submit" value="Add!">

</form>

form.php:

<?
mysql_connect("localhost","root","root")
mysql_select_db("means");

$order = "INSERT INTO categories (name, limite ) VALUES ( '$name', '$limite' )";

$result = mysql_query($order);
if($result){
    echo("<br>Input data is succeed");
} else{
echo("<br>Input data is fail");
}
?>

Upvotes: 0

Views: 53

Answers (4)

greysaff
greysaff

Reputation: 198

$order = "INSERT INTO categories (name, limite ) VALUES ( '$name', '$limite' )";

in above statement, change the following:

$name -> $_POST['name']
$limite -> $_POST['limite']

you might want to read more about php forms. there are lots of resources available online. cheers!

Upvotes: 0

Quentin
Quentin

Reputation: 943569

Your code depends on register_globals being available (meaning you are using an out of date PHP) and turned on.

Get your posted data from $_POST['name'] and $_POST['limite'].


It also depends on short open tags being turned on, which hasn't been the default for many years.

Use <?php, not <?.

Upvotes: 0

VMai
VMai

Reputation: 10336

Your tutorial or book seems very outdated and relies of a configuration of REGISTER_GLOBALS=on. This feature was removed with PHP 5.4, see http://www.php.net/manual/en/security.globals.php .

Please use a modern API to mysql like PDO or mysqli instead of old mysql_ and sanitize your database inputs, i.e. use prepared statements.

Upvotes: 1

DonCallisto
DonCallisto

Reputation: 29912

You have to modify your code as follows

$order = "INSERT INTO categories (name, limite ) VALUES ( $_POST['name'], $_POST['limite'] )";

This is because you're posting data so you have to retrieve it from $_POST php built in variable

Moreover remember that mysql_* functions are deprecated

Upvotes: 0

Related Questions