The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/printthread.php 16 require_once
Warning [2] Undefined property: MyLanguage::$archive_pages - Line: 2 - File: printthread.php(287) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/printthread.php(287) : eval()'d code 2 errorHandler->error
/printthread.php 287 eval
/printthread.php 117 printthread_multipage



UserSpice
HELP!!!! - 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: HELP!!!! (/showthread.php?tid=681)

Pages: 1 2 3


HELP!!!! - Katronix - 08-21-2017

Hi all, I have the following code as one of my pages and I keep being told I have some kind of DB error. How do I find out what it is?

<?php

require_once 'users/init.php';
require_once $abs_us_root.$us_url_root.'users/includes/header.php';
require_once $abs_us_root.$us_url_root.'users/includes/navigation.php';

if (!empty($_POST['studio-name']))
{
$studio_name = Input::get('studio-name');
$studio_url = Input::get('studio-url');
$studio_rss = Input::get('studio-rss');
$studio_bio = Input::get('studio-bio');
$added_on = Input::get('added-on');
$added_by = Input::get('added-by');

$insert = array('studio_name'=>$studio_name, 'studio_url'=>$studio_url,'studio_rss'=>$studio_rss,'studio_bio'=>$studio_bio, 'studio_added'=>$added_on, 'studio_by'=>$added_by);
$db->insert('ad-studio',$insert);
if ($db->error()) { echo "Some kind of DB error!"; die();}
?>
<div id="page-wrapper">
<div class="container">
<div class="jumbotron">
<h1>Thank you!</h1> The Studio Information you have provided has been added!
</div>
</div>
</div>
<!-- footers -->
<?php require_once $abs_us_root.$us_url_root.'users/includes/page_footer.php'; // the final html footer copyright row + the external js calls ?>

<!-- Place any per-page javascript here -->


<?php require_once $abs_us_root.$us_url_root.'users/includes/html_footer.php'; // currently just the closing /body and /html ?>
<?php
die();
}
?>

<div id="page-wrapper">
<div class="container">
<form action="addstudio.php" method="post" class="form-group">
<label for="studio-name">Studio Name</label>
<input type="text" name="studio-name" class="form-control" id="studio-name" placeholder="Podcast Audio" required><p/>
<label for="studio-url">Studio URL</label>
<input type="url" name="studio-url" class="form-control" id="studio-url" placeholder="http://podcastaudio.com" required><p/>
<label for="studio-rss">Studio RSS</label>
<input type="url" name="studio-rss" class="form-control" id="studio-rss" placeholder="http://podcastaudio.com/?feed=rss" required><p/>
<label for="studio-bio">Studio Bio</label>
<textarea id="studio-bio" name="studio-bio" cols="80" rows="20"></textarea><p/>
<input type="hidden" name="added-on" value="<?php echo date('m/j/Y'); ?>">
<input type="hidden" name="added-by" value="<?php echo $user->data()->id; ?>">
<button type="submit" name="add-studio" <?php if(!$user->isLoggedIn()){ echo "disabled"; } ?> class="form-control btn btn-primary">Add Studio</button>
</form>
</div>
</div>


<!-- footers -->
<?php require_once $abs_us_root.$us_url_root.'users/includes/page_footer.php'; // the final html footer copyright row + the external js calls ?>

<!-- Place any per-page javascript here -->


<?php require_once $abs_us_root.$us_url_root.'users/includes/html_footer.php'; // currently just the closing /body and /html ?>


HELP!!!! - mudmin - 08-21-2017

Is there any way you can paste this code on pastebin or hastebin and share the link? All the quotes get messed up when you just paste that much raw code here.



HELP!!!! - Katronix - 08-21-2017

Sure, here it is: https://pastebin.com/TLeYrJhP


HELP!!!! - Brandin - 08-21-2017

Is there a value for
Code:
$db->error
? If so, why don't you echo
Code:
$db->error
instead of:
Code:
if ($db->error()) { echo "Some kind of DB error!"; die();}

Since you know there is an error somewhere...this should tell you what!

Your code looks fine. Does your database match the fields you are inputting? Are you missing a field that isn't default NULL? Or something like that?


HELP!!!! - mudmin - 08-21-2017

Ok. So.... you don't want to put the user id etc in as hidden fields, because people can technically go into the browser and change those things. You should do those in post.

I'm still working on your code, but are you actually getting a db error? I never use the $db->error thing. Is the form inserting into the db?

And just to be clear:
1. Is your table name ad-studio
2. What column type in the database did you use for that date field. Is it date or varchar?

I'll keep looking at your code.


HELP!!!! - mudmin - 08-21-2017

My guess, without seeing your db is that your date is in the db as date and it is looking for a Y-m-d date.

I also think it's best practice to name your form fields the exact same thing as your db fields just for consistency.

Here is that modified with a few of my suggestions.
https://pastebin.com/LDsDAEg2


HELP!!!! - Katronix - 08-21-2017

When I did echo $db->error() it returned 1

Good point about the ID, I'll move that.
The studio_field is a date field, I will try reversing the date to see if that helps.



HELP!!!! - mudmin - 08-21-2017

The code I sent you already does the reversing.


HELP!!!! - Katronix - 08-21-2017

Yes, I saw that.

Using your version of the code, (after fixing line 16 to say 'studio_added'=>$date,) it still returns 1 if I echo the $db->error()

Sad


HELP!!!! - mudmin - 08-21-2017

Can you export that one table from the database so I can take a look at it?