ptanewbe Posted April 18, 2014 Share Posted April 18, 2014 Hi all, I am new to this (programmed on mainframe many years). I created a dropdown selection populated from an SQL table. my problem is if I use mysql_*, the selection is populated and works correct but if I change the mysql_* to mysqli_*, it will not work (I know my connect and slect database work, because i do not go into "or die" part). My coding below: $intIdField = 'code'; $strNameField = 'name'; $strTableName = 'country'; $strNameOrdinal = 'name'; $strMaskName = 'select country'; $strOrderField = 'name'; $strMethod="ASC"; echo "<select name=\"$strNameOrdinal\">\n"; echo "<option value=\"NULL\">".$strMaskName."</option>\n"; $strQuery = "select $intIdField, $strNameField from $strTableName order by $strOrderField $strMethod"; if (!$strQuery) { die("query failed:" . mysql_error()); } echo mysql_query ("set character_set_results='utf8'"); $rsrcResult = mysql_query($strQuery); while($arrayRow = mysql_fetch_assoc($rsrcResult)) { echo $row["name"]; echo $row["code"]; $strA = $arrayRow["$intIdField"]; $strB = $arrayRow["$strNameField"]; echo "<option value=\"$strA\">$strB</option>\n"; } echo "</select>"; It only populates the block with "select country" but if you click on the down arrow, notyhing comes up. as I say, the above coding work but as soon as I change to mysqli, it does not, what am I doing wrong? Thank you in advance Quote Link to comment https://forums.phpfreaks.com/topic/287865-mysql_-versus-mysqli_/ Share on other sites More sharing options...
mac_gyver Posted April 18, 2014 Share Posted April 18, 2014 since you didn't post the mysqli_ version of the code, how could we possibly help with what might be wrong with that version of the code? also, in the following code, why are you testing the sql query statement string variable? - if (!$strQuery) { die("query failed:" . mysql_error()); } all that code is doing is testing if the sql string is true/false. Quote Link to comment https://forums.phpfreaks.com/topic/287865-mysql_-versus-mysqli_/#findComment-1476575 Share on other sites More sharing options...
boompa Posted April 18, 2014 Share Posted April 18, 2014 If you look at the manual for mysqli_query, you'll see that it takes an extra first variable. Quote Link to comment https://forums.phpfreaks.com/topic/287865-mysql_-versus-mysqli_/#findComment-1476576 Share on other sites More sharing options...
therocker Posted April 18, 2014 Share Posted April 18, 2014 You're going to have to do a lot of work. But let's start off with this first. I turned your code into $mysqli and I tested it and I found that $row doesn't exist in the while. Where is it coming from? Also you should never echo out your errors. It should only be used during your debugging process. Otherwise, you should never put it live. Quote Link to comment https://forums.phpfreaks.com/topic/287865-mysql_-versus-mysqli_/#findComment-1476613 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.