Jump to content

Archived

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

SephirGaine

And I present to you.. more n00b questions!

Recommended Posts

Yeah. Most unfortunately. However, they [b]should[/b] be simple fixes, so I'll keep my fingers crossed for now and probably slap myself later when I realize how simply I messed up. BUT, here's what I've got. A dropdown box within a form. Within this dropdown box, it recalls data from a database. A work order number, the customer name, and whoever assigned that work. They select which work order they want to view, click submit, and it goes to an HTML file that generates the rest.

I've got two problems that have stemmed since I've attempted this.

The first, is that not all the word orders are displaying. When I had the list consisting of JUST the word order number, it displayed every work order within the database. However when I added more strings to the option, it only displays the first one.

My second problem. I'm trying to assign the order number to a variable so I can carry it over to the next page. This is where I feel very, very stupid. I've used variables off of forms perfectly, however I figured just using $_POST on the first page and $_GET on the next would work. I was wrong apparently.

Without further ado.. here's my code.

[code]<form action="prevwor.php" method="post">
<select name="prevwor3">
<?php
$query = "SELECT * FROM WOR";
$resource = mysql_query($query) or die("Error: ". mysql_error() ." in query");
if ($resource !== FALSE)
{
  if ($num_open = mysql_fetch_assoc($resource))
  {
    echo '<option>'.$num_open['work_order_num'].' - '.$num_open['Customer'].' - '.$num_open['EmpName'].'</option>';
  }
}
?>
</select>
<?php
$prevwor = $num_open['work_order_num'];
$_POST["$prevwor"];
?>[/code]

And for the next page, pertaining to the second problem..

[code]<?php
$ordernum = Trim(stripslashes($_POST['$prevwor']));
?>[/code]

Thanks in advance!

Share this post


Link to post
Share on other sites
first problem:
I don't usually use the mysql_fetch_assoc() function (and truth be told, i dont know what that does)... but I always use mysql_fetch_array()... you could try that and see if it works?

Share this post


Link to post
Share on other sites
second problem:
I don't believe you need the dollar sign in the $_POST variable:
[code=php:0]
<?php
$ordernum = Trim(stripslashes($_POST['prevwor']));
?>
[/code]

Share this post


Link to post
Share on other sites
I cant understand this line:
if ($num_open = mysql_fetch_assoc($resource))

mysql_fetch_assoc() doesnt reutn true or flase, it returns an array with the results.
If you want to echo all the results, enter this line into a while loop.

while($num_open = mysql_fetch_assoc($resource)){
echo....


Orio.

EDIT- @bpops- you are wrong about the "second problem". everything is fine over there (maybe "trim" being "Trim" is a problem, but I dont know).

Share this post


Link to post
Share on other sites
[quote author=Orio link=topic=103466.msg411973#msg411973 date=1155067295]
EDIT- @bpops- you are wrong about the "second problem". everything is fine over there (maybe "trim" being "Trim" is a problem, but I dont know).
[/quote]

ah, well i've never used that dollar sign in the post before, and it always worked for me. oh well

Share this post


Link to post
Share on other sites
Try
[code]<form action="prevwor.php" method="post">
<select name="prevwor3">
<?php
$query = "SELECT * FROM WOR";
$resource = mysql_query($query) or die("Error: ". mysql_error() ." in query");
if ($resource !== FALSE)
{
  if ($num_open = mysql_fetch_assoc($resource))
  do {
    echo "<option value='{$num_open['work_order_num']}'>".$num_open['work_order_num'].' - '.$num_open['Customer'].' - '.$num_open['EmpName'].'</option>';
  } while ($num_open = mysql_fetch_assoc($resource));
}
?>
</select>
<input type="submit" name="submit" value="Submit">
</form>[/code]

To process, note the select name is "prevwor3"
[code]<?php
$ordnum =  $_POST['prevvor3'];
echo $ordnum;
?>[/code]


@orio

all the mysql_fetch_xxx() functions return false when there are no more records

Share this post


Link to post
Share on other sites
[b]Barand,[/b] brilliant! The first part works just cool now, all the information is in the drop-down box and they all display correctly. However, the work order number is still having trouble being carried over to the next page. I've got the select name as prevwor3, and have this:

[code]<?php
$ordernum =  $_POST['prevvor3'];
?>[/code]

Inside of prevwor.php. However, nothing is being assigned to the variable it seems. Nothing shows when I attempt to echo it.

Share this post


Link to post
Share on other sites
check your spelling!

$_POST['prevvor3']; vs prevwor3 note the v's and w's

Share this post


Link to post
Share on other sites
..d'oh! That was simple enough. Thank god you guys can see what I'm too ignorant to notice.  ;) Thanks for the catch, and all the help!

Share this post


Link to post
Share on other sites

×

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.