Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 08-08-2005, 09:18 AM
Vitesse Vitesse is offline
 
Join Date: Jun 2005
Location: Essex, UK
Posts: 41
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default MySQL / php help needed

Would someone be able to just check my code here and see where i've gone wrong.

PHP Code:
$query=" SELECT * FROM quartertime WHERE user='$user'";   //Query the DB to check if user exists
$result=mysql_query($query);
$num=mysql_numrows($result);
if (
$result !=0){                                    //if record already exists
             //amend it
} else {

// Create new record

}
//Rest of script 
Basically i just want to see if one or more records exist that match a username held in $user

the if/else is so if the record exists it amends all records with 'user'=$user
otherwise it makes a new record with their details. The code for adding/amending is already done and working just cant get the If/Else right

Many thanks
Reply With Quote
  #2  
Old 08-08-2005, 10:24 AM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Have you tried:

PHP Code:
 if ($result !=""){ 
Reply With Quote
  #3  
Old 08-08-2005, 10:40 AM
Logikos Logikos is offline
 
Join Date: Jan 2003
Posts: 2,924
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try this:
PHP Code:
$query mysql_query("
        SELECT *
        FROM quartertime
        WHERE user = '" 
$user "'
"
);

if (
mysql_num_rows($query))
{
        
// we found something!
}
else
{
        
//we didn't find anything!

Reply With Quote
  #4  
Old 08-08-2005, 10:57 AM
Vitesse Vitesse is offline
 
Join Date: Jun 2005
Location: Essex, UK
Posts: 41
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Just solved it (i hope)

PHP Code:
$query=" SELECT * FROM quartertime WHERE user='$user'";   $result=mysql_query($query); 
$num=mysql_numrows($result); 
if (
$num !=0){                                    
//Amend
} else { 
// Create new record

The underlying problem was that i had a ; further down in the script preventing it from creating new records <---- DOH


One other thing i need to do though, is check that $quartertime conforms to some criteria

it's a number figure to two decimal places....must be higher than 6, and in the followin format eg. 10.30, 11.99, 9.35 you get the idea, not overly sure how to check that.



Thanks for your assistance guys
Reply With Quote
  #5  
Old 08-08-2005, 11:02 AM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

And changing this:

PHP Code:
 if ($result !=0){ 
to this probably made a difference.

PHP Code:
 if ($num !=0){ 
Reply With Quote
  #6  
Old 08-08-2005, 11:11 AM
Vitesse Vitesse is offline
 
Join Date: Jun 2005
Location: Essex, UK
Posts: 41
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

well, that too LOL, i put $num and $result into the template so i could see what was going on and $result was returning a alhpanumeric tstring where $num was returning a numerical only result, anyone got any idea on checking the conformity of the $quartertime (edited in last post), i just know someone's gonna eventually realise they can add text in there and put something offensive on my site :P
Reply With Quote
  #7  
Old 08-08-2005, 11:30 AM
Logikos Logikos is offline
 
Join Date: Jan 2003
Posts: 2,924
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Couldn't you even do:
PHP Code:
if (!$num
{


Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:23 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.07096 seconds
  • Memory Usage 2,233KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (7)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete