Jump to content

[SOLVED] echo works but value=variable


mbrown

Recommended Posts

$softwareQuery = "SELECT * FROM `software` WHERE `SKU` = '$SKU'";
$softwareResult = mysql_fetch_assoc(mysql_query($softwareQuery));
[/coe]



When I echo out $softwareResult[OtherInfo] it display but when i put it in something like this: 

[code]
<textarea name='otherinfo' id='otherinfo' cols='45' rows='5' value='$softwareResult[OtherInfo]'></textarea>

 

it does not display it in the form.

 

any ideas why?

 

like I said when i do the following it works

 

echo $softwareResult[OtherInfo]

Link to comment
https://forums.phpfreaks.com/topic/143770-solved-echo-works-but-valuevariable/
Share on other sites

$softwareResult[OtherInfo] will give you PHP warning error in your logs for "Invalid array index" or something simliar.

You MUST use quotes for associative array indices.

i.e.

$softwareResult['OtherInfo']

 

You also haven't shown the full code for the following line:

<textarea name='otherinfo' id='otherinfo' cols='45' rows='5' value='$softwareResult[OtherInfo]'></textarea>

 

We don't know how the above is being output? By echo? By print?

 

timmah1's solution is the correct one. So either post the full code or implement his solution.

<?php
session_start();
if ($_SESSION['loggedIn'] == TRUE)
{
	$username = $_SESSION['username'];
	echo "User Logged In: $username";
	echo "<br /><a href='../administration/index1.php'>Main Admin</a>";
	echo "<br />";
	echo "<div align='center'><img src='../images/wasdBanner.gif' alt='header' /></div>";

	//including the database connection script
	include("../includes/connect.php");


	echo "<!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>Modify Software</title>
	</head>

	<body>";

	$userquery = "SELECT * FROM users WHERE username = '$username'";
	$query = mysql_fetch_assoc(mysql_query($userquery));
	if($query[usergroup] != "Super Administrator")
	{
		echo "<br />You need to have administration privleges";
		//meta refresh
	}//end of if($query[usergroup] == "Super Administrator")

	else
	{
		$SKU = $_POST['sku#'];

		$softwareQuery = "SELECT * FROM `software` WHERE `SKU` = '$SKU'";
		$softwareResultNumRows = mysql_query($softwareQuery) or die (mysql_error());
		$softwareResult = mysql_fetch_assoc(mysql_query($softwareQuery));
		$softwareNumRows = mysql_num_rows($softwareResultNumRows);

		//Debuggin: echo "$SKU";

		if ($softwareNumRows == 0)
		{
			if ($SKU == "")
			{
				echo "Please enter a SKU Number";
			}//end of if ($SKU == "")
		}//end of if ($numrows == 0)

		else
		{

			echo "<style type='text/css'>
					<!--
					.style1 {
						color: #0000FF;
						font-weight: bold;
					}
					.style2 {color: #0000FF}
					.style3 {font-size: 12px}
					-->
					</style>
					 ";

			echo "<form id='software' name='software' method='post' action='softwareModifyCheck.php'>
			  <div align='center' >
				<p class='style1'>Software<br />
				<hr width='50%' />
				<p align='left'>
				<label>ID:
				  <input type='text' name='ID' id='ID' value='$softwareResult[iD]' readonly='readonly' length='4'/>
				  </label>
				  </p>
				<p align='left'>
				  <label>Software Title:
				  <input type='text' name='softwareTitle' id='softwareTitle' value='$softwareResult[softwareTitle]'/>
				  </label>
				</p>
				<p align='left'>
				  <label>SKU #:
				  <input type='text' name='sku#' id='sku#' value='$softwareResult[sKU]'/>
				  </label>
				</p>
				<p align='left'>Building: 
				  <select name='building' id='building'>
					<option value='$softwareResult[Location]'>$softwareResult[Location]</option>
					<option value='Summitview'>Summitview</option>
					<option value='WAMS'>WAMS</option>
					<option value='WASHS'>WASHS</option>
					<option value='Hooverville'>Hooverville</option>
					<option value='Mowery'>Mowery</option>
					<option value='Fairview Ave'>Fairview Ave</option>
					<option value='Clayton Ave'>Clayton Ave</option>
				  </select>
				</p>
				 <p align='left'>Room: 
				  <label>
				  <input name='room' type='text' id='room' size='3' maxlength='3' value='$softwareResult[Room]'>
				  </label>
				</p>
				<p align='left'>Grant: 
				  <label>
				  <input type='text' name='grant' id='grant' value='$softwareResult[Grant]'/>
				  </label>
				</p>
				<p align='left'>Other Information: 
				  <label><br />
				  <textarea name='otherinfo' id='otherinfo' cols='45' rows='5'>$softwareResult[OtherInfo]</textarea>
				  </label>
				</p>
				<p align='left'> </p>
				<div align='center'>
				  <input type='submit' name='submit2' id='submit2' value='Submit' />
		    
		  <input type='reset' name='button' id='button2' value='Reset' />
				</div>
				</div>
			</form>";
		}//end of else
	}//end of else
}//end of if ($_SESSION['loggedIn'] == TRUE)

else
{
	header('Location: ../login.php');
}
echo"	</body>
	</html>";




?>

 

I implemented timmah1's solution

 

<textarea name='otherinfo' id='otherinfo' cols='45' rows='5'>$softwareResult[OtherInfo]</textarea>

Archived

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

×
×
  • 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.