Praetorian Posted September 18, 2008 Share Posted September 18, 2008 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 More sharing options...
justsomeguy Posted September 18, 2008 Share Posted September 18, 2008 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 More sharing options...
Praetorian Posted September 18, 2008 Author Share Posted September 18, 2008 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 More sharing options...
Praetorian Posted September 18, 2008 Author Share Posted September 18, 2008 Not just that, but there really are no errors. Which is what makes no sense. There should at least be a connection error, or something. But.. nothing. It just doesn't insert. Link to comment Share on other sites More sharing options...
jeffman Posted September 18, 2008 Share Posted September 18, 2008 Does it matter that id is undefined? I mean, there's no text input for it or other statement where a value gets assigned to it. Or maybe not. That's just a field name, and you put NULL there. Link to comment Share on other sites More sharing options...
Praetorian Posted September 18, 2008 Author Share Posted September 18, 2008 Doesn't matter. That's what the NULL is in the values. ID is auto-incrementing. Link to comment Share on other sites More sharing options...
Praetorian Posted September 18, 2008 Author Share Posted September 18, 2008 Okay. I found it. There was apparently a missing field in the table. One of the fields I was trying to add didn't exist yet. Though I find it ridiculous that that didn't cause an error. Thanks for trying to help folks. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 18, 2008 Share Posted September 18, 2008 It's probably the same thing with MySQL. An error coming back from the MySQL server isn't reported as a PHP error, you need to check the result of the operation and display the error yourself. Link to comment Share on other sites More sharing options...
Praetorian Posted September 18, 2008 Author Share Posted September 18, 2008 (Yea, added the field, but the problem is still there.)How can I check that with pdo though? I don't know how to debug pdo. How can I display what information it's sending to the sql server and what's coming back? Link to comment Share on other sites More sharing options...
justsomeguy Posted September 18, 2008 Share Posted September 18, 2008 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 More sharing options...
Praetorian Posted September 18, 2008 Author Share Posted September 18, 2008 Okay. Thanks.Off the top of your head, any reason you can think of that this might be happening? that's part of what's so confusing. There aren't any errors, the fields are all there, the permissions are set... It's driving me insane. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 18, 2008 Share Posted September 18, 2008 There are no error messages. If there weren't any errors then it would be working. Chances are there are one or more errors that you're just not aware of. Link to comment Share on other sites More sharing options...
Praetorian Posted September 18, 2008 Author Share Posted September 18, 2008 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.