Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Having trouble with a MYSQL update

    Hello everyone,

    I am having trouble with some code that updates a database with information taken from a form. I keep getting these errors...

    ["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
    "

    Below is the Latest version of the code, it seems to point to my variables as errors
    Code:
    <?php
    ini_set ("display_errors", "1");
    error_reporting(E_ALL);
    
    
    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.php">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="Loc/AH/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/ah.php>Auburn Hills</a><br />
          <a href=LA/la.php>Los Angeles</a><br />
          <a href=SC/sc.php>San Carlos</a><br />
    	  <a href=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>&nbsp;&nbsp;";
    }
    
    //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>
     <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_id" value="Update">
    </form>
     <?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_id'];
    $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
    $queryresult = mysql_query($runThis);
    $count = mysql_num_rows($queryresult);
    
    //Validate input
    $error = false;
    if ($count=0)
    { $error = "No entry";
    }
    else if ($asset_id == "")
    {
        $error = "Asset ID field is 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 "Asset Added 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>";
      
    ?>	
      
    
               </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="../LA/la.php">Los Angeles</a>
                        <a href="../SC/sc.php">San Carlos</a>
                        <a href="../BOS/bos.php">Boston</a>
                        <a href="../BNA/">Nashville</a>
                   	 </p>
                     <div class="clear"></div>
            </div>
            
        
        </div>
    </div>
    </body>
    </html>
    Last edited by cjohnson; 09-09-2011 at 03:39 AM. Reason: formatting

  2. #2
    Regular Coder
    Join Date
    May 2011
    Posts
    246
    Thanks
    1
    Thanked 59 Times in 58 Posts
    The first time you run the page, these indexes are undefined.

    Try this

    PHP Code:
    if (!empty($_POST['edit_id']))
    {
            
    $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']));


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

            
    //Validate input
            
    $error false;
            if (
    $count=0)
            { 
    $error "No entry";
            }
            else if (
    $asset_id == "")
            {
                
    $error "Asset ID field is 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());
                   }
            }


  3. #3
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    use isset function first time e.g

    if ( isset ( $A ) )
    {

    /// do update

    }

  4. #4
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    trouble

    I am still having some trouble with this code, I was getting just the submit button was undefined, but now all of them are now undefined...
    Do I do an isset for all the variables I am sending?
    Here is my current code...
    PHP Code:
    <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_id" value="Update">
    </form>
     <?php 
        
         
    if ($_SESSION['username'])
      { 

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

    mysql_select_db("gpj_asset"$con);
               

            if (
    $submit)
    {
    if (!empty(
    $_POST['edit_id'])) 
    {
            
            
    $submit strtolower(strip_tags(trim($_POST['edit_id'])));     
            
    $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']));

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

            
    //Validate input 
            
    $error false
            if (
    $count=0
            {
                 
    $error "No entry"
            } 
            else if (
    $asset_id == ""
            { 
                
    $error "Asset ID field is 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()); 
                   } 
            } 
    }
    }
    }
    }  
      
      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>"
    ;
      
    ?>
    Last edited by Inigoesdr; 09-09-2011 at 05:09 PM.

  5. #5
    Regular Coder
    Join Date
    May 2011
    Posts
    246
    Thanks
    1
    Thanked 59 Times in 58 Posts
    PHP Code:
    <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_id" value="Update"> 
    </form> 
     <?php  
         
         
    if ($_SESSION['username']) 
      {  

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

    mysql_select_db("gpj_asset"$con); 
                

    if (!empty(
    $_POST['edit_id']))  

             
            
    $submit strtolower(strip_tags(trim($_POST['edit_id'])));      
            
    $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'])); 

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

            
    //Validate input  
            
    $error false;  
            if (
    $count=0)  
            { 
                 
    $error "No entry";  
            }  
            else if (
    $asset_id == "")  
            {  
                
    $error "Asset ID field is 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());  
                   }  
            }  


    }   
       
      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>"

       
    ?>

  6. #6
    Regular Coder
    Join Date
    May 2011
    Posts
    246
    Thanks
    1
    Thanked 59 Times in 58 Posts
    You should also replace
    PHP Code:
    if ($_SESSION['username']) 
    with
    PHP Code:
    if (!empty($_SESSION['username'])) 

  7. #7
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Submit errors

    Hey Gurus,

    I have made the changes but am still getting my submit var as undefined...

    Do I need to use isset as was recommended because I am using select options in my form?

    This page is the very last page I have to write for this project, it was working when I was using text boxes but when I changed to select options things go poof. Just getting more frustrated lol

    Thanks again for all the help!!!!!!

    PHP Code:
    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>&nbsp;&nbsp;";
    }

    //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>
     <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_id" value="Update">  
    </form>  
     <?php   
          
         
    if (!empty($_SESSION['username']))  
      {   

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

    mysql_select_db("gpj_asset"$con);  
                 

    if (!empty(
    $_POST['edit_id']))   
    {  
              
            
    $submit strtolower(strip_tags(trim($_POST['edit_id'])));       
            
    $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']));  

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

            
    //Validate input   
            
    $error false;   
            if (
    $count=0)   
            {  
                 
    $error "No entry";   
            }   
            else if (
    $asset_id == "")   
            {   
                
    $error "Asset ID field is 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());   
                   }   
            }   
    }  
    }  
    }    
        
      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>"
    ;  
        
    ?>

  8. #8
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,979
    Thanks
    104
    Thanked 583 Times in 570 Posts
    Quote Originally Posted by cjohnson View Post
    I am still having some trouble with this code, I was getting just the submit button was undefined
    You should never be checking for a submit button to trigger form submission processing. Instead use the name of a form field or a hidden element in your isset(). My sig gives a bit more detail.
    Quote Originally Posted by deathshadow View Post
    So seriously, loosen up that tie, let out the belt, and try relating to normal people on the street instead of the gentleman's club crowd.

  9. #9
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Still a little confused but getting better...

    Well I think I understand what you are saying... Dont use isset on the submit button due to ie error. I am having trouble with my direction though. Could you give me an example of how I should fix my variables? I think I will have to write an if statement to see which ones are empty. Now what happens if they are empty? Do I need to break up the query so that each one only updates the db if it is populated by the form?

    Thanks

  10. #10
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey guys I made some changes... I still have a syntax error that I am trying to find, am I on the right track?

    PHP Code:
    <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_id" value="Update">  
    </form>  
     <?php   
          
         
    if ($_SESSION['username'])
      {   

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

    mysql_select_db("gpj_asset"$con);  
                        
            
    $submit =  $_POST['edit_id'];  
             
    $asset_id $_POST['asset_id'];   
            
    $location $_POST['location'];   
            
    $active $_POST['status'];   
             
    $platform  $_POST['type'];   
               
    $make  $_POST['make'];   
            
    $model $_POST['model'];   
            
    $Ram $_POST['Ram'];
            
    $warranty $_POST['warranty'];   
               
    $active_user $_POST['active_user'];   
            
    $notes $_POST['notes'];  

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

                 
    //No input errors, run query  
                 
    if (isset($location))
                 {
                     
    $query "UPDATE assets   
             SET  location = '
    $location'  
             WHERE asset_id = 
    $asset_id"
                  }
                 if (isset(
    $status))
                 {
                     
    $query "UPDATE assets   
             SET   status = '
    $status', 
             WHERE asset_id = 
    $asset_id"
                 }
                 
                 if (isset(
    $type))
                 {
                     
    $query "UPDATE assets   
             SET  platform = '
    $type'  
             WHERE asset_id = 
    $asset_id"
                 }
                 if (isset(
    $make))
                 {
                     
    $query "UPDATE assets   
             SET  make = '
    $make'   
             WHERE asset_id = 
    $asset_id"
                 }
                 if (isset(
    $model)){
                     
    $query "UPDATE assets   
             SET   model='
    $model'  
             WHERE asset_id = 
    $asset_id"
                 }
                 if (isset(
    $Ram))
                 {
                     
    $query "UPDATE assets   
             SET   Ram = '
    $Ram'  
             WHERE asset_id = 
    $asset_id"
                 }
                 if (isset(
    $warranty))
                 {
                     
    $query "UPDATE assets   
             SET   warranty = '
    $warranty'  
             WHERE asset_id = 
    $asset_id"
                 }
                 if (isset(
    $active_user))
                 {
                     
    $query "UPDATE assets   
             SET   active_user = '
    $active_user
             WHERE asset_id = 
    $asset_id"
                 }
                 if (isset(
    $notes))
                 {
                     
    $query "UPDATE assets   
             SET   notes = '
    $notes'   
             WHERE asset_id = 
    $asset_id"
                 } 

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

      
       
    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>"
    ;  

    ?>


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •