mysql error in edit page.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jive
Forum Newbie
Posts: 20
Joined: Thu May 23, 2002 1:34 pm
Contact:

mysql error in edit page.

Post by jive »

Hey guys, thank for all your help so far. I've run into a problem with my edit page.



newac_edit.php


Code: Select all

<html>

<head>

<title>Untitled Document</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

<body>

<?php

$type = $_GET['type'];

$ac_desc_ID = $_GET['ac_desc_ID'];

//echo($type);

//echo($ac_desc_ID);

include ("connect.php");

echo("Edit from the <b> $type </b>aircraft type ");

$aircraftlist = mysql_query("SELECT * FROM ac_description WHERE ID='$ac_desc_ID'");

$aircraft = mysql_fetch_array($aircraftlist);

$description_order = $aircraft['description_order']; 

$ac_desc_ID = $aircraft['ID']; 

$ac_name = $aircraft['ac_name'];

$serial_num = $aircraft['serial_num'];

$registration_num = $aircraft['registration_num'];

$L_engine = $aircraft['L_engine'];

$R_engine = $aircraft['R_engine'];

$L_propeller = $aircraft['L_propeller'];

$R_propeller = $aircraft['R_propeller'];

$C_propeller = $aircraft['registration_num'];

$interior = $aircraft['interior'];

$exterior = $aircraft['exterior'];

$optional_equip = $aircraft['optional_equip'];

$avionics = $aircraft['avionics'];

$actype_ID = $aircraft['actype_ID'];

echo($actype_ID . "hello");

?>

 

 

<form name="editaircraft" method="post" action="<?=$_SERVER['PHP_SELF']?>" enctype="multipart/form-data">

<table><tr><td>

<table><tr><td>

Add aircraft to which aircraft type?:</td>

<td>

<select name="typeID">

<option value="">Aircraft Type</option>

<option value="">- - - - - - - -</option>

<?php 

// Aircraft select box 

$sql        = 'SELECT * FROM ac_type'; 

$actypelist = mysql_query($sql) or die(mysql_error()); 

 

while($actype = mysql_fetch_array($actypelist)) { 

    $typeID     = $actype['ID']; 

    $type     = $actype['type']; 

    $selected = ($actype_ID == $typeID) ? 'selected="selected"' : ''; 

    echo '<option value="'.$typeID.'" '.$selected.'>'.$type.'</option>'."\n"; 

} 

?> 

 

</select></td><td>

Aircraft order:</td><td> <input type="text" size="5" maxlength="10" name="description_order" value="<?=$description_order?>"></td>

</tr></table>

<table><tr><td>

Aircraft Name:</td><td> <input type="text" size="25" maxlength="100" name="ac_name" value="<?=$ac_name?>"></td>

</tr>

<tr>

<td>

Serial Number:</td><td> <input type="text" size="25" maxlength="100" name="serial_num" value="<?=$serial_num?>"></td>

</tr>

<tr>

<td>

Registration Number:</td><td><input type="text" size="25" maxlength="100" name="registration_num" value="<?=$registration_num?>"></td>

</tr>

<tr>

<td colspan="2">Engines</td>

</tr>

<tr>

<td>Left:</td><td><input type="text" size="25" maxlength="100" name="L_engine" value="<?=$L_engine?>"></td>

</tr>

<tr>

<td>Right:</td><td><input type="text" size="25" maxlength="100" name="R_engine" value="<?=$R_engine?>"></td>

</tr>

<tr>

<td>

Propellers

</td>

</tr>

<tr>

<td>Left:</td><td><input type="text" size="25" maxlength="100" name="L_propeller" value="<?=$L_propeller?>"></td></tr>

<tr><td>

Right:</td><td><input type="text" size="25" maxlength="100" name="R_propeller" value="<?=$R_propeller?>"></td></tr>

<tr><td>

Center:</td><td><input type="text" size="25" maxlength="100" name="C_propeller" value="<?=$C_propeller?>"></td>

</tr>

<tr><td valign="top">

Interior:</td>

<td>

<textarea cols="26" rows="10" name="interior"><?=$interior?></textarea>

<script language="JavaScript1.2" defer>

editor_generate('topic_text');

</script></td>

</tr>

<tr>

<td valign="top">

Exterior</td>

<td>

<textarea cols="26" rows="10" name="exterior"><?=$exterior?></textarea></td></tr>

<tr><td valign="top">

Optional Equipment:</td>

<td><textarea cols="26" rows="10" name="optional_equip"><?=$optional_equip?></textarea></td></tr>

<tr><td valign="top">

Avionics:</td>

<td>

<textarea cols="26" rows="10" name="avionics"><?=$avionics?></textarea></td></tr>

 

<tr><td valign="top">

Exterior Image:</td><td> <input type="file" name="img_exterior"></td> </tr>

<tr><td valign="top">

Cockpit Image:</td><td> <input type="file" name="img_cockpit"></td> </tr>

<tr><td valign="top">

Interior Image:</td><td> <input type="file" name="img_interior"></td> </tr>

 

<tr>

<td colspan="2">

<input type="hidden" name="ac_desc_ID" value="<?=$ac_desc_ID?>">

<input type="submit" value="submit" name="edit_aircraft">

</td>

</tr></table>

</td></tr></table>

