need to pass information for one item from a page with multiple results
I am creating a database that will be filled with items for sale. I am trying to create a back end so that the items can be edited, currently I am working on the pictures that will be uploaded for the items. I need to make it so that I can upload multiple pictures for each individual item. I have almost everything working however when I try to select the specific item from a page that lists all the items in the database I run into my problems. I have tried using select buttons but I am missing on passing only the one items id through to the next page and I wind up passing all of the ids along and get errors. Can anyone help? here is the code I am working with:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Vehicle Select</title>
</head>
<body onUnload="window.addEventListener("unload", invalidateBackCache, true)>
<center>
<?php
$result = mysql_query("SELECT * FROM inventory")
or die(mysql_error());
echo "<table border = '1'>";
echo "<tr><th>ID</th><th>Description</th></tr>";
while($row = mysql_fetch_array($result))
{
//print out the contents of each row
echo "<tr><td>";
echo $row['id'];
$refId = $row['id'];
echo "</td><td>";
echo $row['description'];
echo "</td><td>";
?>
<form action="picUploads.php" method="post"
enctype="multipart/form-data">
<input type="hidden" name="refID" value=<?php echo $refId; ?> /></td><td><input type="submit" name="submit" value="Select" />
<?php
echo "</td></tr>";
}
echo "</table>";
switch($refId)
{
}
?><br /><br />
<a href = addInventory.php><input type = "button" value = "Add Items" /></a> <a href = register.php><input type = "button" value = "Add Users" /></a><br /><br /><a href = logout.php><input type = "button" value = "Logout" /></a>
</center>
</body>
</html>
I need for the ID to be passed along to the next page to be used as a reference so that the pictures uploaded will refer to the selected item. The code for the page that it is passed to:
when I get this figured out there will be more places for the user to upload photos so that they can give more then one at a time. Thank you in advance for any help.
I have tried using select buttons but I am missing on passing only the one items id through to the next page and I wind up passing all of the ids along and get errors.
Where is you name? Plus you didn't close your </form>
I need for the ID to be passed along to the next page to be used as a reference so that the pictures uploaded will refer to the selected item. The code for the page that it is passed to
You are missing a query to fetch that id to appear on to that page.
@LastMitch I owe you an appology bud, I had uploaded a previous version of my script, I thought the form was closed and all the mistakes you had pointed to were fixed, I have a newer script which is the one I thought was uploaded that I have it all set up the way you are suggesting. I am very sorry for my comments.
@everyone I made all the necesasary changes to the scripts and I now have it passing a value but it will only pass through the last id that was retrieved from the table no mater which one I "select" any ideas?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Vehicle Select</title>
</head>
<body onUnload="window.addEventListener("unload", invalidateBackCache, true)">
<center>
<?php
$result = mysql_query("SELECT * FROM inventory")
or die(mysql_error());
echo "<table border = '1'>";
echo "<tr><th>ID</th><th>Year</th><th>Make</th><th>Model</th><th>Milage</th><th>Description</th></tr>";
//keeps getting the next row untill no more exist
while($row = mysql_fetch_array($result))
{
//print out the contents of each row
echo "<tr><td>";
echo $row['id'];
$refId = $row['id'];
echo "</td><td>";
echo $row['year'];
echo "</td><td>";
echo $row['make'];
echo "</td><td>";
echo $row['model'];
echo "</td><td>";
echo $row['mileage'];
echo "</td><td>";
echo $row['description'];
echo "</td><td>";
?>
<form action="picUploads.php" method="post"
name="itemSelect">
<input type="text" name="refID" value=<?php echo $refId; ?> /></td><td><input type="submit" name="submit" value="Select" id="<?php $refId; ?>" /></td></tr>
<?php
}
?></table><br /><br />
<a href = addInventory.php><input type = "button" value = "Add Cars" /></a> <a href = register.php><input type = "button" value = "Add Users" /></a><br /><br /><a href = logout.php><input type = "button" value = "Logout" /></a>
</form>
</center>
</body>
</html>
as far as errors there are no errors it simply displayse the item id of the last one that was loaded so if the last one loaded was if 12 then 12 is displayed in the refID field on the next page regardless of which item I "select"
Line 36, change value=<?php echo $refId; ?> to value="<?php echo $refId; ?>". I don't think that'll solve it but you should have the quotes there. Same for the hrefs on line 40.
Can you provide your code on the next page that includes $_POST['refID'] and how you process it? Make sure you are accessing $_POST['refID'], not $_POST['refId'].
is made a text area for the sole purpose of testing to see if the propper value is passed through, once it is passed correctly it will be made a hidden field to hold the value for further processing
I will definitely look into those, however I am being told to "recreate the whele" as it were, and I get chewed out whenever I look to something like those even for snippets, I am however urged to look at things like those for ideas on how to go about making my own programms
I'm sorry, I'm not seeing any reason why only the last refID would be passed. Maybe someone else has an idea.
On a side note, the <center> tag is deprecated, you shouldn't use it anymore. If you need to center-align something, wrap it in a div, give the div a width, and then set margin: 0 auto;. The auto left & right margins will center the div.
ok so I finally figured this one out, by the grace of God. the code is good but I had to make each itteration of the while loop create a form specifically for each item pulled up so that the forms only had one refID each but I still had all the information I needed to have pulled up.