yosra Posted April 13, 2013 Share Posted April 13, 2013 when i try to execute this code i always have a problem . and i can't get the element i m searching for in the database //select the CODE from nxcp_code $sql= "select value from nxcp_code where name = '$name'" ; $res=mysql_query($sql); if( !$res ) {throw new Exception(mysql_error(),mysql_errno());} $codeArray = mysql_fetch_assoc($res); //This fetch the first row of the result to an array with numeric indexes. if( !$codeArray ){ throw new Exception('Code not found');} //somevhere you should catch it $code =$codeArray[0]; any help please thanks in advance Link to comment https://forums.phpfreaks.com/topic/276911-undefined-offset-0/ Share on other sites More sharing options...
gizmola Posted April 13, 2013 Share Posted April 13, 2013 You are using mysql_fetch_assoc. $codeArray = mysql_fetch_assoc($res); This returns you an array where the elements are the column names. In your case, it would be 'value'. Try: $code = $codeArray['value']; Link to comment https://forums.phpfreaks.com/topic/276911-undefined-offset-0/#findComment-1424587 Share on other sites More sharing options...
yosra Posted April 13, 2013 Author Share Posted April 13, 2013 thank u very much that worked Link to comment https://forums.phpfreaks.com/topic/276911-undefined-offset-0/#findComment-1424588 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.