I'm running a query to display the number of rows returned from a select statement. (I know, it's simple, but I'm trying to learn this stuff from a book.) I get the desired message, but I also get the following message:
Record added
As far as I know, I shouldn't get that message when selecting data, because I'm not adding records. I've listed my code below, can someone explain why I'm getting this record added message?
Thanks:
<?php
// Wednesday, August 13, 2008 2:59:55 PM
// Connect to port 0000 on website.net.
$link = mysql_connect('website.net:0000', 'userid', 'testpw','testdb');
if (!$link) {
printf("Connect failed: %s\n", mysql_error());
exit();
} else {
include_once( 'add_record.php');
//
// select the database
$db_selected = mysql_select_db('testdb', $link);
if (!$db_selected) {
die ('Can\'t use testdb: ' . mysql_error());
}
//
$query ="select * from leadsTable";
// Perform Query
$result = mysql_query($query);
// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
} else {
$number_of_rows = mysql_num_rows($result);
printf("Number of rows: %d.\n", $number_of_rows);
}
}
?>
Query output:
Record added. Number of rows: 9.
PETERV
Syracuse, NY &
Boston, MA
Record added
As far as I know, I shouldn't get that message when selecting data, because I'm not adding records. I've listed my code below, can someone explain why I'm getting this record added message?
Thanks:
<?php
// Wednesday, August 13, 2008 2:59:55 PM
// Connect to port 0000 on website.net.
$link = mysql_connect('website.net:0000', 'userid', 'testpw','testdb');
if (!$link) {
printf("Connect failed: %s\n", mysql_error());
exit();
} else {
include_once( 'add_record.php');
//
// select the database
$db_selected = mysql_select_db('testdb', $link);
if (!$db_selected) {
die ('Can\'t use testdb: ' . mysql_error());
}
//
$query ="select * from leadsTable";
// Perform Query
$result = mysql_query($query);
// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
} else {
$number_of_rows = mysql_num_rows($result);
printf("Number of rows: %d.\n", $number_of_rows);
}
}
?>
Query output:
Record added. Number of rows: 9.
PETERV
Syracuse, NY &
Boston, MA