Sql update doesn't work unless choosing a file - php

in this edit file i have to choose the same picture file or another picture file to be able update the rows. but i want to be able to change whichever i want without touching the other rows. any ideas over here?
<?php
include('../config.php');
include ('../ac.thumbs.php');
if ($_GET['sil']) {
$sil = htmlspecialchars(stripslashes($_GET['sil']));
mysql_query("DELETE FROM CloseOut WHERE itemNO = $sil limit 1");
echo "<h1>$sil item nolu kayit silinmistir</h1><br>";
}
$edit = htmlspecialchars(stripslashes($_GET['edit']));
$data = mysql_query("SELECT * FROM CloseOut WHERE itemNO=$edit") or die(mysql_error());
//Puts it into an array
while($info = mysql_fetch_array( $data ))
{ echo "
<center>
[ Delete ]<br>
<a href=../../large.php?f=upload/".$info['resim'], $thumblarge .">
<img src=../../small.php?f=upload/".$info['resim'], $thumbsmall .">
</a>";
$editresim = $info[resim];
$editisim = $info[isim];
$editalan1 = $info[alan1];
$editalan2 = $info[alan2];
$editalan3 = $info[alan3];
$editalan4 = $info[alan4];
}
//Resimlerin yuklenecegin yer
$target = "../../upload/";
//////////////////////////////////////////////////////////////////////
///////////////////////////////Resim1/////////////////////////////////
//////////////////////////////////////////////////////////////////////
$target1 = $target . basename( $_FILES['resim1']['name']) ;
//Formdan gelen bilgileri almasi icin
$resim=($_FILES['resim1']['name']);
$isim=$_POST['isim1'];
$alan1=$_POST['alan11'];
$alan2=$_POST['alan21'];
$alan3=$_POST['alan31'];
$alan4=$_POST['alan41'];
/////////////Formdaki bos alanlara bos bilgi kayit etmemesi icin////////////////////////
$updates = array();
if (!empty($resim))
$updates[] = 'resim="'.mysql_real_escape_string($resim).'"';
if (!empty($isim))
$updates[] = 'isim="'.mysql_real_escape_string($isim).'"';
if (!empty($alan1))
$updates[] = 'alan1="'.mysql_real_escape_string($alan1).'"';
if (!empty($alan2))
$updates[] = 'alan2="'.mysql_real_escape_string($alan2).'"';
if (!empty($alan3))
$updates[] = 'alan3="'.mysql_real_escape_string($alan3).'"';
if (!empty($alan4))
$updates[] = 'alan4="'.mysql_real_escape_string($alan4).'"';
$updates = implode(', ', $updates);
/////////////////////////////////////////////////////////////////////////////////////////
//update etmesi icin
if(move_uploaded_file($_FILES['resim1']['tmp_name'], $target1))
{
mysql_query("UPDATE CloseOut SET $updates WHERE itemNO='$edit' ");
echo "Tebrikler, ". basename( $_FILES['resim1']['name']). " isimli dosya yuklendi ve database'e basariyla islendi!<br>";
}
?>
<br>
<center>
<table width="900" border="5" style="background-color:white; "bordercolor="#000000">
<tr>
<td width="120" height="50" bgcolor= "545454"><b>RESIM</b></td>
<td width="120" height="50" bgcolor= "545454"><b>NAME</b></td>
<td width="120" height="50" bgcolor= "545454"><b>CATAGORY</b></td>
<td width="120" height="50" bgcolor= "545454"><b>QUANTITY</b></td>
<td width="120" height="50" bgcolor= "545454"><b>LOCATION</b></td>
<td width="120" height="50" bgcolor= "545454"><b>PRICE</b></td>
</tr>
<tr>
<form enctype="multipart/form-data" method="post" action="">
<td><input type="file" name="resim1" value="<?php echo $editresim;?>"> </td>
<td><input type="text" name="isim1" value="<?php echo $editisim;?>"> </td>
<td><input type="text" name="alan11" value="<?php echo $editalan1;?>"> </td>
<td><input type="text" name="alan21" value="<?php echo $editalan2;?>"> </td>
<td><input type="text" name="alan31" value="<?php echo $editalan3;?>"></td>
<td><input type="text" name="alan41" value="<?php echo $editalan4;?>"></td>
</tr>
<td colspan="5"><center><input type="submit"></center></td>
</form>
</table>
</center>

Related

I'm not getting values from session variable set for results

