dodaaxx Posted April 16, 2010 Share Posted April 16, 2010 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 PHP Code: <?php $localhost="localhost"; $username="root"; $password=""; $database="e_cinema"; $linkid=mysql_connect($localhost,$username,$password); mysql_select_db($database) or die( "Unable to select database"); $query="SELECT MovieName,MovieID FROM movie"; $result = mysql_query ($query); echo "<form name=MovieName method=post action='data.php'> <select MovieName=MovieName>Movie Name"; while($nt=mysql_fetch_array($result)){ echo "<option value=$nt[MovieID]>$nt[MovieName]</option>"; } echo "</select>";// Closing of list box echo " <input type=submit value=Submit name=button> </form>"; ?> data.php PHP Code: <?php $localhost="localhost"; $username="root"; $password=""; $database="e_cinema"; $linkid=mysql_connect($localhost,$username,$password); mysql_select_db($database) or die( "Unable to select database"); if(isset($_POST['button'])) { $MovieName= isset($_POST['MovieName']); $query = "SELECT * FROM movie WHERE MovieName= $MovieName"; $result = mysql_query($query) or die(mysql_error()); echo "<table border='1'>"; echo "<tr> <th>MovieID</th> <th>MovieName</th> <th>MovieRating</th> <th>Category</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr><td>"; echo $row['MovieID']; echo "</td><td>"; echo $row['MovieName']; echo "</td><td>"; echo $row['MovieRating']; echo "</td><td>"; echo $row['Category']; echo "</td></tr>"; } echo "</table>"; } else{ } ?> i dont know where is the wrong so can you plz help Link to comment https://forums.phpfreaks.com/topic/198805-drop-down-box-problem-using-mysql/ Share on other sites More sharing options...
TeddyKiller Posted April 16, 2010 Share Posted April 16, 2010 dropdown.php <?php $localhost = "localhost"; $username = "root"; $password = ""; $database = "e_cinema"; $linkid = mysql_connect($localhost,$username,$password); mysql_select_db($database) or die( "Unable to select database"); $query = "SELECT MovieName,MovieID FROM movie"; $result = mysql_query($query); echo '<form name="MovieName" method="post" action="data.php"> <select name="MovieName">Movie Name'; while($nt=mysql_fetch_array($result)) { echo '<option value='.$nt['MovieID'].'>'.$nt['MovieName'].'</option>'; } echo "</select>";// Closing of list box echo echo '<input type="submit" value="Submit" name="button"> </form>'; ?> data.php <?php $localhost = "localhost"; $username = "root"; $password = ""; $database = "e_cinema"; $linkid = mysql_connect($localhost,$username,$password); mysql_select_db($database) or die( "Unable to select database"); if(isset($_POST['button'])) { $MovieName = $_POST['MovieName']; $query = "SELECT * FROM movie WHERE MovieName='$MovieName'"; $result = mysql_query($query) or die(mysql_error()); echo '<table border="1"> <tr> <th>MovieID</th> <th>MovieName</th> <th>MovieRating</th> <th>Category</th> </tr>'; while($row = mysql_fetch_array($result)) { echo '<tr> <td>' . $row['MovieID'] . '</td> <td>' . $row['MovieName'] . '</td> <td>' . $row['MovieRating'] . '</td> <td>' . $row['Category'] . '</td> </tr>'; } echo "</table>"; } ?> Not much change, though I tidied it up. The problem was here.. <select MovieName=MovieName> It should be <select name=MovieName> Link to comment https://forums.phpfreaks.com/topic/198805-drop-down-box-problem-using-mysql/#findComment-1043407 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.