brokenglass Posted November 6, 2014 Share Posted November 6, 2014 Hi guys, Here's my code: <?php $servername="127.0.0.1"; $username="root"; $password=""; $dbname="testdb"; $connection = new mysqli($servername,$username,$password,$dbname); $sql = "SELECT Wages FROM w WHERE \"Country\"=\"".$_POST["blah"]."\""; $r = $connection->query($sql); $result = $r->fetch_all(MYSQLI_ASSOC); echo $result; ?> When I go to the page I get the following message: Notice: Undefined index: w in C:\xampp\htdocs\test\processing.php on line 13 Does anyone know what problem I'm having here? /stuck Cheers, B Link to comment https://forums.phpfreaks.com/topic/292318-echo-sql-result/ Share on other sites More sharing options...
brokenglass Posted November 6, 2014 Author Share Posted November 6, 2014 Don't know how to edit OP but actual error is: Notice: Array to string conversion in C:\xampp\htdocs\test\processing.php on line 13 Link to comment https://forums.phpfreaks.com/topic/292318-echo-sql-result/#findComment-1495933 Share on other sites More sharing options...
brokenglass Posted November 6, 2014 Author Share Posted November 6, 2014 Also my actual code is: <?php $servername="127.0.0.1"; $username="root"; $password=""; $dbname="testdb"; $connection = new mysqli($servername,$username,$password,$dbname); $sql = "SELECT Wages FROM w WHERE Country=\"".$_POST["blah"]."\""; echo $sql; $r = $connection->query($sql); $result = $r->fetch_all(MYSQLI_ASSOC); echo $result; ?> Link to comment https://forums.phpfreaks.com/topic/292318-echo-sql-result/#findComment-1495934 Share on other sites More sharing options...
Barand Posted November 6, 2014 Share Posted November 6, 2014 fetch_all() returns and array of the returned rows which you would then loop through, as in your last posted topic. If you only expect a single row for the selected country then it is $r = $connection->query($sql); $result = $r->fetch_assoc(); echo $result['Wages']; Link to comment https://forums.phpfreaks.com/topic/292318-echo-sql-result/#findComment-1495935 Share on other sites More sharing options...
brokenglass Posted November 6, 2014 Author Share Posted November 6, 2014 Awesome, cheers mate. Link to comment https://forums.phpfreaks.com/topic/292318-echo-sql-result/#findComment-1495939 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.