</form>

 

<?php

 

 

if(isset($_POST['edit_aircraft'])) {

$description_order = (int) $_POST['description_order']; 

$typeID = (int) $_POST['actype_ID']; 

$ac_name = addslashes($_POST['ac_name']);

$serial_num = addslashes($_POST['serial_num']);

$registration_num = addslashes($_POST['registration_num']);

$L_engine = addslashes($_POST['L_engine']);

$R_engine = addslashes($_POST['R_engine']);

$L_propeller = addslashes($_POST['L_propeller']);

$R_propeller = addslashes($_POST['R_propeller']);

$C_propeller = addslashes($_POST['registration_num']);

$interior = addslashes($_POST['interior']);

$exterior = addslashes($_POST['exterior']);

$optional_equip = addslashes($_POST['optional_equip']);

$avionics = addslashes($_POST['avionics']);

$ac_desc_ID = (int) $_POST['ID']; 

//Update photos if any.    

if ($_FILES['img_exterior']['type'] == "image/gif" or $_FILES['img_exterior']['type'] == "image/pjpeg"){ 

move_uploaded_file($_FILES['img_exterior']['tmp_name'], "images/".$_FILES['img_exterior']['name']) 

    or die ("Could not copy"); }

else { 

 

            echo "Could Not Copy, Wrong Filetype (".$_FILES['img_exterior']['name'].")"; 

 

        } 

//} 

//interior upload

if ($_FILES['img_interior']['type'] == "image/gif" or $_FILES['img_interior']['type'] == "image/pjpeg"){ 

move_uploaded_file($_FILES['img_interior']['tmp_name'], "images/".$_FILES['img_interior']['name']) 

    or die ("Could not copy"); }

else { 

 

            echo "Could Not Copy, Wrong Filetype (".$_FILES['img_interior']['name'].")"; 

 

        } 

//} 

if ($_FILES['img_cockpit']['type'] == "image/gif" or $_FILES['img_cockpit']['type'] == "image/pjpeg"){ 

move_uploaded_file($_FILES['img_cockpit']['tmp_name'], "images/".$_FILES['img_cockpit']['name']) 

    or die ("Could not copy"); }

else { 

 

            echo "Could Not Copy, Wrong Filetype (".$_FILES['img_cockpit']['name'].")"; 

 

        } 

 

/*

$sql = 'UPDATE ac_description SET

    description_order = '''. $description_order . ''',

        actype_ID = ''' . $typeID . ''',

        ac_name = ''' . $ac_name . ''',

        serial_num = ''' . $serial_num . ''',

registration_num = ''' . $registration_num . ''',

        L_engine = ''' . $L_engine . ''',

        R_engine = ''' . $R_engine . ''',

L_propeller = ''' . $L_propeller . ''',

        R_propeller = ''' . $R_propeller . ''',

C_propeller = ''' . $C_propeller . ''',

interior = ''' . $interior . ''',

        exterior = ''' . $exterior . ''',

optional_equip = ''' . $optional_equip . ''',

avionics = ''' . $avionics . ''',

img_exterior = ''' . $_FILES['img_exterior']['name'] . ''', 

        img_interior = ''' . $_FILES['img_interior']['name'] . ''',

img_cockpit = ''' . $_FILES['img_cockpit']['name'] . ''',

WHERE ID = "$ac_desc_ID"';

*/ 

$sql = " 

            UPDATE 

                ac_description 

            SET 

                description_order     = '$description_order', 

                actype_ID             = $typeID, 

                ac_name             = '$ac_name', 

                serial_num            = $serial_num, 

                registration_num     = $registration_num, 

                L_engine             = '$L_engine', 

                R_engine             = '$R_engine', 

                L_propeller         = '$L_propeller', 

                R_propeller         = '$R_propeller', 

                C_propeller         = '$C_propeller', 

                interior             = '$interior', 

                exterior             = '$exterior', 

                optional_equip        = '$optional_equip', 

                avionics             = '$avionics', 

                img_exterior         = '".$_FILES['img_exterior']['name']."', 

                img_interior         = '".$_FILES['img_interior']['name']."', 

                img_cockpit         = '".$_FILES['img_cockpit']['name']."', 

            WHERE 

                ID                    = $ac_desc_ID"; 

 

 

 

 

 

 

 

if(mysql_query($sql)) {

echo('The chapter has been edited');

}

else {

echo('error editing chapter:' . mysql_error());

}

}

?>

 

 

</body>

</html>


I'm getting the following error:



error editing chapter:You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ' registration_num = 87979,



any ideas what my syntax error might be??
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

Code: Select all

<?php
$sql = "UPDATE ac_description SET description_order='$description_order', actype_ID='$typeID', ac_name='$ac_name', serial_num='$serial_num', registration_num='$registration_num', L_engine='$L_engine',     R_engine='$R_engine', L_propeller='$L_propeller', R_propeller='$R_propeller', C_propeller='$C_propeller', interior='$interior', exterior='$exterior', optional_equip='$optional_equip', avionics='$avionics', img_exterior='".$_FILES['img_exterior']['name']."', img_interior='".$_FILES['img_interior']['name']."', img_cockpit='".$_FILES['img_cockpit']['name']."',WHERE ID='$ac_desc_ID'";
?>
Try that.
Post Reply