0

I have error with this line

while($row = mysql_fetch_array($pregled)) in line 42

here is part of code that has problem, can anyone check this out? I need to fix this as soon as possible

thanks in advance

<p align="center"><font color="#0000FF">Pregled grupa</font></p>



<p align="center">Grupa kojoj koncert pripada: 



   <select name="grupa_select2" id="grupa_select2">
      <?php
    while($row = mysql_fetch_array($sql))
    {
    echo "<option>".$row['grupanaziv']."</option>";
    }
    ?>
    </select>
 </p>

  <p align="center">
    <input type="submit" name="pregled_grupe" id="pregled_grupe" value="- Izaberi grupu-" />
  </p>
  <p>
    <label></label>
  </p>

  <?php
   if (isset($_POST['pregled_grupe']))  {
  $con = mysql_connect($hostname,$db_username,$db_password);
    if (!$con)
    {
        die('Could not connect: ' . mysql_error());
    }
    mysql_select_db($db_name, $con);
        $selektovanje = mysql_query("select id from grupe where grupanaziv = '".($grupa_select2)."'");
        $grupa_id = mysql_fetch_array($selektovanje);

  $pregled = mysql_query("select * from koncerti where grupa_id = ".$grupa_id['id']."");



        echo "Koncerti za izabranu grupu su: ";
    while($row = mysql_fetch_array($pregled))
  {

    echo "<br>".$row['koncertnaziv'];
    echo "<br>".$row['mesto'];
    echo "<br>".$row['datum'];
    echo "<br>".$row['karte'];
  }
  }


?>

Edited by filipgothic

3
Contributors
8
Replies
26
Views
3 Years
Discussion Span
Last Post by filipgothic
1

Hi, define the error you get on line 42 and add mysql_error() to this query and to the previous.

0

I added here

$pregled = mysql_query("select * from koncerti where grupa_id = ".$grupa_id['id']."");

   if (!mysql_query($pregled,$grupa_id,$selektovanje))
    {
        die('Error: ' . mysql_error());
    }

        echo "Koncerti za izabranu grupu su: ";
    while($row = mysql_fetch_array($pregled))

  {



    echo "<br>".$row['koncertnaziv'];
    echo "<br>".$row['mesto'];
    echo "<br>".$row['datum'];
    echo "<br>".$row['karte'];
  }
  }

and erors are

Warning: Wrong parameter count for mysql_query() in /home/a9752689/public_html/zadatak2/admin.php on line 237

whic is code I added

if (!mysql_query($pregled,$grupa_id,$selektovanje))

and

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

am not sure what is this

line 1 is <?php

Edited by filipgothic

1

Ok, mysql_query() accepts two parameters, the first is mandatory, the second is optional. This:

$pregled = mysql_query("select * from koncerti where grupa_id = ".$grupa_id['id']."");
if (!mysql_query($pregled,$grupa_id,$selektovanje))
{
    die('Error: ' . mysql_error());
}

Should be:

$pregled = mysql_query("select * from koncerti where grupa_id = ".$grupa_id['id']) or die(mysql_error());

Note that at the end of the query I removed the double quotes, that's the reason of the second error:

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

If you need quotes because the value to compare is a string then write:

$pregled = mysql_query("select * from koncerti where grupa_id = '" . $grupa_id['id'] . "'");

Spot the difference:

grupa_id = '" . $grupa_id['id'] . "'"

Instead of:

grupa_id = " . $grupa_id['id'] . ""
-1

Man this is what you are expected to write:
$pregled = mysql_query("select * from koncerti where grupa_id = ".$grupa_id['id']."") or die(myslq_error());

mysql_query takes only one argument. I mean I can't even understand how can you post such a thing here.

0

I guess 000webhost sux I tested on my server and here are erros, I changed grupa_select2 to just grupa_select because with 2 it was undefined var error

Notice: Undefined variable: grupa_select in D:\Programs\wamp\www\test\seminarski\zadatak2\admin.php on line 232

which is

    $selektovanje = mysql_query("select id from grupe where grupanaziv = '".($grupa_select)."'");

and

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in D:\Programs\wamp\www\test\seminarski\zadatak2\admin.php on line 240

 while($row = mysql_fetch_array($pregled))

Edited by filipgothic

1

It means $grupa_select (which was $grupa_select2 in your original script) is not defined.

0

I changed that to just grupa_select without 2

I defined it after

 if (isset($_POST['pregled_grupe']))  {
   $grupa_select = $_POST['grupa_select'];

it works now, I forgot to make $grupa_select

let me checks for more than 1 record how will be displayed

1

Fixed, thanks for help cereal, everything was in defining $grupa_select to
$grupa_select = $_POST['grupa_select'];

Solved

Edited by filipgothic

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.