p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 (http://p2p.wrox.com/forumdisplay.php?f=123)
-   -   chapter 6, page 173-175, error in sql syntax (http://p2p.wrox.com/showthread.php?t=13314)

vkranendonk May 23rd, 2004 05:52 AM

chapter 6, page 173-175, error in sql syntax
 
Hello,

On chapter 6, page 173-175 I get an error in my mysql syntax. I don't know whats wrong with it I have tried several things.

I hope somebody can help me.

This is the error that is displayed.

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 ') VALUES ( 'Vincent,' , '2002' , '3' , '3' ,

This is the text file:

<?php
//************************************************** ************************************************** ********
//commit add
//************************************************** ************************************************** ********
  $link = mysql_connect("localhost", "root", "kranendonk") or die(mysql_error());
  $select = mysql_select_db("wiley", $link) or die(mysql_error());
  switch( $_GET['action'] ){
    case "add":
  switch( $_GET['type'] ){
    case "movie":
  $sql = "INSERT INTO
      `movie`
    ( `movie_name`,
      `movie_year`,
      `movie_type`,
        `movie_leadactor`,
      `movie_director`,)
      VALUES
    ( '".$_POST['movie_name'].",' ,
      '".$_POST['movie_year']."' ,
      '".$_POST['movie_type']."' ,
      '".$_POST['movie_leadactor']."' ,
      '".$_POST['movie_director']."' )
      ";
    break;
  }
    break;
}
if ( isset( $sql ) && !empty( $sql )){
  echo "<!-".$sql."->";
  $result = mysql_query( $sql ) or die(mysql_error());
?>
  <p align="center" style="color:#FF0000">
    Done. <a href="index.php">Index</a>
  </p>
<?php
  }
?>

If somebody could help me i will be verry happy.


richard.york May 24th, 2004 06:08 PM

The error is here

 ( 'Vincent,' , '2002' , '3' , '3' ,

You are missing two single quotes.

So it needs to be

 ( 'Vincent', '', '2002' , '3' , '3' ,

since your VALUES have to match the number of columns you specify.

HTH!




Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::

richard.york May 24th, 2004 06:10 PM

Oops I misread your code, actually you have one too many commas.. so it needs to be:

 ( 'Vincent', '2002' , '3' , '3' ,

Or in the context of your code:

Code:

      '".$_POST['movie_name']."',
      '".$_POST['movie_year']."',
      '".$_POST['movie_type']."',
      '".$_POST['movie_leadactor']."',
      '".$_POST['movie_director']."' )

HTH!

Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::

vkranendonk May 26th, 2004 12:30 PM

Heej, thanks for answering on my problem. But that wasn't the problem.

I had a "," to much in my mysql syntax.

      `movie`
    ( `movie_name` ,
      `movie_year` ,
      `movie_type` ,
        `movie_leadactor` ,
      `movie_director`, )

greetings, vincent kranendonk



All times are GMT -4. The time now is 04:17 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.