[SOLVED] update error

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
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

[SOLVED] update error

Post by C_Calav »

hi guys, back again.. sorry!

im just coding a update script and get the following errors..

my layout of my script goes like this

<php select from db ?>
<html put into text boxes>
<php post new feilds >

all this is in one script. here is the last part

Code: Select all

<?php

    $db = mysql_pconnect('xxx)or die ("Could not connect to database");

    mysql_select_db('models') or die ("Could not select database!"); 

        if ($_SERVER['REQUEST_METHOD'] == "POST") 
        {

	$ud_P_Stock = stripslashes($_POST["ud_P_Stock"]);
	$ud_P_Name = stripslashes($_POST["ud_P_Name"]);
 	$ud_P_Cat = stripslashes($_POST["ud_P_Cat"]);		
	$ud_P_Scale = stripslashes($_POST["ud_P_Scale"]);
	$ud_P_Length = stripslashes($_POST["ud_P_Length"]);	
	$ud_P_Span = stripslashes($_POST["ud_P_Span"]);
	$ud_P_Price = stripslashes($_POST["ud_P_Price"]);
	$ud_P_Desc = stripslashes($_POST["ud_P_Desc"]);
	

	$query = "UPDATE planes WHERE P_Stock='$ud_P_Stock' SET P_Name='$ud_P_Name',P_Cat='$ud_P_Cat',P_Scale='$ud_P_Scale',P_Length='$ud_P_Length',P_Span='$ud_P_Span',P_Price='$ud_P_Price',P_Desc='$ud_P_Desc'";

        #execute SQL statement
       $result = mysql_query($query, $db) or die (mysql_error()."<br />Couldn't execute query: $query");
	
	

	print "<br><b>aircraft updated</b><br><br>";
	echo"$P_Stock";
	}
	

?>

and heres the error:
You have an error in your SQL syntax near 'WHERE P_Stock='QQQ' SET P_Name='Crazy Joe',P_Cat='1st Flight',P_Scale='12',P_Len' at line 1
Couldn't execute query: UPDATE planes WHERE P_Stock='QQQ' SET P_Name='Crazy Joe',P_Cat='1st Flight',P_Scale='12',P_Length='50',P_Span='30',P_Price='350',P_Desc='Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test '
thanx for all your help!
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

The syntax is "UPDATE ... SET ... WHERE" not "UPDATE ... WHERE ... SET"
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

thanx silly mistake, a tutorial had it wrong too!

another post sovled.. :o
Post Reply