grahamb314 Posted June 20, 2008 Share Posted June 20, 2008 Hi all! I'm new to PHP and have just started database interaction. I have done some code to accesss a database but keep getting the error below. Parse error: syntax error, unexpected T_STRING in [*url removed*] index.php on line 17 I have a database with a table called shows which has 2 fields; id and show. Here is the php: <?php require_once 'mysql_connect.php'; //This connects fine //Line 17 is below $DJshows = mysqli_query(mysqli link, "SELECT * FROM `shows`"); while ($show = mysqli_fetch_assoc($DJshows)) { echo "<option value="{$show['id']}">{$show['title']}</option>"; } ?> I's probably something simple! Cheers. Link to comment https://forums.phpfreaks.com/topic/111075-solved-small-database-related-problem/ Share on other sites More sharing options...
zenag Posted June 20, 2008 Share Posted June 20, 2008 $DJshows = mysqli_query(mysqli link, "SELECT * FROM 'shows' "); Link to comment https://forums.phpfreaks.com/topic/111075-solved-small-database-related-problem/#findComment-569993 Share on other sites More sharing options...
mmarif4u Posted June 20, 2008 Share Posted June 20, 2008 try this: echo "<option value=\"{$show['id']}\">{$show['title']}</option>"; Link to comment https://forums.phpfreaks.com/topic/111075-solved-small-database-related-problem/#findComment-569998 Share on other sites More sharing options...
grahamb314 Posted June 20, 2008 Author Share Posted June 20, 2008 Thanks for the help, there is still an error though: Parse error: syntax error, unexpected T_STRING in /[*URL REMOVED*] /index.php on line 18 Code: <?php require_once 'mysql_connect.php'; //BELOW IS LINE 18// $DJshows = mysqli_query(mysqli link, "SELECT * FROM 'shows' "); while ($show = mysqli_fetch_assoc($DJshows)) { echo "<option value=\"{$show['id']}\">{$show['title']}</option>";} ?> Thank again Link to comment https://forums.phpfreaks.com/topic/111075-solved-small-database-related-problem/#findComment-570057 Share on other sites More sharing options...
grahamb314 Posted June 20, 2008 Author Share Posted June 20, 2008 Should the code work? I don't see anything wrong with it really Maybe its some config stuff?? Any thoughts? ??? Link to comment https://forums.phpfreaks.com/topic/111075-solved-small-database-related-problem/#findComment-570081 Share on other sites More sharing options...
zenag Posted June 20, 2008 Share Posted June 20, 2008 $DJshows = mysqli_query(mysqli link, "SELECT * FROM 'shows' "); code should be ... $DJshows = mysqli_query(mysqli link, "SELECT * FROM shows ");remove single quotes for table name and try it.... Link to comment https://forums.phpfreaks.com/topic/111075-solved-small-database-related-problem/#findComment-570085 Share on other sites More sharing options...
grahamb314 Posted June 20, 2008 Author Share Posted June 20, 2008 Thanks, but still no luck Could it be something to do with "mysqli link" ?? Like I said, I'm new to PHP but am really enjoying it so far, yet im getting stuck on relativly simple concepts! Link to comment https://forums.phpfreaks.com/topic/111075-solved-small-database-related-problem/#findComment-570090 Share on other sites More sharing options...
DarkerAngel Posted June 20, 2008 Share Posted June 20, 2008 Well, my questions are 1. Where are you getting this mysqli link from (for one I don't understand why there's a space) 2. with the mysql_connect.php file, should you not be just using standard MySQL command functions <?php require_once 'mysql_connect.php'; //This connects fine //Line 17 is below $DJshows = mysql_query("SELECT * FROM `shows`"); while ($show = mysql_fetch_assoc($DJshows)) { echo "<option value="{$show['id']}">{$show['title']}</option>"; } ?> I would have to know whats in the mysql_connect.php to further assist. Link to comment https://forums.phpfreaks.com/topic/111075-solved-small-database-related-problem/#findComment-570098 Share on other sites More sharing options...
grahamb314 Posted June 20, 2008 Author Share Posted June 20, 2008 Thanks for the help, Here is the mysql_connect.php code (Login details changed for obvious reasons) <?php $mysqli = @mysqli_connect("HOST", "USERNAME", "PASSWORD", "TABLE"); if (mysqli_connect_errno()) { printf("Connection Failed: %s/n", mysqli_connect_error()); exit(); } ?> Link to comment https://forums.phpfreaks.com/topic/111075-solved-small-database-related-problem/#findComment-570100 Share on other sites More sharing options...
grahamb314 Posted June 20, 2008 Author Share Posted June 20, 2008 Sorry I mean Database instead of table! Link to comment https://forums.phpfreaks.com/topic/111075-solved-small-database-related-problem/#findComment-570107 Share on other sites More sharing options...
DarkerAngel Posted June 20, 2008 Share Posted June 20, 2008 $DJshows = mysqli_query($mysqli, "SELECT * FROM shows"); Link to comment https://forums.phpfreaks.com/topic/111075-solved-small-database-related-problem/#findComment-570117 Share on other sites More sharing options...
grahamb314 Posted June 20, 2008 Author Share Posted June 20, 2008 The works fine now, however there is still 1 confusing error left: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /[*URL REMOVED*]/index.php on line 21 <html> <head> <title>DJ Upload Form</title> </head> <body> <form action="selectfiles.php" method="POST"> <p align="center"> <p align="center"><strong><img src="Purple_Logo.jpg" width="300" height="113"></strong> <p align="center"><strong>DJ Upload Form</strong> <p align="center"><strong>Select your Show Name:</strong><br/> <select name="DJs[]" multiple="multiple"> <?php require_once 'mysql_connect.php'; //$DJshows = mysql_query("SELECT * FROM `shows`"); $DJshows = mysqli_query($mysqli, "SELECT * FROM shows"); while ($show = mysql_fetch_assoc($DJshows)) { echo "<option value=\"{$show['id']}\">{$show['title']}</option>"; } ?> </select> <p align="center"> <input type="submit" value="Next"/> </p> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/111075-solved-small-database-related-problem/#findComment-570229 Share on other sites More sharing options...
DarkerAngel Posted June 20, 2008 Share Posted June 20, 2008 while ($show = mysql_fetch_assoc($DJshows)) { echo "<option value=\"{$show['id']}\">{$show['title']}</option>"; } needs to be changed back to mysqli while ($show = mysqli_fetch_assoc($DJshows)) { echo "<option value=\"{$show['id']}\">{$show['title']}</option>"; } Link to comment https://forums.phpfreaks.com/topic/111075-solved-small-database-related-problem/#findComment-570241 Share on other sites More sharing options...
grahamb314 Posted June 20, 2008 Author Share Posted June 20, 2008 You guys are brillient! Is there a way to give you rep? :) Link to comment https://forums.phpfreaks.com/topic/111075-solved-small-database-related-problem/#findComment-570249 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.