I have created the following pages.
1. questions.php
2. functions.php
3. result.php
i have set the values of session variables on page function.php when the question form on questions.php form is submitted the functions.php code runs and the i have echo the values of session variables on result.php page. but i'm unable to get the session values result.the sessions values are resulting empty .anyone help please.
functions.php
if(isset($_POST['question_form']))
{
global $conn;
if (!isset($_SESSION['result'])) {
$result = 0;
$_SESSION['result'] = 0;
}
if (!isset($_SESSION['attempted'])) {
$attempted = 0;
$_SESSION['attempted'] = 0;
}
$resArray = array();
$resArray['message'] = '';
$resArray['status'] = '';
$no = $_POST['no'];
$postedAnswer = $_POST['answer_'.$no];
$question_id = $_POST['question_id'];
$subject_id = $_POST['subject_id'];
$sql = "SELECT True_answer FROM question WHERE QuestionId = '$question_id' AND SubjectId = '$subject_id'";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
$True_answer = $row['True_answer'];
if($postedAnswer === $True_answer)
{
$result = $_SESSION['result'];
$result++;
$_SESSION['result'] = $result;
}
$attempted = $_SESSION['attempted'];
$attempted++;
$_SESSION['attempted'] = $attempted;
$resArray['status'] = true;
//$resArray['q_id'] = $no;
$resArray['message'] = 'Submitted Successfully';
echo json_encode($resArray);
exit();
}
=====questions.php========
<form action="includes/functions.php" id="question_form_<?php echo $j; ?>" >
<div class='container' >
<div class='row'>
<div class='col-lg-12'>
<div class='thumbnail'>
<p id="question_description">Q.<?php echo $i; ?><br><?php echo $row['QuestionDescription']; ?></p>
<div class="questions_options">
<label><input type="radio" id="btn_radio" name="answer_<?php echo $j; ?>" value="<?php echo $row['Option1']; ?>"><?php echo $row['Option1']; ?></input></label><br>
<label><input type="radio" id="btn_radio" name="answer_<?php echo $j; ?>" value="<?php echo $row['Option2']; ?>"><?php echo $row['Option2']; ?></input></label><br>
<label><input type="radio" id="btn_radio" name="answer_<?php echo $j; ?>" value="<?php echo $row['Option3']; ?>"><?php echo $row['Option3']; ?></input></label><br>
<label><input type="radio" id="btn_radio" name="answer_<?php echo $j; ?>" value="<?php echo $row['Option4']; ?>"><?php echo $row['Option4']; ?></input></label><br><br>
<input type="hidden" name="question_id" value="<?php echo $row['QuestionId'] ?>">
<input type="hidden" name="subject_id" value="<?php echo $row['SubjectId'] ?>">
<input type="hidden" name="question_form" value="question_form">
<input type="hidden" name="no" value="<?php echo $j; ?>">
<button class="btn btn-primary btn-sm" id="btn_submit">Submit<i class="glyphicon glyphicon-arrow-right" >
</i></button>
</div>
</div>
</div>
</div>
</div>
</form>
============result.php===============
<table class="table table-striped table-hover" id="result_table" >
<thead>
<tr>
<th style="text-align: center;">Total Questions</th>
<th style="text-align: center;">Attempted Questions</th>
<th style="text-align: center;">Total Marks</th>
<th style="text-align: center;">Obtained Marks</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: center;"><?php echo $number_of_questions;?></td>
<td style="text-align: center;"><?php echo $_SESSION['attempted']; ?></td>
<td style="text-align: center;"><?php if(!isset($_SESSION['result']))
{
echo "empty";
}
else
{
echo $_SESSION['result'];
}
?></td>
<td style="text-align: center;"><?php echo $marks_obtained;?></td>
</tr>
</tbody>
</table>
Please start the session using session_start() function

Display and retrieve image from database in PHP

I want to display image from database but currently it displays only name of image. need help. here is my code
submit.php
<?php
$radio = $_POST['RadioGroup1'];
$img_banner = $_FILES['bannerImage']['name'];
$target_file = "uploads/";
if(!empty($img_banner))
{
$errors = array();
$file_name = $_FILES['bannerImage']['name'];
$file_size = $_FILES['bannerImage']['size'];
$file_tmp = $_FILES['bannerImage']['tmp_name'];
$file_type = $_FILES['bannerImage']['type'];
$file_ext = strtolower(end(explode('.',$_FILES['bannerImage']['name'])));
$k = move_uploaded_file($file_tmp,"uploads/".$file_name);
}
$date = $_POST['date'];
$qry_banner = "INSERT INTO `banner_tbl`(`banner_img`, `date`) VALUES ('$img_banner','$date')";
$res_banner = mysql_query($qry_banner);
$banner_tbl_id = mysql_insert_id();
$sec_id = $_POST['sectionID'];
$sec_active_image = $_POST['activeimage'];
$sec_title = $_POST['section_title'];
$total_sec = count($sec_id);
for($i=0;$i<$total_sec;$i++)
{
$qry_section1 = "INSERT INTO `section_lt_tbl`(`banner_id`, `sectionID`, `activeimage`, `sectiontitle`) VALUES
('$banner_tbl_id','$sec_id[$i]','$sec_active_image[$i]','$sec_title[$i]')";
$res_section1 = mysql_query($qry_section1);
$sec_tbl_id1 = mysql_insert_id();
$section_generated_id[] = $sec_tbl_id1;
}
$array_section_ids = array();
for($i=1;$i<=$radio;$i++)
{
$j = $i-1 ;
$array_section_ids[$i] = $section_generated_id[$j];
}
for($h=1;$h<=count($array_section_ids);$h++)
{
$news_ids_sec[$h] = $_POST['sec_'.$h.'_new'];
$news_title_sec[$h] = $_POST['sec_'.$h.'_title_news'];
$sec_1_desc[$h] = $_POST['sec_'.$h.'_desc'];
$sec_1_newslink[$h] = $_POST['sec_'.$h.'_newslink'];
$sec_1_news_url[$h] = $_POST['sec_'.$h.'_news_url'];
$sec_1_news_img[$h] = $_FILES['sec_'.$h.'_news_img']['name'];
$temp_file[$h] = $_FILES['sec_'.$h.'_news_img']['tmp_name'];
$section = $array_section_ids[$h];
for($c=0;$c<count($news_ids_sec[$h]);$c++)
{
$id = $news_ids_sec[$h][$c];
// $sec_id = $array_section_ids[$h][$c];
$title= $news_title_sec[$h][$c];
$desc = $sec_1_desc[$h][$c];
$link = $sec_1_newslink[$h][$c];
$url = $sec_1_news_url[$h][$c];
$img = $sec_1_news_img[$h][$c][0];
$tmp_name = $temp_file[$h][$c][0];
$qry_news_insert = "INSERT INTO `news_lt_tbl`(`newsid`, `news_sec_id`, `newstitle`, `Description`, `titleoflink`, `urlofnews`, `news_img`) VALUES ('$id','$section','$title','$desc','$link','$url','$img')";
$res_news = mysql_query($qry_news_insert);
$file_name = $img;
$file_tmp = $tmp_name;
$file_ext = strtolower(end(explode('.',$file_name)));
$k = move_uploaded_file($file_tmp,"uploads/".$file_name);
}
}
?>
<?php
$qry_test = "SELECT * FROM `section_lt_tbl` WHERE sec_id = 162";
$res_tses = mysql_query($qry_test);
$arr = mysql_fetch_assoc($res_tses);
?>
<?php
$query = "SELECT `newsid`, `newstitle`, `Description`, `titleoflink`, `urlofnews`, `news_img` FROM `news_lt_tbl` ";
$result_news = mysql_query($query);
$file_name = $img;
$file_tmp = $tmp_name;
$file_ext = strtolower(end(explode('.',$file_name)));
$k = move_uploaded_file($file_tmp,"uploads/".$file_name);
?>
And
<table align="center" width="600">
<tr>
<tr>
<td bgcolor="#ffffff" valign="bottom" align="left"><img border="0" src="http://www.nrsadvisors.com/email-images/mainlogo.jpg" alt="NRS Advisors"/></td>
</tr>
<tr>
<td style="border-top-width:2px; border-top-style:solid; border-top-color: #3E7DBD;" bgcolor="#dbdbdb"><img border="0" src="http://www.nrsadvisors.com/email-images/banner-hero-image.png" alt="bannerimg" width="550" /><a name="featuredstartup" style="height:0;margin:0;padding:0"></a></td>
</tr>
<td bgcolor="#dbdbdb" align="center"><table border="0" cellpadding="0" cellspacing="0" width="550" align="center">
<tr>
<td width="25%"><a href="#featuredstartup"><img src="uploads/<?php echo $arr['activeimage'] ?>_blue.jpg" width="125px" height="134px" />
</a></td>
<td width="25%"><img src="uploads/<?php echo $arr['activeimage'] ?>_grey.jpg" width="125px" height="134px" /></td>
<td width="25%"><img src="uploads/<?php echo $arr['activeimage'] ?>_grey.jpg" width="125px" height="134px" /></td>
<td width="25%"><img src="uploads/<?php echo $arr['activeimage'] ?>_grey.jpg" width="125px" height="134px" /></td>
</tr>
</table>
</td>
</tr>
<?php
while ($row = mysql_fetch_array($result_news)) {
?>
<table align="center" width="600">
<tr>
<span style="font-size:14px;line-height:17px;font-weight:normal;color:#333333">
<td align="left">
<span style="font-weight:bold">
<?php echo $row['newsid'] ?>
</span>
</td>
</span>
</tr>
<tr>
<td>
<span align='left' style='color:#3E7DBD;font-weight:bold'>
<span style='font-size:14px;line-height:17px;font-weight:normal;color:#333333'><span style='font-weight:bold'>
<?php echo $row['newstitle'] ?>
-</span><br><br>
</td>
</tr>
<tr>
<td><?php echo $row['Description'] ?></td><br><br>
</tr>
<tr>
<td>
<a href="<?php echo $row['urlofnews'] ?>" style='font-size:14px;line-height:17px;color:#3FC47B; text-decoration:none;'><?php echo $row['titleoflink'] ?></a></td><br><br>
</tr>
<tr>
<td><?php echo $row['news_img'] ?></td>
</tr>
</table>
<?php
}
?>
You need to use img tag to display Image. like this:
<img src="your_upload_path/<?php echo $row['news_img'] ?>" />
Specify the upload image path in img src like this
<img src="Upload Path/<?php echo $row['news_img'] ?" />

Code doesn't update

I have an edit form that will search for the ID and edit it in the same page. Then tosses it to another page where it will show that it's successful.
<body bgcolor = "#FFFFFF" text = "#000000">
<form name = "ReadID" method="post">
<table width = "350" border = "0" align="center" cellpadding = "3" >
<tr>
<td colspan = "2" bgcolor = "#EF8D25" height = "23">
<center><b>Search</b></center>
</td>
</tr>
<tr bgcolor = "#eeeeee">
<td width = "40%" bgcolor = "#eeeeee">
<center>Asset ID</center>
</td>
<td width = "60%">
<input id="text" type = "text" name = "ASSET_ID">
</td>
</tr>
<td colspan = "2" bgcolor = "#EF8D25">
<center>
<input type = "submit" name = "Submit" value = "Search" onclick="showElem()">
</center>
</td>
</tr>
</table>
</form>
<form name="displayform" method="post" action="edititem.php">
<table width="350" border="0" align="center" cellpadding="3" id="111">
<tr>
<td colspan="2" bgcolor="#EF8D25">
<div align="center"><b>Edit Form</b></div>
</td>
</tr>
<?php
$host = "localhost";
$uname = "root";
$pass = "";
$tablename = "tb_asset";
$con = mysql_connect($host, $uname, $pass)
or die ("Database connection failed!<br>");
mysql_select_db("db_itinventory",$con);
$ASSET_ID = $_POST['ASSET_ID'];
$sql="select * from tb_asset where ASSET_ID='$ASSET_ID'";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
?>
<tr bgcolor="#eeeeee">
</tr>
<tr bgcolor = "#eeeeee">
<td width = "100" bgcolor = "#eeeeee">
<div align="right" >Barcode</div>
</td>
<td width = "150">
<input id="text" type="text" name = "Barcode" value ="<?php echo $row['Barcode']; ?>"/>
</td>
</tr>
<tr bgcolor = "#eeeeee">
<td width = "100" bgcolor = "#eeeeee">
<div align = "right" >Item Name</div>
</td>
<td width = "150">
<input id="text" type = "text" name="Item_Name" value="<?php echo $row['Item_Name']; ?>" />
</td>
</tr>
<tr bgcolor = "#eeeeee">
<td width = "100" bgcolor = "#eeeeee">
<div align = "right" >Serial</div>
</td>
<td width = "150">
<input id="text" type = "text" name="Serial" value="<?php echo $row['Serial']; ?>" />
</td>
</tr>
<tr bgcolor = "#eeeeee">
<td width = "100" bgcolor = "#eeeeee">
<div align = "right" >Brand</div>
</td>
<td width = "150">
<input id="text" type = "text" name="Brand" value="<?php echo $row['Brand']; ?>" />
</td>
</tr>
<tr bgcolor = "#eeeeee">
<td width = "100" bgcolor = "#eeeeee">
<div align = "right" >Model</div>
</td>
<td width = "150">
<input id="text" type = "text" name="Model" value="<?php echo $row['Model']; ?>" />
</td>
</tr>
<tr bgcolor = "#eeeeee">
<td width = "100" bgcolor = "#eeeeee">
<div align = "right" >Status</div>
</td>
<td width = "150">
<input id="text" type = "text" name="Status" value="<?php echo $row['Status']; ?>" />
</td>
</tr>
<td colspan="2" bgcolor="#EF8D25" >
<div align="center">
<input type="submit" name="Submit" value="Update" />
</div>
</td>
</tr>
</table>
</form>
</body>
</html>
This is the second page.
<?php
$user_name = "root";
$password = "";
$database = "db_itinventory";
$server = "localhost";
mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database);
$ASSET_ID = trim(mysql_real_escape_string($_POST["ASSET_ID"]));
$Barcode = trim(mysql_real_escape_string($_POST["Barcode"]));
$Item_Name = trim(mysql_real_escape_string($_POST["Item_Name"]));
$Serial = trim(mysql_real_escape_string($_POST["Serial"]));
$Brand = trim(mysql_real_escape_string($_POST["Brand"]));
$Model = trim(mysql_real_escape_string($_POST["Model"]));
$Status = trim(mysql_real_escape_string($_POST["Status"]));
$sql = ("Update tb_asset set Barcode = '".$Barcode."' , Item_Name = '".$Item_Name."' , Serial = '".$Serial."' , Brand = '".$Brand."' , Model = '".$Model."' , Status = '".$Status."' where ASSET_ID = '".$ASSET_ID."'");
$result=mysql_query($sql);
if ($result){
echo "<center><table border = \"0\" align = \*center\* cellspacing = \"1\" cellpadding = \"5\" width = \"350\">";
echo "<tr>";
echo "<td colspan = \"2\" bgcolor = \"#EF8D25\">";
echo "<center><b>Record successfully edited!</b></center>";
echo "</td>";
echo "</tr>";
echo "<tr bgcolor = \"#eeeeee\">";
echo "<td width = \"20\">";
echo "<div align = \"right\">Barcode</div>";
echo "</td>";
echo "<td width = \"550\">".$Barcode."</td>";
echo "</tr>";
echo "<tr bgcolor = \"#eeeeee\">";
echo "<td width = \"200\">";
echo "<div align = \"right\">Item_Name</div>";
echo "</td>";
echo "<td width = \"200\">".$Item_Name."</td>";
echo "</tr>";
echo "<tr bgcolor = \"#eeeeee\">";
echo "<td width = \"200\">";
echo "<div align = \"right\">Serial</div>";
echo "</td>";
echo "<td width = \"200\">".$Serial."</td>";
echo "</tr>";
echo "<tr bgcolor = \"#eeeeee\">";
echo "<td width = \"200\">";
echo "<div align = \"right\">Brand</div>";
echo "</td>";
echo "<td width = \"200\">".$Brand."</td>";
echo "</tr>";
//echo "<tr>";
echo "<tr bgcolor = \"#eeeeee\">";
echo "<td width = \"200\">";
echo "<div align = \"right\">Model</div>";
echo "</td>";
echo "<td width = \"200\">".$Model."</td>";
echo "</tr>";
echo "<tr bgcolor = \"#eeeeee\">";
echo "<td width = \"200\">";
echo "<div align = \"right\">Status</div>";
echo "</td>";
echo "<td width = \"200\">".$Status."</td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan = \"2\" bgcolor = \"#EF8D25\"> </td>";
echo "</tr>";
echo "</table>";
}
else {
echo "ERROR!";
}
?>
There's no error showing. But the code is not working. Help?
One of few possible errors..
$sql = ("Update tb_asset set Barcode = '".$Barcode."' , Item_Name = '".$Item_Name."' , Serial = '".$Serial."' , Brand = '".$Brand."' , Model = '".$Model."' , Status = '".$Status."' where ASSET_ID = '".$ASSET_ID."'");
*shouldn't have any parentheses.
Regarding undefined ASSET_ID:
You might want to put the value of ASSET_ID in a hidden form field
<input type="hidden" name = "ASSET_ID" value ="<?php echo $row['ASSET_ID']; ?>"/>

