PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
hward
Forum Contributor
Posts: 107 Joined: Mon Apr 19, 2004 6:19 pm
Post
by hward » Wed Apr 21, 2004 5:17 pm
Code: Select all
if what_stock = stock_num {
header("Location: /error.html");
exit;
} else {
session_start();
}
what_stock in coming in from previous page
stock_num is out of the database
i wanted to add this to a search page that i don't want it to return any results and redirect to another page if there not the same
the page as it is now works fine but when you search a number thats not in the database it just returns the results as empty
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Wed Apr 21, 2004 5:37 pm
Code: Select all
if ($what_stock == $stock_num) {
header("Location: /error.html");
exit;
} else {
//................
just corrected your syntax errors
hward
Forum Contributor
Posts: 107 Joined: Mon Apr 19, 2004 6:19 pm
Post
by hward » Wed Apr 21, 2004 5:50 pm
now i am getting a parser error after i add it in
Code: Select all
<?PHP
if ($what_stock == $stock_num) {
header("Location: /error.html");
exit;
} else {
//................
// connect to database
$database = "*******";
$table_name = "items";
$connection = @mysql_connect("localhost", "*******", "*******")
or die("Couldn't connect.");
$db = @mysql_select_db($database, $connection)
or die("Couldn't select database.");
// ----------------------------
// create the sql statement
$sql = "SELECT stock_num, price, cost, item_type, item_disc, photo
FROM $table_name WHERE stock_num = ($what_stock)";
// execute the sql statement
$result = mysql_query($sql, $connection) or die("problem here");
?>
<?PHP
while ($row = mysql_fetch_array($result)) {
// get data from the current row
$qty = $rowї"qty"];
$price = $rowї"price"];
$cost = $rowї"cost"];
$item_disc = $rowї"item_disc"];
$photo = $rowї"photo"];
?>
<p> </p>
<p> </p>
<p>
<?PHP
}
?>
<div align="left">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="389" height="127" id="AutoNumber1">
<tr>
<td width="195" height="124" rowspan="3">
<p align="center"><img name="photo" src="/test/pictures/<?PHP echo $photo; ?>" width="151" height="128" alt=""> </td>
<td width="194" height="1"> Stock#<form method="POST" action="/test/do_delcontact.php"><input type="text" name="del_item" size="20"value="<?PHP echo $what_stock; ?>"></td>
</tr>
<tr>
<td width="194" height="11"> Description:</td>
</tr>
<tr>
<td width="194" height="50">
<p align="justify"><?PHP echo $item_disc; ?></td>
</tr>
<tr>
<td width="194" height="29"> Price $<?PHP echo $price; ?></td>
<td width="194" height="29"> Quantity :<?PHP echo $qty; ?> </td>
</tr>
<tr>
<td width="194" height="28"> Cost $<?PHP echo $cost; ?></td>
</tr>
</table>
</div>
</p>
<input type="submit" value="Delete" name="delete"></p>
</form>
</html>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Apr 21, 2004 5:54 pm
......and the error is.........?
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Wed Apr 21, 2004 5:55 pm
sure you have. I used
//........
to omit the code that you don't need to change.
Here is full version
Code: Select all
if ($what_stock == $stock_num) {
header("Location: /error.html");
exit;
} else {
session_start();
}
hward
Forum Contributor
Posts: 107 Joined: Mon Apr 19, 2004 6:19 pm
Post
by hward » Wed Apr 21, 2004 5:56 pm
Parse error: parse error in /home/kmartin/www/admin/search.php on line 88
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Wed Apr 21, 2004 5:56 pm
feyd wrote: ......and the error is.........?
unmatched curly brace =)
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Apr 21, 2004 5:59 pm
btw, hward, your table's going to look funny leaving some cells out.
hward
Forum Contributor
Posts: 107 Joined: Mon Apr 19, 2004 6:19 pm
Post
by hward » Wed Apr 21, 2004 6:09 pm
ok found the error but it still does the same thing that it did before it is returning empty tables instead of redirecting
hward
Forum Contributor
Posts: 107 Joined: Mon Apr 19, 2004 6:19 pm
Post
by hward » Wed Apr 21, 2004 6:11 pm
oh and on the empty table thing i mean its returning a complete empty table when the search doesn't match anything in the database
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Apr 21, 2004 6:13 pm
header("Location: ...
needs full url last I checked.
hward
Forum Contributor
Posts: 107 Joined: Mon Apr 19, 2004 6:19 pm
Post
by hward » Wed Apr 21, 2004 6:20 pm
got it it needed a !
if (!$what_stock == $stock_num)
hward
Forum Contributor
Posts: 107 Joined: Mon Apr 19, 2004 6:19 pm
Post
by hward » Wed Apr 21, 2004 6:21 pm
thanks everyone
Unipus
Forum Contributor
Posts: 409 Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA
Post
by Unipus » Wed Apr 21, 2004 6:22 pm
That looks like weird syntax to me, it may not always do what you expect. I think you might want:
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Apr 21, 2004 6:26 pm
your operator precedence is screwy...
!$what_stock inverts the boolean value of $what_stock.
the page will likely redirect if $stock_num isn't 0 or 1, or if $what_stock is nonzero and $stock_num is anything.
I think what you're really looking for is