Page 1 of 1

Can't find my error :(

Posted: Sun Dec 06, 2009 12:40 pm
by failz_php
I'm doing a project in which I must create a basic website with php coding to allow an admin to edit details in a database and also allow them to delete a record.

I've had others look at the code and none of us can figure out why its not working.

The error:
Notice: Undefined index: motorID in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_u008312/public_html/DIT/deleteselect.php on line 34

I get this when I click to update or delete a record, just ignore the add code as that is working fine, here is my coding so far:

MAIN PAGE - admin.php

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>TVMH - Admin</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="main">
<div id="header_text">
    <span class="header_text1">Team Valley</span>
    <span class="header_text2">Motor Homes</span>
</div>
<div id="header_image"></div>
<div id="horizontal_menu" class="navigation_text"><a href="index.php">Home</a> &curren;<a href="motorhomes.php"> Motorhomes</a> &curren;<a href="search.php"> Search</a> &curren;<a href="admin.php"> Admin</a> &curren; <a href="credits.php">Credits</a></div>
<div id="vertical_menu">
<h2>Site Navigation</h2>
<ul>
    <li><a href="index.php">Home</a></li>
    <li><a href="motorhomes.php">Motorhomes</a></li>
    <li><a href="search.php">Search</a></li>
    <li><a href="admin.php">Admin</a></li>
    <li><a href="credits.php">Credits</a></li>
</ul>
    <h2>Copyright &copy;</h2>
<div class="leftbottomtext" align="center"><strong>Copyright &copy; 2009</strong><br />
    <a href="#">Kyle Ainsley</a> <br /></div>
</div>
<div id="content">
<h1>Admin!</h1>
<h2>Add Record</h2>
<form id = "AddMotorhome" method = "get"
    action = "addmotorhome.php">
 
Manufacturer
    <input type = "text" 
        name = "manufacturer" id = "manufacturer" />
<br />
Model 
    <input type = "text" 
        name = "model" id = "model" />
<br />  
Year 
    <input type = "integer" 
        name = "year" id = "year" />
<br />
Engine 
    <input type = "text" 
        name = "engine" id = "engine" />
 <br /> 
Berths
    <select name = "berths" id = "berths">
        <option value = "1">1</option>
        <option value = "2">2</option>
        <option value = "3">3</option>
        <option value = "4">4</option>
        <option value = "5">5</option>
        <option value = "6">6</option>
        <option value = "7">7</option>
        <option value = "8">8</option>
    </select>
<br />  
Mileage 
    <input type = "integer" 
        name = "mileage" id = "mileage" />
<br />  
Price 
    <input type = "integer" 
        name = "price" id = "price" />
<br /> 
Layout 
    <input type = "text" 
        name = "layout" id = "layout" />
<br /> 
Ownership
    <input type="radio" name="ownership" value="new" checked /> New
    <input type="radio" name="ownership" value="preowned" /> Preowned
<br />  
Description 
    <input type = "text" 
        name = "description" id = "description" />
<br />
    <input type = "submit" value = "Add" />
</form>
<hr />
<h2>Update Record</h2>
<form id = "UpdateMotorhome" method = "get" 
    action = "updateselect.php">
<select name = "updateselect" id = "updateselect">
<?php
    include 'db_conn.php';
    $sql = "SELECT motorID, model FROM motorhomes";
    $queryresult = mysql_query($sql) or die (mysql_error());
    while($row = mysql_fetch_assoc($queryresult)){
        $motorID = $row['motorID'];
        $model = $row['model'];
        echo "<option value = \"$motorID\">$model</option>\n";
    }
    mysql_free_result($queryresult);
    mysql_close($conn);
?>
</select>
<input type = "submit" value = "Select" />
</form>
<hr />
<h2>Delete Record</h2>
<form id = "DeleteMotorhome" method = "get" 
    action = "deleteselect.php">
<select name = "deleteSelect" id = "deleteSelect">
<?php
    include 'db_conn.php';
    $sql = "SELECT motorID, model FROM motorhomes";
    $queryresult = mysql_query($sql) or die (mysql_error());
    while($row = mysql_fetch_assoc($queryresult)){
        $motorID = $row['motorID'];
        $model = $row['model'];
        echo "<option value = \"$motorID\">$model</option>\n";
    }
    mysql_free_result($queryresult);
    mysql_close($conn);
?>
</select>
<input type = "submit" value = "Delete" />
</form>
</div>
</div>
</body>
</html>
updateselect.php

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>TVMH - Admin</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="main">
<div id="header_text">
    <span class="header_text1">Team Valley</span>
    <span class="header_text2">Motor Homes</span>
</div>
<div id="header_image"></div>
<div id="horizontal_menu" class="navigation_text"><a href="index.php">Home</a> &curren;<a href="motorhomes.php"> Motorhomes</a> &curren;<a href="search.php"> Search</a> &curren;<a href="admin.php"> Admin</a> &curren; <a href="credits.php">Credits</a></div>
<div id="vertical_menu">
<h2>Site Navigation</h2>
<ul>
    <li><a href="index.php">Home</a></li>
    <li><a href="motorhomes.php">Motorhomes</a></li>
    <li><a href="search.php">Search</a></li>
    <li><a href="admin.php">Admin</a></li>
    <li><a href="credits.php">Credits</a></li>