php echoing images based on $answer [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
This is a university project and I have a page will a php calculator where users enter '$valuea' which is likely to be between 0-550 then they will hit submit which subtracts '$valueb' which is 250, giving them '$answer'.
What I need help with is I was to have a particular image echo out once the user hit submit, which depends on the figure of $answer.
Here's what I have so far but it is not working;
<?php
if (isset($_POST['valuea'])) $valuea = $_POST['valuea'];
if (isset($_POST['valueb'])) $valueb = '250';
$answer = $valuea - $valueb;
echo <<<_END
<form method='post' action='calculator.php'>
<table border='0' width='500px' cellpadding='3' cellspacing='1' class="table">
<tr class="calcheading"><td colspan="2"><strong>Work out how much you could be saving</strong></td></tr>
<tr class="calcrow"><td>How much do you spend a year?</td><td align="center"><input type='text' name='valuea' value="$valuea"/></td></tr>
<tr class="calcrow"><td>Minus the average price of an n-power student tarrif* Leave Blank:</td><td align="center"><input type='text' name='valueb' value="$valueb"/></td></tr>
<tr class="submit"><td colspan="2"><input type='submit' value='Calculate'/></td></tr>
_END;
?>
<tr class="calcrow">
<td><i>You could be saving:</td>
<td align="center"><input type="text" value="<?php echo round($answer)?>"></td></i>
</tr>
</table>
</form>
<?php
if($db_server){
$image1 = mysqli_query("SELECT URL FROM images WHERE imagename='image1');"
$image2 = mysqli_query("SELECT URL FROM images WHERE imagename='image2');"
$image3 = mysqli_query("SELECT URL FROM images WHERE imagename='image3');"
$image4 = mysqli_query("SELECT URL FROM images WHERE imagename='image4');"
$image5 = mysqli_query("SELECT URL FROM images WHERE imagename='image5');"
if( $answer > 0 and $answer < 150 )?>
<img src="<?php echo $image1;?>"/>
else if( $answer < 250)
<img src="<?php echo $image2;?>"/>
else if( $answer < 350)
<img src="<?php echo $image3;?>"/>
else if( $answer < 450)
<img src="<?php echo $image4;?>"/>
else if( $answer < 550)
<img src="<?php echo $image5;?>"/>
<?php
else
echo 'error';
}
?>
Your code is a real mess. I've cleaned it a bit.
<?php
$valuea = (isset($_POST['valuea']) && is_numeric($_POST['valuea'])) ? $_POST['valuea'] : 0;
$valueb = 250;
$answer = $valuea - $valueb;
?>
<form method='post' action='calculator.php'>
<table border='0' width='500px' cellpadding='3' cellspacing='1' class="table">
<tr class="calcheading">
<td colspan="2"><strong>Work out how much you could be saving</strong></td>
</tr>
<tr class="calcrow">
<td>How much do you spend a year?</td>
<td align="center"><input type='text' name='valuea' value="$valuea"/></td>
</tr>
<tr class="calcrow">
<td>Minus the average price of an n-power student tarrif* Leave Blank:</td>
<td align="center"><input type='text' name='valueb' value="$valueb"/></td>
</tr>
<tr class="submit">
<td colspan="2"><input type='submit' value='Calculate'/></td>
</tr>
<tr class="calcrow">
<td><i>You could be saving:</td>
<td align="center"><input type="text" value="<?php echo round($answer)?>"></td></i>
</tr>
</table>
</form>
<?php
if($db_server){
switch( $answer ){
case $answer > 0 and $answer < 150 : $image = mysqli_query("SELECT URL FROM images WHERE imagename = 'image1'");
break;
case $answer < 250 : $image = mysqli_query("SELECT URL FROM images WHERE imagename = 'image2'");
break;
case $answer < 350 : $image = mysqli_query("SELECT URL FROM images WHERE imagename = 'image3'");
break;
case $answer < 450 : $image = mysqli_query("SELECT URL FROM images WHERE imagename = 'image4'");
break;
case $answer < 550 : $image = mysqli_query("SELECT URL FROM images WHERE imagename = 'image5'");
break;
}
echo "<img src='$image' alt='' />";
}
?>

Broken PHP page

I am trying to access this weapon store file and am getting a blank page. I was hoping someone could help me fix this. The link.php file is just a page holding images and is not the source of the problem as other pages calling on link work fine.
<?php
echo "<table width='100%'><tr><td valign='left' width='95%'><font size=2 color=silver><b>Weapon Market</b></font></td><td><table width=100%><tr><td align=right>";
include('../beta/files/link.php');
echo" Weapon Market. Users can come here to buy weapons that they can to to another city and sell at a black market for profit.'></a></td></tr></table><img src='/beta/layout_images/headertop.gif' width=100% height=4></center><br /><br />";
if(!isset($tools)){
echo"<font color=red><b>Error | It Seems Something Went Wrong Processing Your Account. Please Try Logging Out And Then Logging Back In. If The Problem Persists Please Email Support At Account#Steam-Wars.com. We Apologize For The Inconvenience.</b></font><br /><br /><center><img src='/beta/layout_images/headertop.gif' width=100% height=4></center><br />";
session_destroy();
exit();}
$qry = 'SELECT * FROM weapons WHERE uid='.db_quote_smart($player->uid);
$res = db_query($qry);
$has_weapons_array = mysql_fetch_array($res);
$weapon_names = array('bbgun_bullet', 'handgun_bullet', 'shotgun_bullet', 'rifle_bullet', 'bbgun', 'handgun', 'shotgun', 'ak47', 'bomb', 'taser', 'baseballbat', 'shank', 'detonator', 'battery');
$name_hash = array(
'bbgun_bullet' => 'BBGun Bullet (4-9)',
'handgun_bullet' => 'Handgun Bullet (9-47)',
'shotgun_bullet' => 'Shotgun Bullet (28,142)',
'rifle_bullet' => 'Rifle Bullet (47-237)',
'bbgun' => 'BBGun (280-300)',
'handgun' => 'Handgun (470-500)',
'shotgun' => 'Shotgun (96-100)',
'ak47' => 'AK47 (415-500)',
'bomb' => 'Bomb (248-250)',
'taser' => 'Taser (45-50)',
'baseballbat' => 'Baseball Bat (90-100)',
'shank' => 'Shank (55-100)',
'detonator' => 'Detonator (427-475)',
'battery' => 'Battery (3-9)'
);
$qry = 'SELECT * FROM prices_booze WHERE city='.db_quote_smart($player->city);
$res = db_query($qry);
$prices = mysql_fetch_array($res);
$qry = 'SELECT * FROM weapons WHERE uid='.db_quote_smart($player->uid);
$res = db_query($qry);
$weapons = mysql_fetch_array($res);
$limit = $has_weapons_array["weapon_limit"];
$space_used = 0;
foreach($weapon_names as $name){
$space_used += $weapons[$name];
}
$space_left = $limit - $space_used;
$action = $_GVARS['action'];
if( $action == 'buy' ){
foreach($weapon_names as $weapon){
$price = $prices[$weapon];
$amount = (isset($_POST[$weapon]) ? intval($_POST[$weapon]) : 0);
$cost = $price * $amount;
if( $amount > 0 ){
if( $gUser['cash'] < $cost ){
echo"<font color=red><b>Error | You Do Not Have Enough Money To Purchase $amount unit(s) Of $weapon.</b></font><br /><br /><center><img src='/beta/layout_images/headertop.gif' width=100% height=4></center><br />";
}elseif( ($space_left-$amount) < 0 ){
echo"<font color=red><b>Error | You Do Not Have Enough Space To Carry $amount unit(s) Of $weapon.</b></font><br /><br /><center><img src='/beta/layout_images/headertop.gif' width=100% height=4></center><br />";
}else{
$space_left -= $amount;
$gUser['cash'] -= $cost;
$qry = 'UPDATE user_characters SET cash=cash-'.$cost.' WHERE uid='.db_quote_smart($player->uid);
$res = db_query($qry);
$randscam = mt_rand(1, 100);
$randscam2 = mt_rand(1, 100);
if( $randscam == $randscam2 ){
echo"<font color=red><b>Error | You Were Scammed By A Dealer. The Weapons You Bought Turned Out To Be Replicas.</b></font><br /><br /><center><img src='/beta/layout_images/headertop.gif' width=100% height=4></center><br />";
$randexp=rand(0,1);
$qry = 'UPDATE user_characters SET exp=exp+'.$randexp.', drug_points=drug_points+'.$amount.' WHERE uid='.db_quote_smart($player->uid);
$res = db_query($qry);
}else{
$qry = "UPDATE weapons SET $weapon=$weapon+$amount WHERE uid=".db_quote_smart($player->uid);
$res = db_query($qry);
$randexp2=rand(1,2);
$qry = 'UPDATE user_characters SET exp=exp+'.$randexp2.', drug_points=drug_points+'.$amount.' WHERE uid='.db_quote_smart($player->uid);
$res = db_query($qry);
$sql="UPDATE adv_stats SET drugs_bought=drugs_bought+$amount WHERE uid=".db_quote_smart($player->uid);
$sql=mysql_query($sql);
echo"<font color=green><b>Ciao | You Have Purchased $amount Crate(s) Of $weapon.</b></font><br /><br /><center><img src='/beta/layout_images/headertop.gif' width=100% height=4></center><br />";
}
}
}
}
}
// gets updated version of weapons in pocket
$qry = 'SELECT * FROM weapons WHERE uid='.db_quote_smart($player->uid);
$res = db_query($qry);
$has_weapons_array = mysql_fetch_array($res);
echo "<table align=center width=100% bgcolor=000000><tr><td><br>";
echo "<table width='450' cellpadding='0' border='2' bordercolor='black' style='margin:0 auto;background-image: url(/beta/layout_images/bg_2.gif);'>
<tr bgcolor=#11111>
<td align=center>
<font face=verdana size=1 color=silver><b>Weapon</b></font>
</td>
<td align=center>
<font face=verdana size=1 color=silver><b>Cost</b></font>
</td>
<td align=center>
<font face=verdana size=1 color=silver><b># you have</b></font>
</td>
<td align=center>
<font face=verdana size=1 color=silver><b># to buy</b></font>
</td>
</tr>";
$space_used = 0;
$row = 0;
foreach($weapon_names as $weapon){
$space_used += $has_weapons_array[$weapon];
echo('<tr bgcolor="#'.($row++ % 2 ? '444444' : '333333').'">
<td align="center" width="125"><font face="tahoma" size="1" color="#ffffff"><b>'.$name_hash[$weapon].'</b></td>
<td align="center" width="125"><font face="tahoma" size="1" color="#ffffff">$ '.number_format($prices[$weapon]).'</font></td>
<td align="center" width="125"><font face="tahoma" size="1" color="#ffffff">'.number_format($has_weapons_array[$weapon]).'</font></td>
<td align="center" width="125"><font face="tahoma" size="1" color="#ffffff"><form name="login" action="driver.php?x=weaponstore" method="post"><input type="text" name="'.$weapon.'" size=5 style="font-weight:none;font-size:8pt;color:#ffffff;font-family:arial;background-color:#000000;border-color:#ffffff" maxlength="15"></font></td>
</tr>');
echo "
</table>
<table width='450' cellpadding='0' border='2' bordercolor='black' style='margin:0 auto;background-image: url(/beta/layout_images/bg_2.gif);'>
<tr bgcolor=#11111 valign=top><td>
<table width=100%><tr>
<td align=left width=125><font face=verdana size=1 color=silver><input type=radio checked name=action value=buy> Buy </td>
<td align=center width=250><font size=1><font color=#FFFFFF><b>Weapon space:</b></font> " . $space_used . "/" . $has_weapons_array["weapon_limit"] . "</font></td>
<td align=right width=125><center><font face=verdana size=1 color=silver><input type=submit value=\" Purchase Weapon \" style=\"FONT-WEIGHT: bold; FONT-SIZE: 8pt; COLOR: #FFFFFF; FONT-FAMILY: Arial; BACKGROUND-COLOR: #333333\" size=1></center></td>
</tr></table>
</td></tr>
</table>";
?>
This question was answered by me and you deleted it...
As I said before there is no end bracket in last foreach !
foreach($weapon_names as $weapon){
$space_used += $has_weapons_array[$weapon];
echo('<tr bgcolor="#'.($row++ % 2 ? '444444' : '333333').'">
<td align="center" width="125"><font face="tahoma" size="1" color="#ffffff"><b>'.$name_hash[$weapon].'</b></td>
<td align="center" width="125"><font face="tahoma" size="1" color="#ffffff">$ '.number_format($prices[$weapon]).'</font></td>
<td align="center" width="125"><font face="tahoma" size="1" color="#ffffff">'.number_format($has_weapons_array[$weapon]).'</font></td>
<td align="center" width="125"><font face="tahoma" size="1" color="#ffffff"><form name="login" action="driver.php?x=weaponstore" method="post"><input type="text" name="'.$weapon.'" size=5 style="font-weight:none;font-size:8pt;color:#ffffff;font-family:arial;background-color:#000000;border-color:#ffffff" maxlength="15"></font></td>
</tr>');
}

Categories