Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Not a member yet? Click here to register.
Forgot Password?

Need Code Confirmation

Asked Modified Viewed 1,041 times
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
asked
Senior Member

Hi guys I'm back. If I could I would like to get a confirmation that my code as written will work correctly before I implement it:
This is from my create_post.php file in my new blog infusion.

$epoch = time();
$posted = $epoch;

$result = dbquery("INSERT INTO ".DB_GRIMS_BLOG_POST." (post_id, topic_id, post_title, post_body, post_img, post_thb, posted, active) VALUES ('', '$topic_id', '$post_title', '$post_body', '$post_img', '$post_thb', '$posted.', '$active')");
$last_id = LAST_INSERT_ID();
$month = date("m", posted);
$result = dbquery("INSERT INTO ".DB_GRIMS_BLOG_POST_TOPIC." (post_topic_id, post_id, topic_id, month) VALUES ('', '$last_id', '$topic_id', '$month')");


Any help/insights would be appreciated very much.
Edit: I went ahead and tried it and got an error: [24-Nov-2020 11:27:12 America/Chicago] PHP Fatal error:  Uncaught Error: Call to undefined function LAST_INSERT_ID() in /home/whisperw/public_html/infusions/grims_blog/admin/create_post.php:53
I don't understand why the error. I looked up how to get the last inserted id and thought that was it!

 
Edited by Grimloch on 24-11-2020 19:40,
0 replies

4 posts

R
Anonymous User
R
Anonymous User 367
  • Veteran Member, joined since
  • Contributed 939 posts on the community forums.
  • Started 2 threads in the forums
  • Answered 20 questions
answered
Veteran Member

Use $last_id = dblastid()

This is really bad practice, why you don't save current timestamp ( time() function)? You can do many things with timestamp
$month = date("m", posted);

Why?
$epoch = time();
$posted = $epoch;

Use $posted = time();
0 replies
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
answered
Senior Member

I've already changed $month = date("m", posted); to MONTH(CURDATE());
You're right; $epoch is just an old habit from previous infusions. I will change it. Thanks RobiNN.
0 replies
G
Grimloch
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
answered
Senior Member

That's not it RobiNN. I still get a fatal error. It doesn't like dblastid(); either.
0 replies
R
Anonymous User
R
Anonymous User 367
  • Veteran Member, joined since
  • Contributed 939 posts on the community forums.
  • Started 2 threads in the forums
  • Answered 20 questions
answered
Veteran Member

Ah you use v8. dblastid() is for v9.

V8 for some reason has this name db_lastid()
0 replies

Labels

None yet

Statistics

  • Views 0 views
  • Posts 4 posts
  • Votes 0 votes
  • Topic users 2 members

2 participants

G
G
Energy can neither be created nor destroyed; only transformed !
  • Senior Member, joined since
  • Contributed 722 posts on the community forums.
  • Started 141 threads in the forums
  • Started this discussions
  • Answered 2 questions
R
R
Anonymous User 367
  • Veteran Member, joined since
  • Contributed 939 posts on the community forums.
  • Started 2 threads in the forums
  • Answered 20 questions

Notifications

Track thread

You are not receiving notifications from this thread.

Related Questions

Not yet