Jump to content

DB Error


cjohnson9

Recommended Posts

Hey guys I have an error in my code and cannot figure out what it is. I am getting a syntax error message near "where asset="

 

thanks for the help in advance

<?php

/*Written by Clinton T. Johnson for Project Worldwide and George P. Johnson Companies...*/

session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>337 Department Info System</title>
<link rel="stylesheet" href="stylesheets/styles.css" type="text/css" />

            
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/slider.js"></script>
<script type="text/javascript" src="js/superfish.js"></script>
<script type="text/javascript" src="js/custom.js"></script>

</head>

<body>
<div id="container">
<div id="header">
    	<h1><a href="index.html">Pww</a></h1>
    	<h2>Asset Tracking System</h2>
        <div class="clear"></div>
  </div>
    <div id="nav">
    	<ul class="sf-menu dropdown">
        	<li class="selected"><a href="../../user/login.php">Login</a></li>
            <li class="selected"><a href="ah.php">Auburn Hills</a></li>
            <li class="selected"><a href="Loc/LA/la.php">Los Angeles</a></li>
            <li class="selected"><a href="Loc/SC/sc.php">San Carlos</a></li>
            <li class="selected"><a href="Loc/BOS/bos.php">Boston</a></li>
            <li class="selected"><a href="Loc/BNA/bna.php">Nashville</a></li>
        </ul>
  </div>
    <div id="body" class="has-slider">
      <div class="sidebar">
        <h4><span>GPJ Assets</span></h4> 
            <ul>
               
               <li>
               <li>
                 <p style="margin: 0;">  <?php

if ($_SESSION['username'])
{

echo "<p><b>My Account</b><br /><br />
  <a href=ah.php>Auburn Hills</a><br />
      <a href=Loc/LA/la.php>Los Angeles</a><br />
      <a href=Loc/SC/sc.php>San Carlos</a><br />
    <a href=Loc/BNA/bna.php>Nashville</a><br />
      <a href=../../user/logout.php>log out</a><br />
      <a href=../../user/account.php>Account Settings</a></p>";
}?>     
                 </p>
               </li>
            </ul>
            </li>
                  <h4><span>Options</span></h4>
                  <ul>
                      
                    <li>
                                           <?php
    if ($_SESSION['username'])
  {

echo "<p><b>My Account</b><br /><br />
  <a href=ah_add.php>Add Asset</a><br />
      <a href=ah_edit.php>Edit Asset</a><br />
      <a href=ah_delete.php>Delete Asset</a><br />
      <a href=../../user/account.php>Account Settings</a></p>";
}?>
    </p>
                    </li>
            </ul>
              </li>            
</div>
         <div id="content">
            <div class="box">
                <h2>Edit Auburn Hills Asset</h2>
                <br />
              <?php
		  
		  