</ul>
<h2>Copyright &copy;</h2>
<div class="leftbottomtext" align="center"><strong>Copyright &copy; 2009</strong><br />
<a href="#">Kyle Ainsley</a> <br /></div>
</div>
<div id="content">
<h1>Admin!</h1>
<h2>Updating Record</h2>
<?php
    include 'db_conn.php';
    $motorID = $_GET['motorID'];
 
    $sql = "SELECT * FROM motorhomes WHERE motorID = '$motorID'";
    $queryresult = mysql_query($sql) or die (mysql_error());
    
    $row = mysql_fetch_assoc($queryresult);
    
    $manufacturer = $row['manufacturer'];
    $model = $row['model'];
    $year = $row['year'];
    $engine = $row['engine'];
    $berths = $row['berths'];
    $mileage = $row['mileage'];
    $price = $row['price'];
    $layout = $row['layout'];
    $ownership = $row['ownership'];
    $description = $row['description'];
?>
 
<form action = "updatemotorhome.php" id = "Update" method = "get">
    Manufacturer
    <input type = "text" name = "manufacturer" value = "<?php echo $manufacturer; ?>" /><br />
    Model
    <input type = "text" name = "model" value = "<?php echo $model; ?>" /><br />
    Year
    <input type = "text" name = "year" value = "<?php echo $year; ?>" /><br />
    Engine
    <input type = "text" name = "engine" value = "<?php echo $engine; ?>" /><br />
    Berths
    <input type = "text" name = "berths" value = "<?php echo $berths; ?>" /><br />
    Mileage
    <input type = "text" name = "mileage" value = "<?php echo $mileage; ?>" /><br />
    Price
    <input type = "text" name = "price" value = "<?php echo $price; ?>" /><br />
    Layout
    <input type = "text" name = "layout" value = "<?php echo $layout; ?>" /><br />
    Ownership
    <input type = "text" name = "ownership" value = "<?php echo $ownership; ?>" /><br />
    Description
    <input type = "text" name = "description" value = "<?php echo $description; ?>" /><br />
    <input type = "submit" value = "Update" />
</form>
</div>
</div>
</body>
</html>
deleteselect.php

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>TVMH - Admin</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="main">
<div id="header_text">
    <span class="header_text1">Team Valley</span>
    <span class="header_text2">Motor Homes</span>
</div>
<div id="header_image"></div>
<div id="horizontal_menu" class="navigation_text"><a href="index.php">Home</a> &curren;<a href="motorhomes.php"> Motorhomes</a> &curren;<a href="search.php"> Search</a> &curren;<a href="admin.php"> Admin</a> &curren; <a href="credits.php">Credits</a></div>
<div id="vertical_menu">
<h2>Site Navigation</h2>
<ul>
    <li><a href="index.php">Home</a></li>
    <li><a href="motorhomes.php">Motorhomes</a></li>
    <li><a href="search.php">Search</a></li>
    <li><a href="admin.php">Admin</a></li>
    <li><a href="credits.php">Credits</a></li>
</ul>
<h2>Copyright &copy;</h2>
<div class="leftbottomtext" align="center"><strong>Copyright &copy; 2009</strong><br />
<a href="#">Kyle Ainsley</a> <br /></div>
</div>
<div id="content">
<h1>Admin!</h1>
<h2>Confirm Delete</h2>
<?php
    include 'db_conn.php';
    $motorID = $_GET['motorID'];
    $sql = "SELECT * FROM motorhomes WHERE motorID = '$motorID'";
    $queryresult = mysql_query($sql)
    or die(mysql_error());
    while ($row = mysql_fetch_assoc($queryresult)) {
        $motorID = $row['motorID'];
               $manufacturer = $row['manufacturer'];
               $model = $row['model'];
               $year = $row['year'];
               $engine = $row['engine'];
               $berths = $row['berths'];
               $mileage = $row['mileage'];
               $price = $row['price'];
               $layout = $row['layout'];
               $ownership = $row['ownership'];
        $description = $row['description'];
               echo "Motor ID: $motorID<br />Manufacturer: $manufacturer<br />Model: $model<br />Year: $year<br />Engine: $engine<br />Berths: $berths<br />Mileage: $mileage<br />Price: $price<br />Layout: $layout<br />Ownership: $ownership<br />Description: $description<br />";
               echo "<hr />";
    }
    mysql_free_result($queryresult);
    mysql_close($conn);
?>
<form action = "deletemotorhome.php" id = "Delete" method = "get">
    <input type = "submit" value = "Delete" />
</form>
</div>
</div>
</body>
</html>

Re: Can't find my error :(

Posted: Sun Dec 06, 2009 2:04 pm
by AbraCadaver
You don't have any form inputs named motorID, so you won't have a $_GET['motorID']. You have selects named deleteSelect and updateSelect.

-Shawn

Re: Can't find my error :(

Posted: Sun Dec 06, 2009 2:08 pm
by failz_php
omg thanks bro, cant believe i missed that. I'm such a thick idiot lol