vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Member Archives (https://vborg.vbsupport.ru/forumdisplay.php?f=202)
-   -   MySQL via VB interface code (https://vborg.vbsupport.ru/showthread.php?t=53680)

Cloudrunner 06-01-2003 03:39 PM

MySQL via VB interface code
 
Using $DB_site How would I go about testing a table for a specific unique identifier and have the system return a true or false?

What I have so far (and it doesn't work):
(assuming dbase.test[id] is always a unique identifier within the table)

PHP Code:


$testrecord 
$DB_site->query("SELECT id FROM test WHERE testid = $testid");
  if(!
$testrecord){
    echo 
"There is no record by this name!";
  } else {
    echo 
"Found the record!";
  } 

All I get is the VB warning stating that there is an error in the database when the record is not found. It works when the record is found though.

Any ideas how I could better test for this scenario? My brain is mushy from coding so long.

Thanks in advance!

Cloudrunner

filburt1 06-01-2003 04:12 PM

What's the error?

Also, never use ! except for boolean values or values of only 1 or 0. On a related note, check out the === versus the == operator to see why I'm saying that.

Cloudrunner 06-01-2003 08:20 PM

Got it!

Thanks Filburt. I appreciate it. Although the "===" is not the way that I went. I did the following:

PHP Code:


$testrecord 
$DB_site->query("SELECT * FROM test WHERE testid = '".$testid."'"); 
  if(
$DB_site->num_rows($testrecord) == 1){ 
    echo 
"Found the record!";
  } else { 
    echo 
"There is no record by this name!"
  } 

So basically if the record exists, I'll be able to update it. If it doesn't then I can add it.

Anyways, Thanks for the kick start. It works now so far.

Ciao!

Cloud


All times are GMT. The time now is 11:17 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.01164 seconds
  • Memory Usage 1,715KB
  • 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
  • (2)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (3)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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete