vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   insert function HELP (https://vborg.vbsupport.ru/showthread.php?t=158548)

stonner 09-23-2007 04:24 PM

insert function HELP
 
1 Attachment(s)
I have a function to comment and rate photos.

It should insert the comment into the comment table in the DB. when i check it in the table, the comment-text and user_id are correctly inserted, but the photo_id is 0. (see screenshot)

Can someone help me with this?

Thank you very much




The function is the following:

Quote:

function hon_save_vote(){

$info = auth_member();

$sql_query = "SELECT photos FROM photo_votes WHERE mem_id=".$info["mem_id"];
$exclude = $GLOBALS["DB"]->single($sql_query);
$exclude_photos = handle_empties(explode(",",$exclude));

$rating = $GLOBALS["Get"]->type_val("rating","integer");
$pho_id = $GLOBALS["Get"]->type_val("rate_pho_id","integer");
$comment = $GLOBALS["Get"]->val("comment");

if(!in_array($pho_id,$exclude_photos)){

$sql_query = "UPDATE photos SET rating=rating+".$rating.",votes=votes+1 WHERE pho_id=".$pho_id;
$GLOBALS["DB"]->execute($sql_query);

$sql_query = "UPDATE photo_votes SET photos=CONCAT(photos,'".$pho_id.",') WHERE mem_id=".$info["mem_id"];
$updated = $GLOBALS["DB"]->update($sql_query);

if(!$updated){
$sql_query = "INSERT INTO photo_votes (mem_id,photos) VALUES (".$info["mem_id"].",'".$pho_id.",')";
$GLOBALS["DB"]->execute($sql_query);
}//if

}//if

if($comment){
$sql_query = "INSERT INTO photo_comments (pho_id,mem_id,comment)
VALUES (:pho_id:,:mem_id:,':comment:')";
$vals["pho_id"] = $pho_id;
$vals["mem_id"] = $info["mem_id"];
$vals["comment"] = $comment;
$GLOBALS["DB"]->values = $vals;
$GLOBALS["DB"]->execute($sql_query);
}//if

$p_details["page"] = "";
$p_details["section"] = "";
$p_details["items_file"] = "";

build_page($p_details);

}//hon_save_vote

Eikinskjaldi 09-23-2007 11:13 PM

Set the photo_id field as an auto incrementing primary key

stonner 09-24-2007 06:15 AM

comment_id is the key.

photo_id cannot be autoincrementing.

Dean C 09-24-2007 06:40 AM

You really should not be using the $GLOBALS array in PHP. It's a poor way of accessing your variables.

stonner 09-24-2007 07:01 AM

I don't know how else to do it.

Dean C 09-24-2007 07:08 AM

Well, using globals is generally bad practice. You should pass in your objects to the function as parameters, and use them like that :)

stonner 09-24-2007 07:11 AM

sorry, but i am unable to do this. i'm just glad if one way works..

Dean C 09-24-2007 07:15 AM

Well you're leaving yourself open to security risks. Incompetence is no excuse for lack of security my friend :) Security, education first. Code second...

stonner 09-24-2007 07:16 AM

you're welcome to code it for me.

Guest190829 09-24-2007 07:20 AM

Dean's time (and many coders for that matter) is probably more expensive than the time it takes to learn the foundations of programming and security and then applying it to your code.

I agree with Dean, if you want to learn how to code, take his advice. If you are under a rush or a deadline, you can hire a coder to do it properly.


All times are GMT. The time now is 08:44 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.06097 seconds
  • Memory Usage 1,732KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete