Jump to content

PHP variables in sql query?


zero_ZX

Recommended Posts

Hi

I have this:

$info = mysql_query("SELECT * FROM kunder WHERE id = $row['anmoder']");

 

Which returns error :/

 

Full code:

<?php include('header.php'); ?>
<?php
session_start();
// dBase file
include "inc/config.php";

if (!$_SESSION["valid_user"])
{
// Ikke logget ind
Header("Location: index.php");
exit;
}

$staff = $_SESSION['valid_user'];

$result = mysql_query("SELECT * FROM admin WHERE brugernavn=('$staff')  LIMIT 1");
$row = mysql_fetch_array($result);

if ($row["guyorder"] != "1")
{
echo '

<div class="response-msg error ui-corner-all">
						<span>Meddelelse</span>
						Adgang til denne side blev nægtet af serveren.
                            <br />
                            Du har muligvis ikke fået tildelt en personale konto. Kontakt din administrator vedrørende dette problem.
					</div>



												<div class="clear"></div>

				<div class="clear"></div>

			<div class="clear"></div>

			<div class="clear"></div>';

			include('sidebar.php');
echo'		</div>
		<div class="clear"></div>
	</div>
</div>';
include('footer.php'); 
echo '</div>
</body>
</html> ';

exit();						


}


if ($_GET["op"] == "active")
{
$id = $_GET['id']; 

mysql_query("UPDATE kunder set aktiv = '1' WHERE id = '$id'");	

echo'<div class="response-msg success ui-corner-all">
						<span>Meddelelse</span>
						Status opdateret!
                            <br />
                          Den valgte kunde er nu blevet aktiv, og kan igen logge ind og benytte systemet.
					  <br />
					  Dette starter med øjeblikkelig virkning.
					</div>';
					}
?>

<?PHP
if ($_GET["op"] == "deactive")
{
$id = $_GET['id']; 

mysql_query("UPDATE kunder set aktiv = '0' WHERE id = '$id'");	

echo'<div class="response-msg error ui-corner-all">
						<span>Meddelelse</span>
						Status opdateret!
                            <br />
                          Den valgte kunde er nu blevet de-aktiveret, og kan ikke længere benytte nogen af funktionerne i systemet.
					  <br />
					  Dette starter med øjeblikkelig virkning.
					</div>';
					}
					?>



	<div id="sub-nav"><div class="page-title">
		<h1>Tables</h1>
	</div>
<?php include('top_buttons.php'); ?></div>
	<div id="page-layout"><div id="page-content">
		<div id="page-content-wrapper">
			<div class="inner-page-title">
				<h2>Bestillinger</h2>
				<span>Liste med bestillinger i din database.<br />
Før musen over den valgte virksomhed for ydeligere information om virksomheden.</span>
			</div>
			<div class="hastable">
                
                
                
                <table id="sort-table"> 
					<thead> 
					<tr>
					    <th>Virksomhed</th> 
					    <th>Titel</th> 
					    <th>Godkendt</th> 
					    <th>Status</th> 
					    <th>Ansvarlig</th>
                            <th>Deadline</th>
						<th style="width:128px">Muligheder</th> 
					</tr> 
					</thead> 
					<tbody> 
					<tr>
                
                
                

<?PHP
$result = mysql_query("SELECT * FROM bestillinger ORDER BY deadline");

while($row = mysql_fetch_array($result))

{


$info = mysql_query("SELECT * FROM kunder WHERE id = $row['anmoder']");
$inforow = mysql_fetch_array( $info );

echo '		

   							<td><a class="btn_no_text btn ui-state-default ui-corner-all tooltip" title="' . $inforow["telefon"] . '" href="user-edit.php?id=' . $row["anmoder"] .'"       
						' . $inforow["virksomhed"] . '</a></td> 
					    <td>' . $row["titel"] . '</td> ';


					    if ($row["godkendt"] == "0")
						{
					echo'	<td><a class="btn_no_text btn ui-state-default ui-corner-all tooltip" title="Denne anmodning er ikke godkendt af en formand"><span class="ui-icon ui-icon-closethick"></span></td>	'; 
						}
						else
						{
					echo'	<td><a class="btn_no_text btn ui-state-default ui-corner-all tooltip" title="Denne anmodning er godkendt af en formand"><span class="ui-icon ui-icon-check"></span></td>';
						}


					    if ($row["status"] == "0")
						{
					echo'	<td><a class="btn_no_text btn ui-state-default ui-corner-all tooltip" title="Denne bestilling er ikke behandlet"><span class="ui-icon ui-icon-comment"></span></td>	'; 
						}
						elseif ($row["status"] == "1")
						{
					echo'	<td><a class="btn_no_text btn ui-state-default ui-corner-all tooltip" title="Denne bestilling er under behandling"><span class="ui-icon ui-icon-transferthick-e-w"></span></td>';
						}
						elseif ($row["status"] == "2")
						{
					echo'	<td><a class="btn_no_text btn ui-state-default ui-corner-all tooltip" title="Denne bestilling er under behandling"><span class="ui-icon ui-icon-cart"></span></td>';
						}



		echo'			<td>' . $row["ansvarlig"] . '</td> 
					    <td>' . $row["deadline"] . '</td>'; 
						if ($row["aktiv"] == "0")
						{
					echo'	<td><a class="btn_no_text btn ui-state-default ui-corner-all tooltip" title="Denne brugers konto er lukket"><span class="ui-icon ui-icon-alert"></span></td>	'; 
						}
						else
						{
					echo'	<td>	Ja </td>';
						}

					   echo' <td>

							<a class="btn_no_text btn ui-state-default ui-corner-all tooltip" title="Rediger kunde information" href="user-edit.php?id=' . $row["id"] . '">
								<span class="ui-icon ui-icon-wrench"></span>
							</a>
							<a class="btn_no_text btn ui-state-default ui-corner-all tooltip" title="Opdater kodeord for denne kunde" href="user-password.php?id=' . $row["id"] . '">
								<span class="ui-icon ui-icon-key"></span>
							</a>
							<a class="btn_no_text btn ui-state-default ui-corner-all tooltip" title="Aktiver denne kunde" href="user-list.php?op=active&id=' . $row["id"] . '">
								<span class="ui-icon ui-icon-unlocked"></span>

							</a>
							<a class="btn_no_text btn ui-state-default ui-corner-all tooltip" title="De-aktiver denne kunde" href="user-list.php?op=deactive&id=' . $row["id"] . '">
								<span class="ui-icon ui-icon-locked"></span>

							</a>
						</td>

					</tr> 


'; }


?>
					</tbody>
				</table> 

			</div>



			<div class="clear"></div>
			<?php include('sidebar.php'); ?>

		</div>
		<div class="clear"></div>
	</div>
</div>
<?php include('footer.php'); ?></div>
</body>
</html>

 

I don't understand how I can put a variable in my query if that doesn't work :/

Link to comment
https://forums.phpfreaks.com/topic/207039-php-variables-in-sql-query/
Share on other sites

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.