mysql - Undefined variable error in PHP, code-logic -
$res = $mysqli->query("select anhid anhoriga pnr='".$_post['pnr2']."'"); while($row = $res->fetch_assoc()){ $anhid = array_shift($row); } $res = $mysqli->query("insert samband2 values(".$anhid.", ".$_post['pnr'].")"); this code gets me error line:
>notice: undefined variable: anhid in c:\xampp\htdocs\skapa.php on line 18. the last row of code line 18.
am stupid, or didn't define variable $anhid in previous code???! in specifics, i'm creating employee register, connected database containing info them.
$anhid in return variable(and primary key in database) contains unique id each of acquaintances employees.
$_post['pnr2'] contains social security number of acquaintance.
anhoriga table , spelled correctly.
please can explain i've done wrong?
declare anhid . looks sql not returning data. thats why anhid not getting set. var $anhid =""; $res = $mysqli->query("select anhid anhoriga pnr='".$_post['pnr2']."'"); while($row = $res->fetch_assoc()){ $anhid = array_shift($row); } if(!empty($anhid)){ $res = $mysqli->query("insert samband2 values(".$anhid.", ".$_post['pnr'].")"); } if think there multiple anhid should put insert inside while loop or if select returns 1 row , dont need while loop.
Comments
Post a Comment