Question : var dump not working correctly

hello there,
i am trying to see the results of the mysql update to see if mysql updated the record or it got an error..
when I try to use the var dump i get bool(false) whats can cause this?
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
function GetMyConnection() {
    global $var;
    if( $var )
        return $var;
    $var = mysql_connect( 'localhost', 'root', 'pass') or die('Could not connect to server.' );
    mysql_select_db('db_site_forum', $var) or die('Could not select database.');
    return $var;
}
 
$connection = GetMyConnection();
$qu3 = mysql_query('UPDATE post SET pagetext="'.$post.'" WHERE postid='.$pid, $connection);
var_dump($qu3);
Open in New Window Select All

Answer : var dump not working correctly

Here is my "teaching sample" for how to do a few simple MySQL activities.  Note the extensive use of error checking!  Copy and Paste as needed.

Best, ~Ray
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
NO DB CONNECTION: ";
   echo "
$errmsg
"; } // SELECT THE MYSQL DATA BASE // MAN PAGE: http://us2.php.net/manual/en/function.mysql-select-db.php if (!$db_sel = mysql_select_db($db_name, $db_connection)) { $errmsg = mysql_errno() . ' ' . mysql_error(); echo "
NO DB SELECTION: "; echo "
$errmsg
"; die('NO DATA BASE'); } // IF WE GOT THIS FAR WE CAN DO QUERIES // ESCAPING A DATA FIELD FOR USE IN MYSQL QUERIES // MAN PAGE: http://us2.php.net/manual/en/function.mysql-real-escape-string.php $username = mysql_real_escape_string($_POST["username"]); // CREATING AND SENDING A SELECT QUERY AND TESTING THE RESULTS // MAN PAGE:http://us2.php.net/manual/en/function.mysql-query.php $sql = "SELECT id FROM my_table WHERE username='$username'"; $res = mysql_query($sql); // IF mysql_query() RETURNS FALSE, GET THE ERROR REASONS if (!$res) { $errmsg = mysql_errno() . ' ' . mysql_error(); echo "
QUERY FAIL: "; echo "
$sql
"; die($errmsg); } // IF WE GET THIS FAR, THE QUERY SUCCEEDED AND WE HAVE A RESOURCE-ID IN $res SO WE CAN NOW USE $res IN OTHER MYSQL FUNCTIONS // DETERMINE HOW MANY ROWS OF RESULTS WE GOT // MAN PAGE: http://us2.php.net/manual/en/function.mysql-num-rows.php $num = mysql_num_rows($res); if (!$num) { echo "
QUERY FOUND NO DATA: "; echo "
$sql
"; } else { echo "
QUERY FOUND $num ROWS OF DATA "; echo "
$sql
"; } // A WAY OF DETERMINING HOW MANY ROWS WE HAVE IN A TABLE // MAN PAGE:http://us.php.net/mysql_fetch_array $sql = "SELECT COUNT(*) FROM my_table"; $res = mysql_query($sql); // IF mysql_query() RETURNS FALSE, GET THE ERROR REASONS if (!$res) { $errmsg = mysql_errno() . ' ' . mysql_error(); echo "
QUERY FAIL: "; echo "
$sql
"; die($errmsg); } // GET THE RESULTS SET ROW IN AN ARRAY WITH A NUMERIC INDEX - POSITION ZERO IS THE COUNT $row = mysql_fetch_array($res, MYSQL_NUM); $num = $row[0]; // ITERATE OVER THE RESULTS SET TO SHOW WHAT WE FOUND // MAN PAGE: http://us2.php.net/manual/en/function.mysql-fetch-assoc.php echo "
\n"; // MAKE IT EASY TO READ
while ($row = mysql_fetch_assoc($res))
{
   var_dump($row); // MAN PAGE: http://us2.php.net/manual/en/function.var-dump.php
}
 
 
 
 
// MAKING AN INSERT QUERY AND TESTING THE RESULTS
$sql = "INSERT INTO my_table (username) VALUES (\"$username\")";
$res = mysql_query($sql);
 
// IF mysql_query() RETURNS FALSE, GET THE ERROR REASONS
if (!$res)
{
   $errmsg = mysql_errno() . ' ' . mysql_error();
   echo "
QUERY FAIL: "; echo "
$sql
"; die($errmsg); } // IF WE GET THIS FAR, THE QUERY SUCCEEDED AND WE HAVE A RESOURCE-ID IN $res SO WE CAN NOW USE $res IN OTHER MYSQL FUNCTIONS // GET THE AUTO_INCREMENT ID OF THE RECORD JUST INSERTED // MAN PAGE: http://us2.php.net/manual/en/function.mysql-insert-id.php $id = mysql_insert_id($res);
Open in New Window Select All
Random Solutions  
 
programming4us programming4us