Jump to content


Photo

And I present to you.. more n00b questions!


  • Please log in to reply
8 replies to this topic

#1 SephirGaine

SephirGaine
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 08 August 2006 - 07:26 PM

Yeah. Most unfortunately. However, they should 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.

<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"];
?>

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

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

Thanks in advance!

#2 bpops

bpops
  • Members
  • PipPipPip
  • Advanced Member
  • 232 posts

Posted 08 August 2006 - 07:56 PM

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?


#3 bpops

bpops
  • Members
  • PipPipPip
  • Advanced Member
  • 232 posts

Posted 08 August 2006 - 07:59 PM

second problem:
I don't believe you need the dollar sign in the $_POST variable:
<?php
$ordernum = Trim(stripslashes($_POST['prevwor']));
?>


#4 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 08 August 2006 - 08:01 PM

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).
Think you're smarty?

(Gone until 20 to November)

#5 bpops

bpops
  • Members
  • PipPipPip
  • Advanced Member
  • 232 posts

Posted 08 August 2006 - 08:04 PM

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).


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

#6 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 08 August 2006 - 08:20 PM

Try
<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>

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


@orio

all the mysql_fetch_xxx() functions return false when there are no more records
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#7 SephirGaine

SephirGaine
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 08 August 2006 - 09:12 PM

Barand, 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:

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

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

#8 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 08 August 2006 - 09:17 PM

check your spelling!

$_POST['prevvor3']; vs prevwor3 note the v's and w's
follow me on twitter @PHPsycho

#9 SephirGaine

SephirGaine
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 08 August 2006 - 09:20 PM

..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!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users