jaykappy Posted March 13, 2013 Share Posted March 13, 2013 I am trying to insert a record from values from a FORM. I run the INSERT INTO and nothing happens, no error not new record...maybe another pair of eyes might help... My confusion is that I have an "id" field in the table...Its set to autoNumber so I dont know if I have to reference it in the Queries below????? If so I would passa a null value because it woudl autoNUmber.... Any thoughts? I have the update working fine and using the same login in code. // First we execute our common code to connection to the database and start the session require("commonMapLibrary.php"); MainPageIndex.php <form class="CreateFormRow" id="CreateDataform" action="CreateNewRecord.php?Dept=<?php echo $_GET['Dept'] ?>" method="post" style="display:none"> <legend>Add Record</legend> <ol style="float:left"> <li> <label for=name>id</label> <input id=name type="text" name="Cid" value="" placeholder="ID" /> </li> <li > <label for=name>Year</label> <input id=name type="text" name="CYr" value="" placeholder="Year of Project" required autofocus /> </li> <li> <input id=name type="text" name="CProjectName" value="" placeholder="Project Name" /> </li> <li> <label for=phone>Department</label> <input id=name type="text" name="CDepartment" value="" placeholder="Department"/> </li> <li> <label for=name>Owner</label> <input id=name type="text" name="COwner" value="" placeholder="Owner" /> </li> <li> <label for=email>Maplibrary Name</label> <input id=name type="text" name="CMaplibraryName" value="" placeholder="Maplibrary Name" /> </li> <li> <label for=email>Description</label> <input id=name type="text" name="CDescription" value="" placeholder="Description" /> </li> <li> <label for=phone>Maplibrary Path</label> <input id=name type="text" name="CMaplibraryPath" value="" placeholder="Maplibrary Path" /> </li> </ol> <ol style="float:right"> <li> <label for=phone>Page Size</label> <input id=name type="text" name="CPageSize" value="" placeholder="Page Size" /> </li> <li> <label for=phone>Scale</label> <input id=name type="text" name="CScale" value="" placeholder="Scale" /> </li> <li> <label for=phone>Last Modified</label> <input id=name type="text" name="CLastModified" value="" placeholder="Last Modified" /> </li> <li> <label for=phone>Notes</label> <input id=name type="text" name="CNotes" value="" placeholder="Notes" /> </li> <li> <label for=phone>Modified By</label> <input id=name type="text" name="CModifiedBy" value="" placeholder="Modified By" /> </li> <li> <label for=phone>Full Path</label> <input id=name type="text" name="CFullPath" value="" placeholder="Full Path" /> </li> <li> <label for=phone>Path jpg</label> <input id=name type="text" name="CPath_jpg" value="" placeholder="Path_jpg" /> </li> </ol> <legend></legend> <button id="" class="Submitbutton" type=submit>Submit</button> <button id="CloseButtonAdd" onClick="CloseForm()">Close</button><br> </form> CreateNewRecord.php <?php // First we execute our common code to connection to the database and start the session require("commonMapLibrary.php"); // At the top of the page we check to see whether the user is logged in or not if(empty($_SESSION['user'])) { // If they are not, we redirect them to the login page. header("Location: login.php"); die("Redirecting to login.php"); }else{ } if(!empty($_POST)) { if(empty($_POST['CProjectName'])) { die("Please enter a Project Name."); } $query = "INSERT INTO tbl_maplibrary ( Yr, ProjectName, Department, Owner, MaplibraryName, Description, MaplibraryPath, PageSize, Scale, LastModified, Notes, ModifiedBy, FullPath, Path_jpg ) VALUES ( :Yr, :ProjectName, :Department, :Owner, :MaplibraryName, :Description, :MaplibraryPath, :PageSize, :Scale, :LastModified, :Notes, :ModifiedBy, :FullPath, :Path_jpg ) "; $query_params = array( ':Yr' => $_POST['CYr'], ':ProjectName' => $_POST['CProjectName'], ':Department' => $_POST['CDepartment'], ':Owner' => $_POST['COwner'], ':MaplibraryName' => $_POST['CMaplibraryName'], ':Description' => $_POST['CDescription'], ':MaplibraryPath' => $_POST['CMaplibraryPath'], ':PageSize' => $_POST['CPageSize'], ':Scale' => $_POST['CScale'], ':LastModified' => $_POST['CLastModified'], ':Notes' => $_POST['CNotes'], ':ModifiedBy' => $_POST['CModifiedBy'], ':FullPath' => $_POST['CFullPath'], ':Path_jpg' => $_POST['CPath_jpg'] ); $stmt = $db->prepare($query); $result = $stmt->execute($query_params); ?> Quote Link to comment https://forums.phpfreaks.com/topic/275628-php-insert-into-not-working/ Share on other sites More sharing options...
jaykappy Posted March 13, 2013 Author Share Posted March 13, 2013 (edited) I added this die in the Try statement and I get the return text... die("You got to the query"); so its in the right area and the EXECUTE is firing (well the code is going right passed it) but its not saving the new record... Is there anything I can test? Same connection I am using for the update statement, user has insert and update permissions. No errors nothing....just dosent update the table in the db WHY? try { // Execute the query to create the user $stmt = $db->prepare($query); $result = $stmt->execute($query_params); die("You got to the query"); } catch(PDOException $ex) { // Note: On a production website, you should not output $ex->getMessage(). // It may provide an attacker with helpful information about your code. die("Failed to run query: " . $ex->getMessage()); } Edited March 13, 2013 by jaykappy Quote Link to comment https://forums.phpfreaks.com/topic/275628-php-insert-into-not-working/#findComment-1418469 Share on other sites More sharing options...
gizmola Posted March 13, 2013 Share Posted March 13, 2013 When you wrote "auto number" did you really mean "auto increment"? Omitting the column from the values entirely is correct. You probably have an error of some sort --- check out http://www.php.net/manual/en/pdostatement.errorinfo.php in order to get specifics. Quote Link to comment https://forums.phpfreaks.com/topic/275628-php-insert-into-not-working/#findComment-1418471 Share on other sites More sharing options...
jaykappy Posted March 13, 2013 Author Share Posted March 13, 2013 (edited) Yes I meant Auto Increment.....I have removed the id from the Query and Query Params Array...it was not shown in the first post here... I added this: and get this in return PDOStatement::errorInfo(): can I print the actual query? and verifiy it looks right? DONT know what else to do $stmt = $db->prepare($query); $result = $stmt->execute($query_params); echo "\nPDOStatement::errorInfo():\n"; $arr = $sth->errorInfo(); print_r($arr); Edited March 13, 2013 by jaykappy Quote Link to comment https://forums.phpfreaks.com/topic/275628-php-insert-into-not-working/#findComment-1418472 Share on other sites More sharing options...
jaykappy Posted March 13, 2013 Author Share Posted March 13, 2013 I changed the name of the table in the database and I didnt get an error...very weird... From $query = " INSERT INTO tbl_maplibrary ( To $query = " INSERT INTO tbl_maplibrary99 ( This error should have been caught right? and the "Failed to run Query" shodl have been displayed try { // Execute the query to create the user $stmt = $db->prepare($query); $result = $stmt->execute($query_params); echo "\nPDOStatement::errorInfo():\n"; } catch(PDOException $ex) { die("Failed to run query: " . $ex->getMessage()); } Quote Link to comment https://forums.phpfreaks.com/topic/275628-php-insert-into-not-working/#findComment-1418475 Share on other sites More sharing options...
jaykappy Posted March 13, 2013 Author Share Posted March 13, 2013 THINK I GOT IT....ONE SECOND...so exciting Quote Link to comment https://forums.phpfreaks.com/topic/275628-php-insert-into-not-working/#findComment-1418480 Share on other sites More sharing options...
jaykappy Posted March 13, 2013 Author Share Posted March 13, 2013 (edited) OK I can get all the Fields to INSERT INTO except the one that was (i guess causing the error). The field is a DATE field....i entered 5/5/2013 as a value... Any thoughts as to why I would be blowing up on the date field INSERT INTO Why cant I add the Date Field? Edited March 13, 2013 by jaykappy Quote Link to comment https://forums.phpfreaks.com/topic/275628-php-insert-into-not-working/#findComment-1418483 Share on other sites More sharing options...
Solution gizmola Posted March 13, 2013 Solution Share Posted March 13, 2013 Mysql wants the format of the date to be 'yyyy-mm-dd' Quote Link to comment https://forums.phpfreaks.com/topic/275628-php-insert-into-not-working/#findComment-1418486 Share on other sites More sharing options...
P5system Posted March 14, 2013 Share Posted March 14, 2013 print the query and run it in phpmyadmin u wl get to know where the problem is........ Quote Link to comment https://forums.phpfreaks.com/topic/275628-php-insert-into-not-working/#findComment-1418519 Share on other sites More sharing options...
jaykappy Posted March 14, 2013 Author Share Posted March 14, 2013 (edited) P5system - how do I do that...sorry for the stupid question...still new to this but believe this is very important... Gizmola - That was it...it worked in that format....but that's such a a weird format for someone to put in....Is there any way to add some sort of calendar control that will push the value to the input box in that format? Edited March 14, 2013 by jaykappy Quote Link to comment https://forums.phpfreaks.com/topic/275628-php-insert-into-not-working/#findComment-1418576 Share on other sites More sharing options...
jaykappy Posted March 14, 2013 Author Share Posted March 14, 2013 Using this one... http://javascriptcalendar.org/javascript-date-picker.php Quote Link to comment https://forums.phpfreaks.com/topic/275628-php-insert-into-not-working/#findComment-1418591 Share on other sites More sharing options...
P5system Posted March 18, 2013 Share Posted March 18, 2013 echo $sql="Write your sql here"; exit; exit command will not allow to continue your code and echo will print the query Quote Link to comment https://forums.phpfreaks.com/topic/275628-php-insert-into-not-working/#findComment-1419244 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.