Jump to content

Recommended Posts

Hi guys,

 

It's been a while since I coded in PHP (some 10 years or so). Now I need a web application and thought, I resource to my old talents but I think, I failed miserably :-)

 

Here's the problem:

I want the user to enter an item number and click a button to select the record from the products table.

Once the - I call it "Getit" - button is clicked, the second form containing the record data should be rendered.

 

So far, so good. However, although all variables show their correct values to render the second form, it just refuses to render. Right now, I have mental block and need some help, please.

 

If you want to look at the app, here is the url : http://farbeyondrails.net/catalog/maintenance/edit_article.php

 

Here is the code in question:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Maintenance</title>
<link href="../layout.css" rel="stylesheet" type="text/css" media="all">
<link href="../styles.css" rel="stylesheet" type="text/css" media="all">
</head>

<body>
<?php
	require('../php/helper.php');
	db_connect(); // Datenbank-Verbindung
	get_config();
	$sql = '';
	$arr_radio = array();
	$arr_select = array();
	$sql = "SELECT * FROM gauges";
	$result = mysql_query($sql);
	if($result){
		while ( $row = mysql_fetch_assoc ( $result ) )
		{
			$i = $row['id'];
			$wert = $row['gauge'];
			$arr_radio[$i] =  $wert;
		}
		$gauge_anz = count($arr_radio);
	}
	$sql = "SELECT * FROM categories";
	$result = mysql_query($sql);
	if($result){
		while($row = mysql_fetch_assoc($result))	
		{
			$i	= $row['id'];
			$wert = $row['range'];
			$arr_select[$i] = $wert;
		}
		$sel_anz = count($arr_select);
		//echo $sel_anz.' Elemente in $sel_anz';
	}
	
	echo '
	<div id="wrapper">
    	<div id="header"
        	<div id="fbr-logo">
            	<a href="http://farbeyondrails.net/" title="Back to home page"><img src="../'.$logo.'" /></a>
            </div> <!-- End fbr-logo -->
            <div id="header-grafik">
            	<img src="../'.$header_grafik.'" alt="FBR-Grafik" />
            </div> 
            <div id="fl-grafik">
            	<img src="../../tl_files/fbr/images/site/FL_logo.jpg" alt="FL-Logo"/>
                <img src="../../tl_files/fbr/images/site/roco_logo.jpg" alt="Roco-Logo"/>
            </div> 
        </div>
        <div id="inhalt">
	        <div id="left" class="nav">
				<h2>Navigation</h2>
    	    	<ul>
					<li><a href="../index.php" title="Back to catalog">Front-End</a></li>
					<li><strong>--- System ---</strong></li>
					<li><a href="../admin/edit_config.php" title="Edit configuration">Configuration</a></li>
					<li><strong>--- Catalog ---</strong></li>
					<li><a href="cat_recalc.php" title="Re-calculate catalog with new values">Re-Calculate</a></li>
					<li><a href="new_prod.php" title="Add new products">Add new products</a></li>
					<li>Edit Catalog Item</li>
					<li><strong>--- Customers ---</strong></li>
					<li><strong>--- Orders ---</strong></li>
					<li><strong>--- Payments ---</strong></li>
					<li><strong>--- Shipments ---</strong></li>
					
				</ul>
	        </div>
    	    <div id="main">';
				echo '
        		<div class="center-title"><h1>Fleischmann / Roco Catalog - Maintenance</h1></div>
				<div class="center-title"><h2>Edit a specific catalog item</h2></div>';
								
				// SQL - string
				// Test sql string
				echo 'SQL before main form: '.$sql.'<br/>';
				echo ' Value isset($_POST["update"]) : '.isset($_POST['update']).'<br/>';
				echo ' Value isset($_POST["submit"]) : '.isset($_POST['submit']).'<br/>';
				if(!isset($_POST['update']) && isset($_POST['submit']))
				{
					$sql = "SELECT * FROM products WHERE item_no='".$item_no."'";
					$result = mysql_query($sql);
					if(result)
					{
						// Test
						echo '<br/>$result = '.$result.'<br/>';
						$row = mysql_fetch_assoc($result);
						// Form for data record here
						if($item_no != 0 && $_POST['gesendet'])
						{
							echo '
							<form method="POST" action="'.$PHP_SELF.'">
								<table>
									<tr>
										<td>Item No.:</td><td><input type="text" name="item_no" size="6" value="'.$item_no.'" readonly="readonly" />     Brand : <input type="text" title="Enter the abbreviation for the brand" name="brand" size="2" maxlength="2" value="'.$row['brand'].'" />     Brand : <input type="text" title="Enter the abbreviation for availability:<br/>
										√ (ALT+2+5+1),N,L,D" name="avail" size="1" maxlength="1" value="'.$row['avail'].'"</td>
									</tr>
									<tr>
										<td>Gauge:</td><td>';
											for($i=1;$i < $gauge_anz+1;$i++)
												{
													if($arr_radio[$i]==$row['scale'])
													{
														echo'<input type="radio" name="gauge" value = "'.$arr_radio[$i].'" checked="checked" />'.$arr_radio[$i].'  ';
													}else{
														echo'<input type="radio" name="gauge" value = "'.$arr_radio[$i].'"/>'.$arr_radio[$i].'  ';
													}
												}
											echo '</td>
									</tr>
									<tr>
										<td><input type="hidden" name="gesendet" value="1" /><input type="submit" name="update" value="Update"  /></td>
									</tr>
								</table>
							</form>
							';
						}else{
					
						}
					}else{
						echo 'An error occured: '.mysql_error();
					}
				}
				// Test 
				echo '<br/>SQL string after click on Get IT:'.$sql.'<br/>';
				echo 'Var_Dump $_POST: ';var_dump($_POST);
				if(!isset($POST['submit']))
				{
					echo '
					<form method="POST">
						<p>Item No. : <input type="text" title="Enter the item number to be edited (max. 6 digits)" name="item_no" size="6" maxlength="6" value="0" /> <input type="submit" name="submit" onclick="$item_no=this.form.item_no.value" value="Get it!" /p>
						
					</form>';
				}
				if(isset($_POST['item_no']))
				{
					$item_no = $_POST['item-no'];
					$sql = "SELECT * FROM products WHERE item_no='".$item_no."'";
					echo '<br/>'.$item_no;
				}
				
				
				// Footer
				echo '<div id="footer">
                	<div class="footer-text">©2014 Erhard Baltrusch, Far Beyond Rails,LLC, Florida, USA<br />
                    Pictures © Modelleisenbahn München Gmbh, München, Germany <br />
                    All Rights reserved
                    </div>
                </div>
	        </div> 
    	    <div id="right" class="news-text">
        		<p>
					 
				</p>
			</div> 
		</div> 
    </div>'