if ($_SESSION['username'])
		   {$con = mysql_connect("localhost","root","c3rb3ru5");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("gpj_asset", $con);

//table header code
echo "
<table border='1'>
<tr>
<th>Asset ID#</th>
<th>location</th>
<th>active</th>
<th>platform</th>
<th>Make</th>
<th>Model</th>
<th>Memory</th>
<th>Warranty</th>
<th>Active User</th>
<th>Notes</th>
</tr>";

// Pagination
if(!empty($_GET["start"])){
    $start  = $_GET['start'];// To take care global variable if OFF
}else{
    $start   = 0;
}
if(!($start > 0)) { // This variable is set to zero for the first page
    $start = 0;
}

$eu   = ($start - 0);
$limit           = 5; // No of records to be shown per page.
$whathis      = $eu + $limit;
$back          = $eu - $limit;
$next          = $eu + $limit;

// to check the total number of records
$query         = mysql_query(" SELECT * FROM assets 
					WHERE location='Auburn Hills' ORDER BY asset_id ASC ") or die (mysql_error());
$total_rows     = mysql_num_rows($query);

//select the record with limitation
$query         = mysql_query(" SELECT * FROM assets 
					WHERE location='Auburn Hills' ORDER BY asset_id ASC limit $eu, $limit ") or die (mysql_error());


while($row = mysql_fetch_array($query))
	{
  echo "<tr>";
  echo "<td>" . $row['asset_id'] . "</td>";
  echo "<td>" . $row['location'] . "</td>";
  echo "<td>" . $row['active'] . "</td>";
  echo "<td>" . $row['platform'] . "</td>";
  echo "<td>" . $row['make'] . "</td>";
  echo "<td>" . $row['model'] . "</td>"; 
  echo "<td>" . $row['ram'] . "</td>";
  echo "<td>" . $row['warranty'] . "</td>";
  echo "<td>" . $row['active_user'] . "</td>";
  echo "<td>" . $row['notes'] . "</td>";
  echo "</tr>";
	}  
  echo "</table>";
//code for previous
if($back >=0) {
echo "<a href='ah_edit.php?start=$back'><font face='Verdana' size='2'>PREV</font></a>  ";
}

//code for the number of page with links
$i     = 0;
$x    = 1;
for($i=0;$i < $total_rows;$i=$i+$limit){
if($i != $eu){
    echo "<a href='ah_edit.php?start=$i'><font face='Verdana' size='2'>$x</font></a> ";
}else { 
    echo "<font face='Verdana' size='4' color=red>$x</font>";
} // Current page is not displayed as link and given font color red

$x    = $x+1;
}
//code for next
if($whathis < $total_rows) {
echo "<a href='ah_edit.php?start=$next'><font face='Verdana' size='2'>NEXT</font></a>";
}   
	}
 else  echo " <form action=../user/connect.php method=POST>
<h3>Login</h3>

<table border=0>
<tr><td>Username:</td><td> <input type=text name=username></td></tr>
<tr><td>Password:</td><td> <input type=password name=password></td></tr></table>
<input class=buttonSubmit type=submit name=submit value=submit></form>";
?>
</h2>
<?php 

 if ($_SESSION['username'])
  {   
{$con = mysql_connect("localhost","root","c3rb3ru5");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("gpj_assets", $con);
  

//process the input into variables
$submit = $_POST['edit_asset'];
$asset_id = strtolower(strip_tags(trim($_POST['asset_id'])));
$location = strip_tags(trim($_POST['location']));
$active = strip_tags(trim($_POST['status']));
$platform  = strip_tags(trim($_POST['type']));
$make  = strip_tags(trim($_POST['make']));
$model = strip_tags(trim($_POST['model']));
$Ram = strip_tags(trim($_POST['Ram']));
$warranty = strip_tags(trim($_POST['warranty']));
$active_user = strip_tags(trim($_POST['active_user']));
$notes = strip_tags(trim($_POST['notes']));



if ($submit)
{

// Check for an existing asset
$runThis = "SELECT * FROM assets WHERE asset_id = '$asset_id'";
//find the amount that match
$count = mysql_num_rows($runThis);


//Validate input
$error = false;
if ($count!=1)
{
 $error = "Don't Be rediculous, enter an existing id...";
}

else
{
   //No input errors, run query
$query = "UPDATE asset SET location = '$location', SET active = '$active', SET platform = '$platform', SET make = '$make', SET 
model = '$model', SET Ram = '$Ram', SET warranty = '$warranty', SET active_user = '$active_user', SET  notes = '$notes'
WHERE asset_id = $asset_id";
//Check if any errors occured
if($error !== false)
{
    echo "<span style=\"color:red\"> {$error}</pan>\n";
}
else
{
    echo "Edit was completed Successfully";
}
  }
}
  
  else echo " <form action=../user/connect.php method=POST>
<h3>Please Login <img src=\"images/0.410.gif\" /></h3>

<table border=0>
<tr><td>Username:</td><td> <input type=text name=username></td></tr>
<tr><td>Password:</td><td> <input type=password name=password></td></tr></table>
<input class=buttonSubmit type=submit name=submit value=submit></form>";
}
  }
?>
<form action ='ah_edit.php' method="POST">

    <table border=1>
  
<tr><td>Asset ID: *</td><td> <input type=text name="asset_id" maxlength="10" size="10">
</td></tr>

<tr><td>Location: *</td>
<td> <select name="location" id="location"> 
<option value ="Auburn Hills"> Auburn Hills</option>
<option value ="Los Angeles"> Los Angeles</option>
<option value ="San Carlos"> San Carlos</option>
<option value ="Boston"> Boston</option>
<option value ="Nashville"> Nashville</option>
</td></tr>

<tr><td>Status: *</td>
<td> <select name="status" id="status">
<option value ="active"> active</option>
<option value ="spare"> spare</option>
</td></tr>

<tr><td>Type: *</td>
<td> <select name="type" id="type">
<option value ="desktop"> desktop</option>
<option value ="laptop"> laptop</option>
<option value ="server"> server</option>
</td></tr>

<tr><td>Manufacturer:</td>
<td> <select name="make" id="make">
<option value ="Apple"> Apple</option>
<option value ="Dell"> Dell</option>
<option value ="HP"> HP</option>
<option value ="IBM"> IBM</option>
<option value ="Lenovo"> Lenovo</option>
<option value ="Custom"> Custom</option>
</td></tr>

<tr><td>Model: *</td>
<td> <select name="model" id="model">
<option value ="MB Pro">MacBook Pro</option>
<option value ="Mac Pro">Mac Pro</option>
<option value ="Dimension D-620">Dimension D-620</option>
<option value ="Dimension D-630">Dimension D-630</option>
<option value ="Optiplex 745">Optiplex 745</option>
<option value ="Optiplex 780">Optiplex 780</option>
<option value ="Dimension M90">Dimension M90</option>
<option value ="Dimension M6500">Dimension M6500</option>
<option value ="Dimension E6410">Dimension E6410</option>
<option value ="Dimension E6420">Dimension E6420</option>
</td></tr>

<tr><td>Amount of Ram:</td>
<td> <select name="Ram" id="Ram">
<option value ="not sure"> not sure</option>
<option value ="Under 1GB"> under 1GB</option>
<option value ="1 GB"> 1 GB</option>
<option value ="2 GB"> 2 GB</option>
<option value ="3 GB"> 3 GB</option>
<option value ="4 GB"> 4 GB</option>
<option value ="8 GB"> 8 GB</option>
<option value ="16 GB"> 16 GB</option>
<option value ="24 GB"> 24 GB</option>
<option value ="Above 24GB"> Above 24GB</option>
</td></tr>

<tr><td>warranty:</td><td> <input type="text" name="warranty" maxlength="20" size="20"></td></tr>

<tr><td>username:</td><td> <input type="text" name="active_user" maxlength="8" size="8"></td></tr>

<tr><td>notes:</td><td> <input type="text" name="notes" maxlength="45" size="45"></td></tr>
</table>
<br>
            <input class="buttonSubmit" type="submit" name="edit_asset" value="Update Asset">             
</form>
           </div>
        </div>
     
   <div class="clear"></div>
    </div>
    <div id="footer">
        <div class="footer-content">
    
        <span class="sitename">PWW</span>
          		<p class="footer-links">
                    <a href="ah.php">Auburn Hills</a>
                    <a href="Loc/LA/la.php">Los Angeles</a>
                    <a href="Loc/SC/sc.php">San Carlos</a>
                    <a href="Loc/BOS/bos.php">Boston</a>
                    <a href="Loc/BNA/bna.php">Nashville</a>
               	 </p>
                 <div class="clear"></div>
        </div>
        
    
    </div>
</div>
</body>
</html>

 

Link to comment
Share on other sites

You're doing the same thing right above where PFM pointed out after if ($submit).

 

There is a SELECT but no actual execution to provide mysql_num_rows() with a resource id:

// Check for an existing asset
$runThis = "SELECT * FROM assets WHERE asset_id = '$asset_id'";
//find the amount that match
$count = mysql_num_rows($runThis);

Link to comment
Share on other sites

I thought I knew why my query was not executing but now I am stuck...

 

Here is my code right now...

<?php

 if ($_SESSION['username'])
  {

{$con = mysql_connect("localhost","root","c3rb3ru5");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("gpj_asset", $con);


//process the input into variables
$submit = $_POST['edit_asset'];
$asset_id = strtolower(strip_tags(trim($_POST['asset_id'])));
$location = strip_tags(trim($_POST['location']));
$active = strip_tags(trim($_POST['status']));
$platform  = strip_tags(trim($_POST['type']));
$make  = strip_tags(trim($_POST['make']));
$model = strip_tags(trim($_POST['model']));
$Ram = strip_tags(trim($_POST['Ram']));
$warranty = strip_tags(trim($_POST['warranty']));
$active_user = strip_tags(trim($_POST['active_user']));
$notes = strip_tags(trim($_POST['notes']));


if ($submit)
{

// Check for an existing asset
$runThis = "SELECT * FROM assets WHERE asset_id = '$asset_id'";

$qr = mysql_query($runThis);

//find the amount that match
$count = mysql_num_rows($qr);


//Validate input
$error = false;
if ($count=0)
{ $error = "No record found!!!!";
}
if ($asset_id == "")
{
    $error = "Asset Id required";
}
else
{
   //No input errors, run query
$query = "UPDATE assets
SET  location = '$location', status = '$status', type = '$type', make = '$make', model='$model', 
Ram = '$Ram', warranty = '$warranty', active_user = '$active_user', notes = 'notes',
WHERE asset_id = $asset_id";

   $result = mysql_query($query);
   if (!$result)
       {
	   die('Invalid query: ' . mysql_error());
       }
}
}

//Check if any errors occured
if($error !== false)
{
    echo "<span style=\"color:red\"> {$error}</pan>\n";
}
else
{
    echo "Edit was completed Successfully";
}
  }
}

  else echo " <form action=../../user/connect.php method=POST>
<h3>Please Login <img src=\"images/0.410.gif\" /></h3>

<table border=0>
<tr><td>Username:</td><td> <input type=text name=username></td></tr>
<tr><td>Password:</td><td> <input type=password name=password></td></tr></table>
<input class=buttonSubmit type=submit name=submit value=submit></form>";

?>
<form action ='ah_edit.php' method="POST">

    <table border=1>
  
<tr><td>Asset ID: *</td><td> <input type=text name="asset_id" maxlength="10" size="10">
</td></tr>

<tr><td>Location: *</td>
<td> <select name="location" id="location"> 
<option value ="Auburn Hills"> Auburn Hills</option>
<option value ="Los Angeles"> Los Angeles</option>
<option value ="San Carlos"> San Carlos</option>
<option value ="Boston"> Boston</option>
<option value ="Nashville"> Nashville</option>
</td></tr>

<tr><td>Status: *</td>
<td> <select name="status" id="status">
<option value ="active"> active</option>
<option value ="spare"> spare</option>
</td></tr>

<tr><td>Type: *</td>
<td> <select name="type" id="type">
<option value ="desktop"> desktop</option>
<option value ="laptop"> laptop</option>
<option value ="server"> server</option>
</td></tr>

<tr><td>Manufacturer:</td>
<td> <select name="make" id="make">
<option value ="Apple"> Apple</option>
<option value ="Dell"> Dell</option>
<option value ="HP"> HP</option>
<option value ="IBM"> IBM</option>
<option value ="Lenovo"> Lenovo</option>
<option value ="Custom"> Custom</option>
</td></tr>

<tr><td>Model: *</td>
<td> <select name="model" id="model">
<option value ="MB Pro">MacBook Pro</option>
<option value ="Mac Pro">Mac Pro</option>
<option value ="Dimension D-620">Dimension D-620</option>
<option value ="Dimension D-630">Dimension D-630</option>
<option value ="Optiplex 745">Optiplex 745</option>
<option value ="Optiplex 780">Optiplex 780</option>
<option value ="Dimension M90">Dimension M90</option>
<option value ="Dimension M6500">Dimension M6500</option>
<option value ="Dimension E6410">Dimension E6410</option>
<option value ="Dimension E6420">Dimension E6420</option>
</td></tr>

<tr><td>Amount of Ram:</td>
<td> <select name="Ram" id="Ram">
<option value ="not sure"> not sure</option>
<option value ="Under 1GB"> under 1GB</option>
<option value ="1 GB"> 1 GB</option>
<option value ="2 GB"> 2 GB</option>
<option value ="3 GB"> 3 GB</option>
<option value ="4 GB"> 4 GB</option>
<option value ="8 GB"> 8 GB</option>
<option value ="16 GB"> 16 GB</option>
<option value ="24 GB"> 24 GB</option>
<option value =" 24GB+">24GB+</option>
</td></tr>

<tr><td>warranty:</td><td> <input type="text" name="warranty" maxlength="20" size="20"></td></tr>

<tr><td>username:</td><td> <input type="text" name="active_user" maxlength="8" size="8"></td></tr>

<tr><td>notes:</td><td> <input type="text" name="notes" maxlength="45" size="45"></td></tr>
</table>
<br>
            <input class="buttonSubmit" type="submit" name="edit_asset" value="Update Asset">             
</form>

 

This is what is displayed when i turn on error messaging...

Notice: Undefined index: edit_asset in /var/www/PWW/Loc/AH/ah_edit.php on line 207 Notice: Undefined index: asset_id in /var/www/PWW/Loc/AH/ah_edit.php on line 208 Notice: Undefined index: location in /var/www/PWW/Loc/AH/ah_edit.php on line 209 Notice: Undefined index: status in /var/www/PWW/Loc/AH/ah_edit.php on line 210 Notice: Undefined index: type in /var/www/PWW/Loc/AH/ah_edit.php on line 211 Notice: Undefined index: make in /var/www/PWW/Loc/AH/ah_edit.php on line 212 Notice: Undefined index: model in /var/www/PWW/Loc/AH/ah_edit.php on line 213 Notice: Undefined index: Ram in /var/www/PWW/Loc/AH/ah_edit.php on line 214 Notice: Undefined index: warranty in /var/www/PWW/Loc/AH/ah_edit.php on line 215 Notice: Undefined index: active_user in /var/www/PWW/Loc/AH/ah_edit.php on line 216 Notice: Undefined index: notes in /var/www/PWW/Loc/AH/ah_edit.php on line 217 Notice: Undefined variable: error in /var/www/PWW/Loc/AH/ah_edit.php on line 258 Notice: Undefined variable: error in /var/www/PWW/Loc/AH/ah_edit.php on line 260

 

 

Link to comment
Share on other sites

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.