Jump to content

Insert doesn't work


Praetorian

Recommended Posts

This one is about to melt my brain. I'm trying to insert a row, the username has permissions, the table name is correct, and yet... nothing. No errors... it just reloads the page, and doesn't insert the row.

<?php	session_start();	include 'includes/class.php';	if($_SERVER['REQUEST_METHOD'] == "GET")	{		if(!empty($_SESSION['admin']))		{echo <<< HTML			<form method="post" action="insert.php">				Username: <input type="text" name="insert_user_name" size="30" /><br />				Email: <input type="text" name="insert_email" size="30" /><br />				Link Name: <input type="text" name="insert_link_name" size="30" /><br />				Character Name: <input type="text" name="insert_character_name" size="30" /><br />				Pronounce: <input type="text" name="insert_pronounce" size="30" /><br />				Character Age: <input type="text" name="insert_character_age" size="30" /><br />				Character Gender: <input type="text" name="insert_character_gender" size="30" /><br />				Character Race: <input type="text" name="insert_character_race" size="30" /><br />				Character Class: <input type="text" name="insert_character_class" size="30" /><br />				Hair color: <input type="text" name="insert_hair_color" size="30" /><br />				Diseases: <input type="text" name="insert_diseases" size="30" /><br /><br />				Physical description<br />					<textarea name="insert_physical_description" cols="50" rows="20"></textarea><br /><br />				Personality<br />					<textarea name="insert_personality" cols="50" rows="20"></textarea><br /><br />				Languages<br />					<textarea name="insert_languages" cols="50" rows="20"></textarea><br /><br />				Deity<br />					<textarea name="insert_deity" cols="50" rows="20"></textarea><br /><br />				Arsenal<br />					<textarea name="insert_arsenal" cols="50" rows="20"></textarea><br /><br />				Armor<br />					<textarea name="insert_armor" cols="50" rows="20"></textarea><br /><br />				Skills<br />					<textarea name="insert_skills" cols="50" rows="20"></textarea><br /><br />				Faults<br />					<textarea name="insert_faults" cols="50" rows="20"></textarea><br /><br />				Power<br />					<textarea name="insert_power" cols="50" rows="20"></textarea><br /><br />				Weaknesses<br />					<textarea name="insert_weaknesses" cols="50" rows="20"></textarea><br /><br />				Crystals<br />					<textarea name="insert_crystals" cols="50" rows="20"></textarea><br /><br />				Items<br />					<textarea name="insert_items" cols="50" rows="20"></textarea><br /><br />				Notes<br />					<textarea name="insert_notes" cols="50" rows="20"></textarea><br /><br />				History<br />					<textarea name="insert_history" cols="50" rows="20"></textarea><br /><br />				Sample Post<br />					<textarea name="insert_sample_post" cols="50" rows="20"></textarea><br /><br />				Race: <input type="text" name="insert_race" size="30" /><br />				Character Type: <input type="text" name="insert_character_type" size="30" /><br /><br />				<input type="submit" name="submit_insert" value="done" />			</form>HTML;		}		else		{			header("Location: index.php");		}	}	elseif($_SERVER['REQUEST_METHOD'] == "POST")	{		foreach($_POST AS $key => $value)		{			$key = preg_replace("/insert_/","",$key);			$$key = $value;		}		$insert_character = pdo_query($cxn,"INSERT INTO census			(				'id',				'user_name',				'email',				'link_name',				'character_name',				'pronounce',				'character_age',				'character_gender',				'character_race',				'character_class',				'hair_color',				'diseases',				'physical_description',				'personality',				'languages',				'deity',				'arsenal',				'armor',				'skills',				'faults',				'power',				'weaknesses',				'crystals',				'items',				'notes',				'history',				'sample_post',				'race',				'character_type'			) VALUES (NULL,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",			array($user_name,$email,$link_name,$character_name,$pronounce,$character_age,$character_gender,$character_race,$character_class,$hair_color,$diseases,$physical_description,$personality,$languages,$deity,$arsenal,$armor,$skills,$faults,$power,$weaknesses,$crystals,$items,$notes,$history,$sample_post,$race,$character_type));			if($insert_character)			{				echo "Done!";			}			else			{				"Error";			}	}?>

Link to comment
Share on other sites

You're not doing any debugging. There are if statements there but you aren't printing out the expressions you're evaluating, for example. Print $_SERVER['REQUEST_METHOD'] and $_SESSION['admin'] to make sure they are what you think they are. Add output at various points so that when you run the page you can see how far it gets. And make sure display_errors is on and that error_reporting is set to show them all.

Link to comment
Share on other sites

I'll do that, but that can't be the problem. If the $_SESSION wasn't right, it would redirect the page, which it doesn't. And if the REQUEST_METHOD wasn't post, it wouldn't evaluate the if statement there and say "done".Is there a debugging I can do for pdo? Something that would tell me what it's doing? The problem has to be somewhere in the query..

Link to comment
Share on other sites

I can't find a reference at php.net for procedural-style PDO functions, all I can find is object-oriented style where you create an instance of the PDO class. The PDO class has methods called errorCode and errorInfo that look like they get information about errors on the server, but I'm not sure how to use those procedurally. Maybe just pdo_errorCode.

Link to comment
Share on other sites

Well........ apparently ........ (and mind you I feel like putting my head through a wall after finding this out)I had set the age field as an integer. Rather than just a varchar. And pdo turns everything into a string. So I think it was dying because it was a string when it was expecting an integer.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...