?>
</body>
</html>

I'm pretty sure, I' missing just a tiny thing - just what I don't see ...

Can someone please help me out?

Thanks in advance

Erhard

Right here:

if(isset($_POST['item_no']))
{
	$item_no = $_POST['item-no'];
	$sql = "SELECT * FROM products WHERE item_no='".$item_no."'";
	echo '<br/>'.$item_no;
}

It displays with a value once the "Get It!" - button is clicked.

Some examples for Item nos: 35004,35007,35010 - incase you want to try it out.

I'll start with a suggestion. Do not intermingle the HTML and the PHP logic. Put all your PHP code at the top of the page (or in a separate file). Use the logic to create the output into variables, then just output the variables within the HTML. Makes it much easier to debug the code and makes it more flexible.

 

Also, I'm seeing several errors:

 

if(result)
There is no dollar sign for the variable.

 

<div id="header"
No closing carat

 

</div>'
No ending semi-colon Edited by Psycho

Right here:

if(isset($_POST['item_no']))
{
	$item_no = $_POST['item-no'];
	$sql = "SELECT * FROM products WHERE item_no='".$item_no."'";
	echo '<br/>'.$item_no;
}

It displays with a value once the "Get It!" - button is clicked.

Some examples for Item nos: 35004,35007,35010 - incase you want to try it out.

 

You refer to $item_no before that

				if(!isset($_POST['update']) && isset($_POST['submit']))
				{
					$sql = "SELECT * FROM products WHERE item_no='".$item_no."'";            // line 82
					$result = mysql_query($sql);
					if(result)
					{

I'll also offer the following observation. The 'output' for the form is nested in quite a few if() conditions. If any of those conditions are false, the form will not be generated. But, there are no else conditions to let you know if something failed. In this case, this condition is failing

if($item_no != 0 && $_POST['gesendet'])
because $item_no had not yet been defined. Edited by Psycho

Thanks so far, guys!

 

Guess, I was pretty blind after wrestling with it for about 5 hours :-). Also, Dreamweaver didn't show me any syntax errors and I simply relied on that - my bad.

I' ll re-work it with your suggestions and see what I'll get.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.