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
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HELP!!!!
#1
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 ?>
  Reply
#2
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.
  Reply
#3
Sure, here it is: https://pastebin.com/TLeYrJhP
  Reply
#4
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?
  Reply
#5
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.
  Reply
#6
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
  Reply
#7
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.
  Reply
#8
The code I sent you already does the reversing.
  Reply
#9
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
  Reply
#10
Can you export that one table from the database so I can take a look at it?
  Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)