vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   MySQL / php help needed (https://vborg.vbsupport.ru/showthread.php?t=93851)

Vitesse 08-08-2005 09:18 AM

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

Boofo 08-08-2005 10:24 AM

Have you tried:

PHP Code:

 if ($result !=""){ 


Logikos 08-08-2005 10:40 AM

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!



Vitesse 08-08-2005 10:57 AM

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 :)

Boofo 08-08-2005 11:02 AM

And changing this:

PHP Code:

 if ($result !=0){ 

to this probably made a difference. ;)

PHP Code:

 if ($num !=0){ 


Vitesse 08-08-2005 11:11 AM

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

Logikos 08-08-2005 11:30 AM

Couldn't you even do:
PHP Code:

if (!$num
{





All times are GMT. The time now is 11:47 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.01124 seconds
  • Memory Usage 1,733KB
  • 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
  • (7)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)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