Discussion:
PHP Mystery
Ethan Rosenberg, PhD
2014-06-22 05:00:17 UTC
Permalink
Dear List -

Here is a simple program.

It ran before, but not now...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<html>
<head>
</head>
<body>
<div align="center">
<form method="post">
<input type='text' name=phone></input>
<input type='submit'>
<br /><br /><br />
</form>
</div>
<?php
error_reporting(-1);
require '/home/ethan/PHP/ethan.inc';
$db = "Store";
$cxn = mysqli_connect($host,$user,$password,$db);
if (!$cxn)
{
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}

//if no connection no error message

$phn = $_POST[phone];

//Phone is a 10 digit numerical string, no spaces

$phn = (string)$phn;

$dsh = '-';
$Phn =
$phn[0].$phn[1].$phn[2].$dsh.$phn[3].$phn[4].$phn[5].$dsh.$phn[6].$phn[7].$phn[8].$phn[9];

//construct phone number 123-466-7890

$sql1 ="select Lname, Fname from Customers where Phone = '$Phn' ";

$result1 = mysqli_query($cxn, $sql1);
if(!$result1)
{
?>
<div align="center">

<strong>No Match Found</strong>
<br /><br />
</div>
<?php
}

//if query fails, no error message.


//code to display query results, not listed.



TIA

