This forum is archived. Posts are preserved for historical reference. For current help, join us on Discord.

HELP!!!!

In UserSpice 4.3 and Below · Started by Katronix on 2017-08-21 12:15 pm · 47848 views · 22 replies

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 ?>
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.
Sure, here it is: https://pastebin.com/TLeYrJhP
Is there a value for
$db->error
? If so, why don't you echo
$db->error
instead of:
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?
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.
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
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.
The code I sent you already does the reversing.
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()

:(
Can you export that one table from the database so I can take a look at it?
I will shoot you an email. You can send the sql dump there.
email sent!
Ok. I sent you a response. I accidentally left the $db->error line commented out, but you can comment it back in.
Also, if you want, instead of disabling the submit button, you can add this pretty much anywhere on the page after the init file and it will redirect them to login if they haven't.


<?php if(!$user->isLoggedIn()){ Redirect::to('users/login.php'); } ?>



I tried the code you sent me, and nothing was written to the database :(
Hmm. Let me take another look. sorry about that!
I did tell it to dnd($db->error()) and it returned: bool(true)

Is there a way to see the actual error?
We're working on that. I'm baffled by why I can't get any of your text to insert. Still working on it.
Sending you an email
FYI: Still waiting on email
Oh weird. I wonder if it got filtered. Let me try again.
12Next ›