Jump to content

MySQL server version for the right syntax to use near 'AND comics.comic_conditio


Recommended Posts

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 'AND comics.comic_condition = 'new'' at line 20

 

is the new error message that I am getting.

 

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

<head>

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

<title>Comic Collectables - Search Results</title>

<link rel="stylesheet" href="mystyles.css" media="screen" type="text/css" />

</head>

<body>

<h1>Comic Collectables - Search Results</h1>

<?

// Check that the form has been submitted

if ($_POST) {

 

// Store the form data in variables

  $form_series_name =    $_POST['series_name'];

  $form_comic_issue =    $_POST['comic_issue'];

  $form_comic_condition = $_POST['comic_condition'];

 

// Trim any trailing and leading spaces from the form data

  $form_comic_issue =    trim('$form_comic_issue');Line 20

 

// Open a connection to the database

$link = mysqli_connect('localhost', 'student', 'mmst12009', 'assignment3');

 

// Define an SQL query to retrieve the comic records

$query = "

  SELECT

 

    comics.comic_id,

series.series_name,

    comics.comic_issue,

    comics.comic_condition,

    comics.comic_price

 

  FROM

 

    comics,

    series

 

  WHERE

 

    (comics.series_id = series.series_id)

 

  ORDER BY

 

    comics.comic_id ASC ";

 

 

// Restrict the SQL query with an AND clause if a

// comic issue has been supplied

if ($form_comic_issue != "")

 

{

$query .= "AND comics.comic_issue = '$form_comic_issue' ";

}

// Restrict the SQL query with an AND clause if a

// comic condition has been supplied

if ($form_comic_condition != "")

 

{

$query .= "AND comics.comic_condition = '$form_comic_condition' ";

}

// Run the query and store the result

$result = mysqli_query($link, $query)or die(mysqli_error($link));

 

// Get the number of rows in the result set

$number_of_rows = mysqli_num_rows($result);

 

// Close the connection to the database

mysqli_close($link);

 

// Display a message if no records have been retrieved

if ($number_of_rows == 0) {

  echo <<<END

<p>There are no records in the database.</p>

END;

}

else {

 

  // Display the head of the table

  echo <<<END

  <p>Search results are presented below.</p>

  <table border="0">

    <tr>

      <th>ID Number</th>

      <th>Series</th>

      <th>Issue</th>

      <th>Condition</th>

      <th>Price</th>

    </tr>

END;

 

  // Assign each record in the result to an array

  while ($row = mysqli_fetch_array($result))

  {

 

    // Assign each array element to a variable

    $comic_id =        $row['comic_id'];

    $series_name =    $row['series_name'];

    $comic_issue =    $row['comic_issue'];

    $comic_condition = $row['comic_condition'];

    $comic_price =    $row['comic_price'];

 

 

    // Display each record in a separate row of the table

    echo <<<END

    <tr>

      <td>$comic_id</td>

      <td>$series_name</td>

      <td>$comic_issue</td>

      <td>$comic_condition</td>

      <td>$$comic_price</td>

    </tr>

END;

    }

  echo "</table>";

  }

}

?>

</body>

</html>

 

Cheers,

Greeny

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.