putting data from a form into an sql database help

As the subject states, I would like to add data to a database of mine by taking data that a user inserts into a form and adding it to a table.

Here is the form of my code

[code]<?php
require_once ‘login.php’;

$con = mysql_connect($db_hostname, $db_username, $db_password);
if(!$con)
{
die('Could not connect: ’ . mysql_error());
}

mysql_select_db($db_database, $con);
mysql_close($con);
?>

Add A Pokemon

Fill out the form below to create a new Pokemon in the database.

Please type your pokemon's name: Select your pokemon's type: Bug Dark Electric Fighting Fire Flying Ghost Grass Ice Psychic Steel Water Press to continue ----> [/code]

and here is the back end code to actually put it into the database:

[php]

<?php require_once 'login.php'; $con = mysql_connect($db_hostname, $db_username, $db_password); if(!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db($db_hostname, $con); mysql_query("INSERT INTO Pokemon_Name (pokemonName) VALUES('$_POST[pokemon_Name]')"); mysql_query("INSERT INTO Pokemon_Type (Type) VALUES('$_POST[dropDown]')"); mysql_query("UPDATE Pokemon_Name SET pokemon_Name = pokemonName"); mysql_query("UPDATE Pokemon_Type SET pokemon_Type = Type"); echo "1 record added"; mysql_close($con); ?>[/php]

I see that you are going to have issues with your code…but what is the issue you are asking us about?

Does this help you at all?

[php]<?php
require_once ‘login.php’; // I’m don’t know what this is for
// I assume that you need it for something else

if(isset($_POST[‘submit’])) {

require_once 'db.php';    // Keep your database connection info in this file 
				        // Then you don't need the stuff below

/*
$con = mysql_connect($db_hostname, $db_username, $db_password);
if(!$con)
{
	die('Could not connect: ' . mysql_error());
}

mysql_select_db($db_hostname, $con);
*/



$sql = mysql_query("INSERT INTO Pokemon_Name (pokemonName)
VALUES('$_POST[pokemon_Name]')");

$sql2 = mysql_query("INSERT INTO Pokemon_Type (Type)
VALUES('$_POST[dropDown]')");

// You don't need to do this. You did it with the INSERT query
/* 
mysql_query("UPDATE Pokemon_Name SET pokemon_Name = pokemonName");

mysql_query("UPDATE Pokemon_Type SET pokemon_Type = Type");
*/

if($sql && $sql2){
	echo "1 record added";
}
else {
	echo mysql_error();
}

mysql_close($con);

}
?>

Add A Pokemon

Fill out the form below to create a new Pokemon in the database.

Please type your pokemon's name:


Select your pokemon's type:
Bug Dark Electric Fighting Fire Flying Ghost Grass Ice Psychic Steel Water
Press to continue ----> [/php]

The $_POST should be writtern as $_POST[‘pokemon_Name’] not as $_POST[pokemon_name]

See the commas.

Hope I have helped you.

Sponsor our Newsletter | Privacy Policy | Terms of Service