FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Adding blank rows





Shike
Ok, when i use a php script to add rows to my database table it doesn't take the script from the form.

Code:

<?php
$name = $_POST['name'];
$school = $_POST['school'];
$subschool = $_POST['subschool'];
$descriptor = $_POST['descriptor'];
$caster = $_POST['caster'];
$components = $_POST['components'];
$time = $_POST['casttime'];
$range = $_POST['range1'];
$target = $_POST['target'];
$save = $_POST['save'];
$sr = $_POST['resistance'];
$desc = $_POST['description'];
$src = $_POST['source'];

$conn = mysql_connect("localhost", "shike_spells", "jebu019");
mysql_select_db("shike_spells",$conn);


$sql = "INSERT INTO dnd values ( '', '$name', '$school', '$subschool', '$descriptor', '$caster', '$components', '$time', '$range', '$target', '$save', '$sr', '$desc', '$src' )";

if (mysql_query($sql, $conn)) {
     echo "<h4 align=\"center\">Spell Added!</h4><br /><p align=\"center\"><a href=\"dndspells.html\" target=\"_self\">Add Another Spell</a>";
} else {
    echo "<h4 align=\"center\">Something went wrong<br />Couldn't add Spell.</h4><br /><p align=\"center\"><a href=\"dndspells.html\" target=\"_self\">Try Again?</a>";
}
?>


my form is Here. Any help would be great.
hexkid
Shike wrote:
Ok, when i use a php script to add rows to my database table it doesn't take the script from the form.

[code moved out of the quote]

my form is Here. Any help would be great.


Try this to see the errors you may have (lines I added are preceded by ########)
Code:

<?php
########
error_reporting(E_ALL);
ini_set('display_errors', '1');

$name = $_POST['name'];
$school = $_POST['school'];
$subschool = $_POST['subschool'];
$descriptor = $_POST['descriptor'];
$caster = $_POST['caster'];
$components = $_POST['components'];
$time = $_POST['casttime'];
$range = $_POST['range1'];
$target = $_POST['target'];
$save = $_POST['save'];
$sr = $_POST['resistance'];
$desc = $_POST['description'];
$src = $_POST['source'];

$conn = mysql_connect("localhost", "shike_spells", "jebu019");

########
if (!$conn) exit('Unable to connect because ' . mysql_error());

mysql_select_db("shike_spells",$conn);
######## remove semicolon from last line
######## and uncomment the following line
// or die('Unable to select database because ' . mysql_error());


$sql = "INSERT INTO dnd values ( '', '$name', '$school', '$subschool', '$descriptor', '$caster', '$components', '$time', '$range', '$target', '$save', '$sr', '$desc', '$src' )";

if (mysql_query($sql, $conn)) {
     echo "<h4 align=\"center\">Spell Added!</h4><br /><p align=\"center\"><a href=\"dndspells.html\" target=\"_self\">Add Another Spell</a>";
} else {

    ########
    echo 'Query error: ', mysql_error(), '<br><br><br>';

    echo "<h4 align=\"center\">Something went wrong<br />Couldn't add Spell.</h4><br /><p align=\"center\"><a href=\"dndspells.html\" target=\"_self\">Try Again?</a>";
}
?>
Shike
Hexkid:

This gave me an undefined index for all of my $_POST['name'] data.

I'm very new at this and greatly appreciate your help.


Could you help me figure out what i'm doing wring.

Let me know if you want the markup for my form.
hexkid
Shike wrote:
This gave me an undefined index for all of my $_POST['name'] data.


Which means the data isn't reaching PHP. The reason is that you have
Quote:
enctype="text/plain"

in your form. Remove that and it should be ok.


EDIT:
If I'm not mistaken, enctype should be one of

a) application/x-www-form-urlencoded
b) multipart/form-data

with option a) used as default.
Only use option b) when you have an <input> with type="file".
Shike
Thanx, That worked.

So, I had the scripting right and something wrong in the html. Go figures.

here's some frih$
Related topics
Okay, I'm done trying to use CSS for layout.
Basic HTML Introduction
SQL Tutorial
Installing, Partitioning & Formatting HDDs
U3 Team
[PhP] News Posting Tutorial (code, actually ^^')
Anyone use MySQL Administrator 1.1.2?
Windows does not recognize blank dvd
RTC Fusion Productions / Point Blank Productions
HTML tables with irregular rows and/or columns
simple php to mysql form doesn't work
learning MySQL
Java 2D ArrayLists
Excel question
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.