Page 1 of 1

$_GET Problem!!!Anyone Help??

Posted: Wed Jan 05, 2005 6:39 pm
by mmc01ms
I've created a record website and in a section the admin user can edit a particuler vinyl they are looking at. Using the $_GET it should get the catno for the item and take you to an edit form where it retrieves the details of that vinyl for editing from the catno. Well i know the form works as i've entered the catno myself into the url. the problem is that i have to enter it in it doesn't get passed from the previous page. i'v looked ages to see where and y it don't get passed but can't see it any one help??

url that i get from link selection is:

Code: Select all

http://localhost/edit_vinyl_form.php?catno=
should get

Code: Select all

http://localhost/edit_vinyl_form.php?catno=100000

full code for edit_form_php page:

Code: Select all

<?php
	session_start();
	
	require_once('display_vinyl_form.php');

	$catno = $_GET['cat_no'];
	
		
	if ($vinyl = get_vinyl_details($catno))
	{
		display_vinyl_form($vinyl);
	}
	else
		echo 'Could not retrieve vinyl details.<br />';
	
	
	
	
	
?>

and the script the catno should get passed from is:

Code: Select all

<?php
	
	require_once('useful_stock_fns.php');

	
	function display_vinyl_details($vinyl)
	{
		
		if(!is_array($vinyl))
		{
			echo 'No Details on this record Currently Available<br />';
			return;
		}
		
		{
?>
<table bgcolor="#7b9815" border="0" bordercolor="FFFFFF">
	<tr>
		<td><font color="#7b9815" size="2" face="Arial, Helvetica, sans-serif">
				
				<tr>
					<td align="center">
						<b>Vinyl Details</b>
					</td>
				</td>
				<tr>
					<tr>
						<td bgcolor="#44802c">
							<b>Artist:</b> 
						</td>
					</tr>
					<tr>
						
						<td >
							<?
		}
		echo $vinyl['artist_id'];
		echo '</td>';
		echo '</tr>';
		
		echo '<tr>';
		{
							?>
							
							<td bgcolor="#44802c">
								<?
		}
		
		echo '<b>Title:</b> ';
		echo '</td>';
		echo '</tr>';
		
		echo '<tr>';
		
		echo '<td>';
		
		echo $vinyl['title'];
		echo '</td>';
		echo '</tr>';
		
		echo '<tr>';
		
		{
								?>
								
								<td bgcolor="#44802c">
									<?
		}
		
		echo '<b>Our Price:</b> ';
		echo '</td>';
		echo '</tr>';
		
		echo '<tr>';
		
		echo '<td>';
		
		echo number_format($vinyl['price'], 2);
		echo '</td>';
		echo '</tr>';
		
		echo '<tr>';
		
		{
									?>
									
									<td bgcolor="#44802c">
										<?
		}
		
		echo '<b>Description:</b> ';
		echo '</td>';
		echo '</tr>';
		
		echo '<tr>';
		
		echo '<td>';
		
		echo $vinyl['vinyl_information'];
		echo '</td></tr></table>'; 
		
		
		
		
		if 	($_SESSION['rank'] == '2'){
										?>
										
										<table><tr><td><a href ="edit_vinyl_form.php?catno=".$vinyl['cat_no'])>Edit</a></td>
												<td>   </td>
												<td><a href = "admin.php">Adminstration Menu</a></td>
												<td>   </td>
												<td><a href = "stock.php?action=newrecord">Add Vinyl</a></td>
												<td>   </td>
												<td><a href = "logout.php">Logout</a></td>
											</tr>
											<?
			
		}
		
		if 	($_SESSION['rank'] == '1'){
			
			echo '<table><tr><td><a href =>Add to Basket</a></td>
								<td>   </td>
								<td><a href = >View Basket</a></td>
								<td>   </td>
								<td><a href = >Continue Shopping</a></td>
								<td>   </td>
								<td><a href = >Save Changes</a></td>
								<td>   </td>
								<td><a href = "logout.php">Logout</a></td>


								</tr>';
				
				
			}
		echo '<table>';
	}
		
		session_start();
		require('page.inc');
		
		require_once('shopping_cart_fns.php');
		
		
		$vinylform = new Page();
		
		$vinylform -> Display();
		
		display_main_menu();
		
		$catno = $_GET['cat_no'];
		
		$vinyl = get_vinyl_details($catno);
		
		display_vinyl_details($vinyl);
		
		do_html_footer();
											?>

Re: $_GET Problem!!!Anyone Help??

Posted: Wed Jan 05, 2005 6:46 pm
by timvw
mmc01ms wrote:

Code: Select all

<?php
if 	($_SESSION['rank'] == '2'){
  ?>
<table><tr><td><a href ="edit_vinyl_form.php?catno=".$vinyl['cat_no'])>Edit</a></td>
the problem is that you are out of php mode here...

so change it to

