php - check the manual that corresponds to your MySQL server version -


can't figure out what's problem code

keep getting error on

notice: undefined index: userid in c:\wamp\www\myproject\editprofile\edit_save.php on line 10

and

could not run query: have error in sql syntax; check manual corresponds mysql server version right syntax use near '(userid, matrix_num,student ,username ,town ,email , txtfavorite,nodate,txtmobil' @ line 1

if($_get) { $noedit = $_post[''];               //"select *from " $sql        = "select * tblmyprofile student='$name', username='$username', matrix_num='$matric', town='$town' ,                   mail='$email'"; $query      = mysql_query($sql, $masuk,$boleh) or die ("gagal query".mysql_error()); $data       = mysql_fetch_array($query); } 

the comma operator invalid in clause.

it looks wanted logical and or or operators. query of form this:

select t.*    tblmyprofile t  t.student = 'fee'    , t.username = 'fi'    , t.matrix_num = 'fo'    , t.town = 'fum'    , t.mail = 'foo' 

but that's odd construct sql query; there's nothing invalid it. usually, select, we're intending retrieve rows based on few predicates, , getting values row back.

for debugging issues sql queries, it's idea string sql text intend send database, , echo (or printf or vardump) string, e.g.

$sql = "select col, expr, col mytable col = 'abc'"; echo $sql; 

then, reference $sql in call parse , execute sql statement.

i believe part of issue encountering may construction of string containing sql text. languages persnickety including variables , quotes within string literals.

e.g.

$sql = " t.fee = '" . mysql_real_escape_string($foo) . "'"      . " , t.fi = '" . mysql_real_escape_string($bar) . "'"      . ...  ; 

again, after put sql text, echo out debugging, , verify it's string intend send database.


also note mysql_ interface deprecated. new development should using mysqli_ or pdo. note including unsafe variables in sql text can lead sql injection vulnerabilities. either "escape" special characters in variables include in sql text, or better, use prepared statements bind parameters, avoid sql injection.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -