Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

var_dump outputting empty string - php

Hi I am performing an SQL query (that only returns one row) and I am printing a particular column on screen just for test purposes. The problem I am having is, the column that I am printing contains a string of 12 characters (abcdef123456), yet sometimes the printed variable is empty. So when I do var_dump($test);

sometimes I get:

string(12) "abcdef123456"

but some other times I get

string(12) ""

I dont understand why it knows there are 12 characters yet its still empty, and sometimes it says 12 characters yet its full. Due to this, I cant perform other functions as they rely on the string.

EDIT: here is the query

$query="SELECT * FROM members WHERE name='$member'";
$sqlResult=mysql_query($query);
$row = mysql_fetch_assoc($sqlResult);
$test = $row["membercode"];
var_dump($test);
like image 522
Matt9Atkins Avatar asked Oct 19 '25 09:10

Matt9Atkins


2 Answers

Where do you see that it says string(12) ""? Remember to ALWAYS look in the raw output; the source code. Not how the browser renders it.

For instance, if the string is <span></span>, that'll show up as nothing.

like image 98
kba Avatar answered Oct 22 '25 00:10

kba


You most-likely have html tags in your string that are being rendered by the browser.

$foo = "<p><img><div><table>";
var_dump($foo); // string(20) ""
like image 22
Mike B Avatar answered Oct 21 '25 23:10

Mike B