Code: Select all

<a href="edit_vinyl_form.php?catno=<?php echo $vinyl['cat_no']; ?>">Edit</a>

Posted: Thu Jan 06, 2005 7:26 am
by mmc01ms
thanks for the repley however i did correct that error and no luck it still doesn't pass the value of cat_no through. Looking at the source it has found the cat_no for that vinyl.

Code: Select all

&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;a href ="edit_vinyl_form.php?cat_no="100003"&gt;Edit&lt;/a&gt;&lt;/td&gt;
												&lt;td&gt;   &lt;/td&gt;
												&lt;td&gt;&lt;a href = "admin.php"&gt;Adminstration Menu&lt;/a&gt;&lt;/td&gt;
												&lt;td&gt;   &lt;/td&gt;
												&lt;td&gt;&lt;a href = "stock.php?action=newrecord"&gt;Add Vinyl&lt;/a&gt;&lt;/td&gt;
												&lt;td&gt;   &lt;/td&gt;
												&lt;td&gt;&lt;a href = "logout.php"&gt;Logout&lt;/a&gt;&lt;/td&gt;
											&lt;/tr&gt;
											&lt;table&gt;  	&lt;/body&gt;
however selecting the edit link the value of cat_no still doesn't get passed through. I've included the edited scripts.

Code: Select all

<?php 
	
	//display_vinyl_form.php

	require_once('shopping_cart_fns.php');
	
	
	
	
	function display_vinyl_form($vinyl = '')
	{
	
	$edit = is_array($vinyl);
?>
	<form align="center" name="newrecord" method="post" action="<?php echo $edit?'edit_vinyl.php' : 'insert_vinyl.php';?>">
		<table bordercolor="#FFFFFF" border="1" bgcolor="#FFFFFF">
			<font color="#000000" size="2" face="Courier New, Courier, mono">
				<tr>
					<td><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Title: </font></td>
					<td><input name="title" type="text" maxlength="40" value="<?php echo $edit?$vinyl['title']:' '; ?>"></td>
				</tr>
				<tr>
					<td><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Artist: </font></td>
					<td><select name="artist_id">
							<?php
								$artist_array=get_artists();
								foreach ($artist_array as $thisartist)
								{
									echo '<option value="';
									echo $thisartist['artist_id'];
									echo '"';
									if ($edit && $thisartist['artist_id'] == $vinyl['artist_id'])
										echo 'selected';
									echo '>';
									echo $thisartist['artist_id'];
									echo'</option>';
									echo"\n";
								}
							?>
						</select>
					</td>
				</tr>
				<tr>
					<td><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Release Date: </font></td>
					<td><select name="date"><?php 
						$nums = range(1, 31);
						foreach ($nums as $num) 
						{
							echo '<option value="';
							echo $num;
							echo '"';
							if ($edit && $num['date'] == $vinyl['date'])
								echo 'selected';
							echo '>';
							echo $num;
							echo '</option>';
							echo "\n";
						} ?>
						</select>
						<select name="month"><?php 
						$nums = range(1, 12);
						foreach ($nums as $num) 
						{
							echo '<option value="';
							echo $num;
							echo '"';
							if ($edit && $num['month'] == $vinyl['month'])
								echo 'selected';
							echo '>';
							echo $num;
							echo '</option>';
							echo "\n";
						} ?>
						</select>
						<select name="year"><?php 
						$nums = range(1998, 2005);
						foreach ($nums as $num) 
						{
							echo '<option value="';
							echo $num;
							echo '"';
							if ($edit && $num['year'] == $vinyl['year'])
								echo 'selected';
							echo '>';
							echo $num;
							echo '</option>';
							echo "\n";
						} ?>
						</select></td>
				</tr>
				<tr>
					<td><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Genre: </font></td>
					<td><select name="genre_ref">
							<?php
						$genre_array=get_genres();
						foreach ($genre_array as $thisgenre)
						{
							echo '<option value="';
							echo $thisgenre['genre_ref'];
							echo '"';
							if ($edit && $thisgenre['genre_ref'] == $vinyl['genre_ref'])
								echo 'selected';
							echo '>';
							echo $thisgenre['genre_ref'];
							echo'</option>';
							echo"\n";
						}
							?>
						</select>
					</td>
				</tr>
				<tr>
					<td><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Price: </font></td>
					<td><input name="price" type="text" maxlength="5" id="price" value="<?php echo $edit?$vinyl['price']: ' '; ?>"></td>
				</tr>
				<tr>
					<td><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Qty: </font></td>
					<td><input name="qty" type="text" maxlength="3" id="qty" value="<?php echo $edit?$vinyl['stock_level']: ' '; ?>"></td>
				</tr>
				<tr>
					<td><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Vinyl Information</font></td><td><textarea name="comments" maxlength="225" cols="60" rows="10" value="<?php echo $edit?$vinyl['vinyl_description']: ' '; ?>"></textarea></td>
				</tr>
				<tr>
					<td <?php if(!$edit) echo 'colspan="2"'; ?> align="center">
						<?php
						if ($edit)
							echo '<input type="hidden" name="oldcatno" value="'.$vinyl['cat_no'].'">';
						?>
						<input type="submit" value="<?php echo $edit?'Update' : 'Add';?>Vinyl"></td><td><input type="reset" value="Reset"></td>
				</tr>
				<table></form>	
				
				<div align="left"></div></td>
		</tr>
	</table></td>
<?php
						if($edit)
						{
							echo '<td>';
							echo'<form method="post" action="delete_vinyl.php">';
							echo'<input type="hidden" name="catno" value="'.$vinyl['cat_no'].'">';
							echo '<input type="submit" value="delete vinyl">';
							echo '</form></td>';
						}
?>
		</tr>
	</table>
<?
					}
						
					do_html_footer();
						?>