Ethan
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Ashley Sheridan
2014-06-22 07:39:22 UTC
Permalink
Post by Ethan Rosenberg, PhD
Dear List -
Here is a simple program.
It ran before, but not now...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html>
<head>
</head>
<body>
<div align="center">
<form method="post">
<input type='text' name=phone></input>
<input type='submit'>
<br /><br /><br />
</form>
</div>
<?php
error_reporting(-1);
require '/home/ethan/PHP/ethan.inc';
$db = "Store";
$cxn = mysqli_connect($host,$user,$password,$db);
if (!$cxn)
{
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
//if no connection no error message
$phn = $_POST[phone];
//Phone is a 10 digit numerical string, no spaces
$phn = (string)$phn;
$dsh = '-';
$Phn =
$phn[0].$phn[1].$phn[2].$dsh.$phn[3].$phn[4].$phn[5].$dsh.$phn[6].$phn[7].$phn[8].$phn[9];
//construct phone number 123-466-7890
$sql1 ="select Lname, Fname from Customers where Phone = '$Phn' ";
$result1 = mysqli_query($cxn, $sql1);
if(!$result1)
{
?>
<div align="center">
<strong>No Match Found</strong>
<br /><br />
</div>
<?php
}
//if query fails, no error message.
//code to display query results, not listed.
TIA
Ethan
How is it failing? When you say no error message, do you mean none displayed? It's unusual for an error not to appear in your error logs. Have you checked them?

Thanks,
Ash
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jasper Kips
2014-06-22 10:07:44 UTC
Permalink
The problem lies in this statement: if(!$result1).
Mysqli_query returns returns an object, except when the query fails. The query doesn't fail when the number of found rows is zero. So, if your query is syntactically correct, but there is no data found, $result1 is not false, but an object.
Do a test for $result1->num_rows, like this: if ( 0 === $result1->num_rows ) echo "No data found".

Jasper

Verstuurd vanaf mijn iPad
Post by Ethan Rosenberg, PhD
Dear List -
Here is a simple program.
It ran before, but not now...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html>
<head>
</head>
<body>
<div align="center">
<form method="post">
<input type='text' name=phone></input>
<input type='submit'>
<br /><br /><br />
</form>
</div>
<?php
error_reporting(-1);
require '/home/ethan/PHP/ethan.inc';
$db = "Store";
$cxn = mysqli_connect($host,$user,$password,$db);
if (!$cxn)
{
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
//if no connection no error message
$phn = $_POST[phone];
//Phone is a 10 digit numerical string, no spaces
$phn = (string)$phn;
$dsh = '-';
$Phn = $phn[0].$phn[1].$phn[2].$dsh.$phn[3].$phn[4].$phn[5].$dsh.$phn[6].$phn[7].$phn[8].$phn[9];
//construct phone number 123-466-7890
$sql1 ="select Lname, Fname from Customers where Phone = '$Phn' ";
$result1 = mysqli_query($cxn, $sql1);
if(!$result1)
{
?>
<div align="center">
<strong>No Match Found</strong>
<br /><br />
</div>
<?php
}
//if query fails, no error message.
//code to display query results, not listed.
TIA
Ethan
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Mike (iLL) Kilmer
2014-06-22 12:29:22 UTC
Permalink
And var_dump($result1) will post the contents of $result1 to the screen, which can be really useful for dev.
Post by Jasper Kips
The problem lies in this statement: if(!$result1).
Mysqli_query returns returns an object, except when the query fails.
The query doesn't fail when the number of found rows is zero. So, if
your query is syntactically correct, but there is no data found,
$result1 is not false, but an object.
Do a test for $result1->num_rows, like this: if ( 0 ===
$result1->num_rows ) echo "No data found".
Jasper
Verstuurd vanaf mijn iPad
Op 22 jun. 2014 om 07:00 heeft "Ethan Rosenberg, PhD"
Dear List -
Here is a simple program.
It ran before, but not now...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html>
<head>
</head>
<body>
<div align="center">
<form method="post">
<input type='text' name=phone></input>
<input type='submit'>
<br /><br /><br />
</form>
</div>
<?php
error_reporting(-1);
require '/home/ethan/PHP/ethan.inc';
$db = "Store";
$cxn = mysqli_connect($host,$user,$password,$db);
if (!$cxn)
{
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
//if no connection no error message
$phn = $_POST[phone];
//Phone is a 10 digit numerical string, no spaces
$phn = (string)$phn;
$dsh = '-';
$Phn =
$phn[0].$phn[1].$phn[2].$dsh.$phn[3].$phn[4].$phn[5].$dsh.$phn[6].$phn[7].$phn[8].$phn[9];
//construct phone number 123-466-7890
$sql1 ="select Lname, Fname from Customers where Phone =
'$Phn' ";
$result1 = mysqli_query($cxn, $sql1);
if(!$result1)
{
?>
<div align="center">
<strong>No Match Found</strong>
<br /><br />
</div>
<?php
}
//if query fails, no error message.
//code to display query results, not listed.
TIA
Ethan
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
Jim Giner
2014-06-22 12:55:06 UTC
Permalink
Post by Ethan Rosenberg, PhD
Dear List -
Here is a simple program.
It ran before, but not now...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html>
<head>
</head>
<body>
<div align="center">
<form method="post">
<input type='text' name=phone></input>
<input type='submit'>
<br /><br /><br />
</form>
</div>
<?php
error_reporting(-1);
require '/home/ethan/PHP/ethan.inc';
$db = "Store";
$cxn = mysqli_connect($host,$user,$password,$db);
if (!$cxn)
{
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
//if no connection no error message
$phn = $_POST[phone];
//Phone is a 10 digit numerical string, no spaces
$phn = (string)$phn;
$dsh = '-';
$Phn =
$phn[0].$phn[1].$phn[2].$dsh.$phn[3].$phn[4].$phn[5].$dsh.$phn[6].$phn[7].$phn[8].$phn[9];
//construct phone number 123-466-7890
$sql1 ="select Lname, Fname from Customers where Phone = '$Phn' ";
$result1 = mysqli_query($cxn, $sql1);
if(!$result1)
{
?>
<div align="center">
<strong>No Match Found</strong>
<br /><br />
</div>
<?php
}
//if query fails, no error message.
//code to display query results, not listed.
TIA
Ethan
I fail to see how this script can do anything since you output an html
form that has errors in it (you just don't see the value in '' marks, do
you?) and then attempt to use php to process results. Is this just
sloppy programming and did you already run this script once to put this
same form out to the client?
Plus you insist on using deprecated styles in your tags. Also you
really must get used to wrapping your literal array indices in quotes
because it is going to bite you you-know-where one of these days.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Loading...