The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/printthread.php 16 require_once



UserSpice
Inserting records failed - Printable Version

+- UserSpice (https://userspice.com/forums)
+-- Forum: Support Center (https://userspice.com/forums/forumdisplay.php?fid=23)
+--- Forum: UserSpice 4.3 and Below (https://userspice.com/forums/forumdisplay.php?fid=26)
+--- Thread: Inserting records failed (/showthread.php?tid=1162)



Inserting records failed - vkkan - 10-07-2018

Hi Folks,

I have created form using form builder and this form has to be accessed by the users without login and submit the form and the same has to be saved inside the db but so far its not happening.

form posting php as follows i.e. abc.php

<?php require_once './users/init.php'; ?>
<?php require_once $abs_us_root.$us_url_root.'users/includes/header.php'; ?>
<?php require_once $abs_us_root.$us_url_root.'users/includes/navigation.php'; ?>
<?php if (!securePage($_SERVER['PHP_SELF'])){die();} ?>


<div id="page-wrapper">
<div class="container">
<?php

if($_POST){
   //print_r($_POST);exit;

   $db = DB::getInstance();


[font=Droid Sans Mono]
    try {
       // echo "Trying to create user";
       $fields=array(
[/font]

[font=Droid Sans Mono][font=Droid Sans Mono]         'var1' => Input::get('[font=Droid Sans Mono]var1'),
         'var2' => ucfirst(Input::get('var2')),
         'var3' =>  Input::get('var3'),[/font]
[/font]
[/font]

[font=Droid Sans Mono][font=Droid Sans Mono]       );
       print_r($fields);
       var_dump($db);
       $db->insert('tablename',$fields) or die("not able to create record");exit;
       $theNewId=$db->lastId();
[/font]
[/font]

[font=Droid Sans Mono][font=Droid Sans Mono]}[/font][/font]
[font=Droid Sans Mono][font=Droid Sans Mono][font=Droid Sans Mono]displayForm('abcform');[/font][/font][/font]
[font=Droid Sans Mono][font=Droid Sans Mono]abc.php has be defined as public and error I am getting as follows[/font][/font]

[font=Droid Sans Mono][font=Droid Sans Mono]object(DB)#8 (9) { ["_pdo":"DB":private]=> object(PDO)#6 (0) { } ["_query":"DB":private]=> object(PDOStatement)#32 (1) { ["queryString"]=> string(50) "SELECT id, page, private FROM pages WHERE page = ?" } ["_error":"DB":private]=> bool(false) ["_errorInfo":"DB":private]=> array(3) { [0]=> int(0) [1]=> NULL [2]=> NULL } ["_results":"DB":private]=> array(1) { [0]=> object(stdClass)#31 (3) { ["id"]=> string(2) "87" ["page"]=> string(14) "abc.php" ["private"]=> string(1) "0" } } ["_resultsArray":"DB":private]=> array(1) { [0]=> array(3) { ["id"]=> string(2) "87" ["page"]=> string(14) "abc.php" ["private"]=> string(1) "0" } } ["_count":"DB":private]=> int(1) ["_lastId":"DB":private]=> string(1) "0" ["_queryCount":"DB":private]=> int(51) } not able to create record[/font][/font]

[font=Droid Sans Mono][font=Droid Sans Mono]I am struck here please someone help me[/font][/font]


RE: Inserting records failed - Brandin - 10-07-2018

After your insert you should be doing (nor or die):
if(!$db->error()) {
//If it went well and no errors, do stuff here
} else {
//dump your error stuff here
dump($db->errorString());
}