and the edit_vinyl_form is:

Code: Select all

<?php
	session_start();
	
	require_once('display_vinyl_form.php');

	$catno = $_GET['cat_no'];
	
		
	if ($vinyl = get_vinyl_details($catno))
	{
		display_vinyl_form($vinyl);
	}
	else
		echo 'Could not retrieve vinyl details.<br />';
	
	
	
	
	
?>

and the show_vinyls form where the value of cat_no should get passed from.

Code: Select all

<?php
	
	require_once('useful_stock_fns.php');

	
	function display_vinyl_details($vinyl)
	{
		
		$catno = $_GET['cat_no'];
		
		if(!is_array($vinyl))
		{
			echo 'No Details on this record Currently Available<br />';
			return;
		}
		
		{
?>
<table bgcolor="#7b9815" border="0" bordercolor="FFFFFF">
	<tr>
		<td><font color="#7b9815" size="2" face="Arial, Helvetica, sans-serif">
				
				<tr>
					<td align="center">
						<b>Vinyl Details</b>
					</td>
				</td>
				<tr>
					<tr>
						<td bgcolor="#44802c">
							<b>Artist:</b> 
						</td>
					</tr>
					<tr>
						
						<td >
							<?
		}
		echo $vinyl['artist_id'];
		echo '</td>';
		echo '</tr>';
		
		echo '<tr>';
		{
							?>
							
							<td bgcolor="#44802c">
								<?
		}
		
		echo '<b>Title:</b> ';
		echo '</td>';
		echo '</tr>';
		
		echo '<tr>';
		
		echo '<td>';
		
		echo $vinyl['title'];
		echo '</td>';
		echo '</tr>';
		
		echo '<tr>';
		
		{
								?>
								
								<td bgcolor="#44802c">
									<?
		}
		
		echo '<b>Our Price:</b> ';
		echo '</td>';
		echo '</tr>';
		
		echo '<tr>';
		
		echo '<td>';
		
		echo number_format($vinyl['price'], 2);
		echo '</td>';
		echo '</tr>';
		
		echo '<tr>';
		
		{
									?>
									
									<td bgcolor="#44802c">
										<?
		}
		
		echo '<b>Description:</b> ';
		echo '</td>';
		echo '</tr>';
		
		echo '<tr>';
		
		echo '<td>';
		
		echo $vinyl['vinyl_information'];
		echo '</td></tr></table>'; 
		
		
		
		
		if 	($_SESSION['rank'] == '2'){
										?>
										
										<table><tr><td><a href ="edit_vinyl_form.php?cat_no="<?php echo $catno; ?>">Edit</a></td>
												<td>   </td>
												<td><a href = "admin.php">Adminstration Menu</a></td>
												<td>   </td>
												<td><a href = "stock.php?action=newrecord">Add Vinyl</a></td>
												<td>   </td>
												<td><a href = "logout.php">Logout</a></td>
											</tr>
											<?
			
		}
		
		if 	($_SESSION['rank'] == '1'){
			
			echo '<table><tr><td><a href =>Add to Basket</a></td>
								<td>   </td>
								<td><a href = >View Basket</a></td>
								<td>   </td>
								<td><a href = >Continue Shopping</a></td>
								<td>   </td>
								<td><a href = >Save Changes</a></td>
								<td>   </td>
								<td><a href = "logout.php">Logout</a></td>


								</tr>';
				
				
			}
		echo '<table>';
	}
		
		session_start();
		require('page.inc');
		
		require_once('shopping_cart_fns.php');
		
		
		$vinylform = new Page();
		
		$vinylform -> Display();
		
		display_main_menu();
		
		$catno = $_GET['cat_no'];
		
		$vinyl = get_vinyl_details($catno);
		
		display_vinyl_details($vinyl);
		
		do_html_footer();
											?>

Posted: Thu Jan 06, 2005 8:41 am
by feyd
remove the quote that preceeds the cat_no