Jump to content

[SOLVED] Small Database related problem


grahamb314

Recommended Posts

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

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  :)

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.

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();

}


?>

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>

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>";
}  

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.