I'm trying to figure out how some code works. This is from the book "Web
Database Applications with PHP and MySQL".
The books says "If the region name and description are both not empty, an
INSERT SQL statement is prepared to insert the new region,"
From the looks of "if (empty($regionName) || empty($description)) it seems
that it is the opposite. It looks like "if $regionname or $description are
empty, then....."
Next question. How does the PHP code know that regionName and description in
the Javascript code are $regionName and $description in the PHP code?
Also having problems following the order of the code. What it appears to be
saying is if $regionName and $description are empty then run the <form>,
else if no connection to the database can be established kill everything,
else if could not connect to the DB connection, run showerror() , otherwise
run the insertQuery statement, then not sure what
if ((@ mysql_query ($insertQuery,
$connection))
&& @ mysql_affected_rows() == 1)
echo "<h3>Region successfully inserted</h3>";
else
showerror();
is doing.
What does the && represent. Could not find it in the php manual. Thanks in
advance for any help.
<html>
<head>
<title>Insert a Region</title>
</head>
<body>
<?php
include 'db.inc';
include 'error.inc';
// Test for user input
if (empty($regionName) || empty($description))
{
?>
<form method="GET" action="example.6-1.php">
Region_name:
<br><input type="text" name="regionName" size=80>
<br>Description:
<br><textarea name="description" rows=4 cols=80></textarea>
<br><input type="submit">
</form>
<?php
}
else
{
if (!($connection = @ mysql_connect($hostName,
$username,
$password)))
die("Could not connect to database"
;
if (!mysql_select_db($databaseName, $connection))
showerror();
$insertQuery = "INSERT INTO region VALUES (NULL, " .
"\"" . $regionName . "\", " .
"\"" . $description . "\", " .
"NULL)";
if ((@ mysql_query ($insertQuery,
$connection))
&& @ mysql_affected_rows() == 1)
echo "<h3>Region successfully inserted</h3>";
else
showerror();
} // if else empty()
?>
</body>
</html>
Database Applications with PHP and MySQL".
The books says "If the region name and description are both not empty, an
INSERT SQL statement is prepared to insert the new region,"
From the looks of "if (empty($regionName) || empty($description)) it seems
that it is the opposite. It looks like "if $regionname or $description are
empty, then....."
Next question. How does the PHP code know that regionName and description in
the Javascript code are $regionName and $description in the PHP code?
Also having problems following the order of the code. What it appears to be
saying is if $regionName and $description are empty then run the <form>,
else if no connection to the database can be established kill everything,
else if could not connect to the DB connection, run showerror() , otherwise
run the insertQuery statement, then not sure what
if ((@ mysql_query ($insertQuery,
$connection))
&& @ mysql_affected_rows() == 1)
echo "<h3>Region successfully inserted</h3>";
else
showerror();
is doing.
What does the && represent. Could not find it in the php manual. Thanks in
advance for any help.
<html>
<head>
<title>Insert a Region</title>
</head>
<body>
<?php
include 'db.inc';
include 'error.inc';
// Test for user input
if (empty($regionName) || empty($description))
{
?>
<form method="GET" action="example.6-1.php">
Region_name:
<br><input type="text" name="regionName" size=80>
<br>Description:
<br><textarea name="description" rows=4 cols=80></textarea>
<br><input type="submit">
</form>
<?php
}
else
{
if (!($connection = @ mysql_connect($hostName,
$username,
$password)))
die("Could not connect to database"

if (!mysql_select_db($databaseName, $connection))
showerror();
$insertQuery = "INSERT INTO region VALUES (NULL, " .
"\"" . $regionName . "\", " .
"\"" . $description . "\", " .
"NULL)";
if ((@ mysql_query ($insertQuery,
$connection))
&& @ mysql_affected_rows() == 1)
echo "<h3>Region successfully inserted</h3>";
else
showerror();
} // if else empty()
?>
</body>
</html>