473,386 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Drop down box problem using mysql

Hi all i'm newbie in this php and mysql coding
so can you plz help me

i'm using wamp server

and when i try to run the code there is an error pop up which say

PHP Code:
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 '' at line 1


here is my code

dropdown.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $localhost="localhost";
  3. $username="root";
  4. $password="";
  5. $database="e_cinema";
  6.  
  7. $linkid=mysql_connect($localhost,$username,$password);
  8. mysql_select_db($database) or die( "Unable to select database");
  9.  
  10. $query="SELECT MovieName,MovieID FROM movie";
  11. $result = mysql_query ($query);
  12.  
  13. echo "<form name=MovieName method=post action='data.php'> <select MovieName=MovieName>Movie Name";
  14. while($nt=mysql_fetch_array($result))
  15. {
  16.     echo "<option value=$nt[MovieID]>$nt[MovieName]</option>";
  17. } echo
  18.  
  19. "</select>";
  20. echo " <input type=submit value=Submit name=button> </form>"; 
  21. ?>

data.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $localhost="localhost";
  3. $username="root";
  4. $password="";
  5. $database="e_cinema";
  6.  
  7. $linkid=mysql_connect($localhost,$username,$password);
  8. mysql_select_db($database) or die( "Unable to select database");
  9.  
  10. if(isset($_POST['button']))
  11. {
  12.     $MovieName= isset($_POST['MovieName']);
  13.     $query = "SELECT * FROM movie WHERE MovieName= $MovieName";
  14.     $result = mysql_query($query) or die(mysql_error());
  15.  
  16.     echo "<table border='1'>";
  17.     echo "<tr> <th>MovieID</th> <th>MovieName</th> <th>MovieRating</th> <th>Category</th> </tr>";
  18.     while($row = mysql_fetch_array($result))
  19.     {
  20.         echo "<tr><td>";
  21.         echo $row['MovieID'];
  22.         echo "</td><td>";
  23.         echo $row['MovieName'];
  24.         echo "</td><td>";
  25.         echo $row['MovieRating'];
  26.         echo "</td><td>";
  27.         echo $row['Category'];
  28.         echo "</td></tr>";
  29.     } echo
  30.     "</table>";
  31. }
  32. else
  33. {
  34.  
  35. }
  36.  
  37. ?>


i dont know where is the wrong so can you plz help
Apr 16 '10 #1
1 1682
Atli
5,058 Expert 4TB
Hey.

and when i try to run the code there is an error pop
Which code produces the error, dropdown.php or the data.php?

A few things you should take a look at:
  • The "MovieName" select box in your dropdown code uses the ID of the movie as it's value, but in your data code you try to match it against the MovieName column in your database table. You should be matching it against the MovieID column.
  • The isset function is used to check whether a variable/element exists. Your usage of it on line #12 in your data.php code is incorrect. You should replace it with either mysql_real_escape_string (in cast it is text), or cast it to the appropriate type (int, for IDs).
  • It's not a good idea to verify that a form has been posted by checking a submit button. There are situations where a form can be submitted without it being used. Instead, verify that the POST data you are expecting exists; MovieName, in your case. (On line #10 in data.php)
Apr 16 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jonny Tango | last post by:
Hello everyone. Q. How do I create a dynamically-generated drop-down list for use in an array. I'm using PHP with a MySQL database (through phpMyAdmin) My database table is called...
1
by: jonnytansey2 | last post by:
Can anyone out there give me a pointer regarding creating a dynamically-generated drop-down list connected to an array? And is that question as clear as chocolate spread? Here's what I've got....
5
by: ashok893 | last post by:
I'm using two drop down list ina form. I have generated the first drop down list from MySQL database. When i select an option from first drop down list, i have to generate second drop down list...
0
by: tusaar | last post by:
Hi all I am in big need for a drop down menu created with php, mysql and ajax. Exactly, I need three drop down menu (Category, Subcategory and Item). The data of each drop down will come from...
2
by: ponyeyes | last post by:
Hi There, I am a bit of a newbie to PHP programming and I would like to know how I can place a selected drop down option into a PHP variable and then produce an sql query which incorporates this...
2
by: Boujii | last post by:
Greetings, I have been attempting to make a drop down menu of countries. From this menu I wish to create a variable in order to INPUT into mysql database. I have no trouble making the drop down menu,...
5
by: mramsay | last post by:
HI, I'm having alot of problems trying to figure out how to create drop down links from a hyperlink on my homepage. I have a hyperlink called Programs (this is for a community centre) When...
10
by: darkenroyce | last post by:
Hi Guys I am creating a sports database and one of the features involves create drop down dialogue boxes that retrieve data from MySQL tables and provides them as <option> within...
4
by: badvoc | last post by:
Sorry about the title wasn't sure how to describe my issue in short form. My problem is this. I have a dropdown box that is populated from a mySQL database. The reason for this is there are a...
1
by: student2008 | last post by:
Sorry about the title its a tricky one. I have a form which allows me to add a question and answers into a mysql database via a combination of, if a certain option is chosen and the reset button...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.