php - Variable in SQL not recognized despite using advice from many websites -


my knowledge of html , css good, when comes php/sql knew ~0 until last week (developed multiple html/css-only websites) in summary: hired experienced former business partner (i trusted guy!) develop site...website looked great @ first (i looked on several times never hours @ time)...i paid former partner work....recently have had time really scrutinize website hours @ time....have found many bugs....partner not responding requests....i have learn php fix these bugs myself :)

here's 1 of issues: need retrieve 1 value (from variable 'wealth' users have part of statistics) sql database called 'stats' ascertain if, given user, 'wealth' (< 1) or (>= 1), cannot seem retrieve value. if wealth < 1, x, if wealth >= 1, y. worked fine except y executed value of wealth (including 0 , negative numbers). tried fix declaring global variable $stats9999 (i have tried local variable) fetches value sql database, problems start. here php code:

<?php session_start();  if ((($_session['role']) != sha1('user')) && (($_session['status']) != sha1('active')))        { header( 'location: index.php' ) ; session_destroy();  } else  include 'connect.php' ; //connects sql database fine  $_session['fname']; $_session['login_id']; $_session['user'];  $stats9999=mysql_fetch_assoc(mysql_query("select wealth stats login_id = '"      . mysql_real_escape_string($_session['login_id']) . "'")); //global $stats9999  if {.....} //several if...else if statements in row no problems here far  //can tell, 1 of problems in next series of lines of code   else if  ((($_post['hidden'] ) == 'function') && (($stats9999) == 0)) {      $message = 'text1';  echo "<script> alert('$message'); location = 'profile.php'; </script>";                }  else if  ((($_post['hidden'] ) == 'function') && (($stats9999) != 0)) {      $message = 'text2';  echo "<script> alert('$message'); location = 'profile.php'; </script>";                } 

the browser recognizes "function" , site behaves appropriately if not try account 'wealth' via $stats9999. however, problem $stats9999 not seem recognized. assuming browser somehow not "seeing/recognizing" sql database and/or database entry querying near beginning of code and/or not retrieving ("fetch"ing) entry want (i'm sure due mistake in code). experiment, have replaced ($stats9999 != 0) , ($stats9999 == 0) ($_session['user'] != " ") , ($_session['user'] == " "). code "sees/recognizes" these $_session values strings not equal " ", , site behaves in appropriate way. reinforces belief specific entry in 'stats' database not being "seen/recognized".

i have tested $stats9999 trying echo '$stats9999' (plus variations of name, wondering if makes difference think not) in alert box, in numerous variations have gotten various unwanted outcomes including (a) page crashes (b) blank alert box (c) resource id#2. code written above, site crashes.

i appreciate help, , happy clarify confusing statements have made....thank you!!

mysql_fetch_assoc returns associative array, keys column names in select query. you're trying use $stats9999 if it's scalar variable containing column. need write:

$wealth = $stats9999['wealth']; 

and can use $wealth in if statements.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -