Jump to content

php redirect


witham

Recommended Posts

I am quite new to php but I would really appreciate some help with this one, I have read and re-read the code and I still cannot get my head around it.

[code]<title>Search Database</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>

<!--html for the table which the sql data will populate-->

<table align = "center" border=0>
<tr>
<td colspan = 3 align = "center"><table width="100" border="0" cellspacing="10" cellpadding="10">
  <tr>
    <th scope="row"><img src="car.jpg" width="150" height="150"></th>
    <td><img src="gears.jpg" width="150" height="150"></td>
    <td><img src="wheel.jpg" width="150" height="150"></td>
    <td><img src="metalworking.jpg" width="150" height="150"></td>
    </tr>
</table></td></tr>
<form action="query.php" method="get">

<hr>
<tr><td colspan = 3><h2 align = "center" class="style2">CROSS REFERENCE PAGE</h2></td>
<tr><br>
<br
<tr>
  <td colspan = 2><h3 align=center><span class="style7">This screen allows users to obtain their equivalent to competitors products</span></h3></td></tr>
<tr><td><b>Manufacturer:</b></td>

<!--put the query $sqlMANUFACTURER into the $result variable or display error if query fails-->

<?

$result  = mysql_query($sqlMANUFACTURERS, $dblink)
or die("<p>Error Processing Query</p><hr /><p>".mysql_error()."</p>\n");


// mysql_fetch_array fetches the results from the query a row at a time and populates the drop down box each time it's called
// the result is returned as an array that can be referenced either by field name or by it's index, "ALL" is hardcoded because
//it is always constant and allows the % query to be executed


echo '<td><select name="Manufacturer">';
echo '<option value = "%"><b>ALL';
while ($row = mysql_fetch_array ($result))

// loop through the rows outputing them as select options
  {
echo '<option value="' . $row["MANNAME"] . '">' . $row["MANNAME"] . "</option>";
  }
?>
</select></td></tr>

<!--close select box-->

<!--The other part of the form is hardcoded as the types of lubricant are constant-->

<tr><td><b>Product Type:</b></td>
<td><select name="ProdType">
<option value= "%">ALL
<option value= "engine">ENGINE
<option value= "gear">GEAR
<option value= "hydraulic">HYDRAULIC
<option value= "agricultural">AGRICULTURAL
<option value= "specialist">SPECIALIST
</select></td></tr>

<!--Close the last selection box and put a submit button named "display results from equivalents database" to send the
data to query.php for processing-->
<tr><td colspan = 2 align = center class="style3"><button type="submit">DISPLAY RESULTS FROM EQUIVALENTS DATABASE</button></td></tr>


<p>&nbsp;</p>
<p><span class="style5">
  <!--put links to other parts of the site to bring everything together-->

</span>

</form>

<style type="text/css">
<!--

.combobox {
background-color: #000000;
color: #808080;
font-size: 12pt;
font-family: arial;
font-weight: bold;
}

-->
</style>

<form>
<table align=center border="0" width="80" cellspacing="0">
<tr><td width="100%" bgcolor="#000000">


<table border="0" width="100%" cellspacing="0" cellpadding="0">

</table>

<table border="0" width="100%" cellspacing="0" cellpadding="3">
<tr><td width="2%"

<select class="combobox" name="SiteMap" onchange="if(options[selectedIndex].value){location = options[selectedIndex].value}" size="1">
<option value="">PLEASE CHOOSE AN OPTION</option>
<option value="addprod.php">ADD A PRODUCT</option>
<option value="addman.php">ADD A MANUFACTURER</option>
<option value="delprod.php">DELETE A PRODUCT</option>
<option value="delman.php">DELETE A MANUFACTURER</option>
<option value="searchweld.php">SEARCH FOR A PRODUCT BY NAME</option>
<option value="amendprod.php">AMEND A PRODUCT</option>
</select>

</td></tr>
</table>
</form>
</body>
</html>[/code]

This is fine and sends the data to "query.php" for processing

[code]<?

if (empty($row)){
header("Location: addprod.php");
die ("opps");
}


$dbuser  = ''; // your database server user name
$dbhost  = 'localhost'; // name of the sql server
$dbpass  = ''; // your database server password
$dbname  = 'weld'; // the name of the database to connect to



// the sql query to send to the database so that the results page can be built dynamically
$sqlSELECT = "SELECT MANNAME, prodtype, proddesc, prodnar, prodequiv FROM man, produse, prodname
  where MANNAME like '$Manufacturer'
  and prodtype like '$ProdType'
  and prodid = useid
                  and manno = MANID
  order by MANNAME;";


$sqlCOMPARE = "SELECT * from prodname, man where manno = manid;";


?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<head>

<!-- set style for page -->

<title>W.E.L.D.</title>
</head>
<body>

<?
// mysql_connect connects to the database server and returns a link to the the resource
$dblink = @mysql_connect("$dbhost","$dbpass")
or die("<p><b>Could not connect to database server: ($dbhost)</b></p>\n");

// mysql_select_db selects a database to use on the database server pointers to by $dblink
// the @ sign before the command supresses any error messages
@mysql_select_db ($dbname , $dblink)
or die ("<p><b>Could not connect to database ($dbname)</b></p>\n");


// now execute the next query to return the table data to display
$result  = mysql_query($sqlSELECT, $dblink)
or die("<p>Error Processing Query</p><hr /><p>".mysql_error()."</p>\n");

// output the table and the first row headings


echo'<table align = "center" border=0>' . "\n";
echo'<tr><td colspan = 3 align = "center"><table width="100" border="0" cellspacing="10" cellpadding="10">
  <tr>
    <th scope="row"><img src="car.jpg" width="150" height="150"></th>
    <td><img src="gears.jpg" width="150" height="150"></td>
    <td><img src="wheel.jpg" width="150" height="150"></td>
    <td><img src="metalworking.jpg" width="150" height="150"></td>
    </tr>
</table></td></tr>';

echo '<table align = "center" border="1" cellspacing="2" cellpadding="2">' . "\n";
echo "<tr bgcolor = #000000><td>MANUFACTURER</td><td>PRODUCT TYPE</td><td>PRODUCT NAME</td><td>PRODUCT DESCRIPTION</td><td>PRODUCT EQUIVALENT</td></tr>\n";


// mysql_fetch_array fetches the results from the query a row at a time using a while loop each time it's called
// the result is returned as an array that can be referenced either by field name or by it's index
while ($row = mysql_fetch_array ($result))
// loop through the rows outputing them as html table rows


{

// $row["fieldname"] returns the content for the field in the current row

  echo "<tr><td>" .$row["MANNAME"].  "</td>";

  echo "<td>"  .$row["prodtype"].  "</td>";

  echo "<td>"  .$row["proddesc"].  "</td>";

echo "<td>"  .$row["prodnar"]. "</td>";

  echo "<td>"  .$row["prodequiv"].  "</td></tr>";



}

// close html table tag
echo "</table>\n";

// the mysql_free_result command removes any resources relating to the query results
// this happens automatically at the end of the script but still better to free up now
mysql_free_result ($result);

// the mysql_close command severs the link to the database, with scripts that make multiple
// queries on the same database the command only needs to be done once after all queries are completed
@mysql_close ($dblink)
or die( "<p><b>Error while closing connection to database server:" .
        "($dbhost)</b></p>");

?>

<!-- put in a link returning the user to the original page -->

<p><a href="querytry1.php">Return to the data entry page
    </a></p>
</body>
</html>[/code]

all I want to do is send the user to another page if there are no rows, I am using:

[code]if (empty($row)){
header("Location: addprod.php");
die ("opps");
}[/code]

I have also tried the mysql_num_rows statement but either I have got this wrong or more likely miscoded?

Many Thanks

[b]EDITED BY WILDTEEN88: PLEASE USE THE CODE TAGS WHEN SUBITTING CODE TO THE FORUM[/B]
Link to comment
https://forums.phpfreaks.com/topic/16714-php-redirect/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.