0

I'm having a problem creating a dropdown list and populating it with information from a database. When I display the page below I get this PHP code displayed in place of the drop down menu:
"
\n"; while ($row = mysqli_fetch_array($result)) { $str .= '' . $row . '
' . "\n"; } $str .= ''; echo $str ?>"

<html>
<head><link rel="stylesheet" type="text/css" href="styles.css" />
<title>Add A New Game to the Database</title</head>
<body>

<h3>Add A New Game to the Database</h3>

<form enctype="multipart/form-data" action="process_games.php" method="post">
<p><table border=0>
<TR>
<TD>Select A System</TD>
<TD>

<?php
  require_once ('mysqli_connect.php');

  $sql = "select systemid, systemName
           from systems
           order by systemName";

  $result = mysqli_query($dbc, $sql) or die( "Could not execute query: $query" );

  $str = "<SELECT NAME=systemid><BR>\n";
  while ($row = mysqli_fetch_array($result)) {
        $str .= '<OPTION VALUE=' .  $row['systemid'] . '>' . $row['systemName'] . '<BR>' . "\n";
  }
  $str .= '</SELECT>';

  echo $str
?>

</TD>
</TR>

<TR>
<TD>Select A Genre</TD>
<TD>

<?php
  require_once ('mysqli_connect.php');

  $sql = "select genreid, genre
           from genre
           order by genre";

  $result = mysqli_query($dbc, $sql) or die( "Could not execute query: $query" );

  $str = "<SELECT NAME=genreid><BR>\n";
  while ($row = mysqli_fetch_array($result)) {
        $str .= '<OPTION VALUE=' .  $row['genreid'] . '>' . $row['genre'] . '<BR>' . "\n";
  }
  $str .= '</SELECT>';

  echo $str
?>

</TD>
</TR>

<TR>
<TD>What is the condtion of the game?</TD>
<TD>

<?php
  require_once ('mysqli_connect.php');

  $sql = "select conditionid, condition_name
           from condition_tbl
           order by condition_name";

  $result = mysqli_query($dbc, $sql) or die( "Could not execute query: $query" );

  $str = "<SELECT NAME=conditionid><BR>\n";
  while ($row = mysqli_fetch_array($result)) {
        $str .= '<OPTION VALUE=' .  $row['conditionid'] . '>' . $row['condition_name'] . '<BR>' . "\n";
  }
  $str .= '</SELECT>';

  echo $str
?>

</TD>
</TR>

<input type="hidden" name="MAX_FILE_SIZE" value="1000000">

<TR>
<TR>
<TD>Game Title:</TD>
<TD><input type="text" name="product_name" size="41"></TD>
</TR>
<TR>
<TD>Product Quantity:</TD>
<TD><input type="text" name="quantity" size="41"></TD>
</TR>
<TR>
<TD>Product Price:</TD>
<TD><input type="text" name="price" size="41"></TD>
</TR>
<TR>
<TD>Upload game image: </TD>
<TD><input type="file" name="filename" size="41"></TD>
</TR>

</table>
<BR><BR>
<input type="submit" value="Submit">
</form>

</body>
</html>
4
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by qualitybrains
0

Seems to be a simple mistake :

Add </option> at line 50 and 75 :)

Vivi
First, solve the problem. Then write the code.

Edited by qualitybrains: n/a

0

Yes at 50 & 75

$str .= '<OPTION VALUE=' .  $row['conditionid'] . '>' . $row['condition_name'] . '</OPTION>'.'<BR>' . "\n";

Edited by rajarajan07: n/a

0

it's still not working. now it says this:
Select A System "; while ($row = mysqli_fetch_array($result)) { $str .= '' . $row . ''.'
' . "\n"; } $str .= ""; echo $str ?>
Select A Genre
\n"; while ($row = mysqli_fetch_array($result)) { $str .= '' . $row . ''.'
' . "\n"; } $str .= ''; echo $str ?>
What is the condtion of the game?
\n"; while ($row = mysqli_fetch_array($result)) { $str .= '' . $row . ''.'
' . "\n"; } $str .= ''; echo $str ?>

I know the php works on other pages i've tried. it seems for some reason, the php is not working on this page.

updated code:

<html>
<head><link rel="stylesheet" type="text/css" href="styles.css" />
<title>Add A New Game to the Database</title</head>
<body>

<h3>Add A New Game to the Database</h3>

<form enctype="multipart/form-data" action="process_games.php" method="post">
<p><table border=0>
<TR>
<TD>Select A System</TD>
<TD>

<?php
  require_once ('mysqli_connect.php');

  $sql = "select systemid, systemName
           from systems
           order by systemName";

$str = "<select name='systemid'>";
while ($row = mysqli_fetch_array($result)) {
        $str .= '<OPTION VALUE=' .  $row['systemid'] . '>' . $row['systemName'] . '</OPTION>'.'<BR>' . "\n";
}
$str .= "</select>";


  echo $str
?>

</TD>
</TR>

<TR>
<TD>Select A Genre</TD>
<TD>

<?php
  require_once ('mysqli_connect.php');

  $sql = "select genreid, genre
           from genre
           order by genre";

  $result = mysqli_query($dbc, $sql) or die( "Could not execute query: $query" );

  $str = "<SELECT NAME=genreid><BR>\n";
  while ($row = mysqli_fetch_array($result)) {
        $str .= '<OPTION VALUE=' .  $row['genreid'] . '>' . $row['genre'] . '</OPTION>'.'<BR>' . "\n";
  }
  $str .= '</SELECT>';

  echo $str
?>

</TD>
</TR>

<TR>
<TD>What is the condtion of the game?</TD>
<TD>

<?php
  require_once ('mysqli_connect.php');

  $sql = "select conditionid, condition_name
           from condition_tbl
           order by condition_name";

  $result = mysqli_query($dbc, $sql) or die( "Could not execute query: $query" );

  $str = "<SELECT NAME=conditionid><BR>\n";
  while ($row = mysqli_fetch_array($result)) {
        $str .= '<OPTION VALUE=' .  $row['conditionid'] . '>' . $row['condition_name'] . '</OPTION>'.'<BR>' . "\n";
  }
  $str .= '</SELECT>';

  echo $str
?>

</TD>
</TR>

<input type="hidden" name="MAX_FILE_SIZE" value="1000000">

<TR>
<TR>
<TD>Game Title:</TD>
<TD><input type="text" name="product_name" size="41"></TD>
</TR>
<TR>
<TD>Product Quantity:</TD>
<TD><input type="text" name="quantity" size="41"></TD>
</TR>
<TR>
<TD>Product Price:</TD>
<TD><input type="text" name="price" size="41"></TD>
</TR>
<TR>
<TD>Upload game image: </TD>
<TD><input type="file" name="filename" size="41"></TD>
</TR>

</table>
<BR><BR>
<input type="submit" value="Submit">
</form>

</body>
</html>
0

Rename the file with a php extension (e.g. page.php). If you've already done this - are you sure that the server is running php?

0

Rename the file with a php extension (e.g. page.php). If you've already done this - are you sure that the server is running php?

Renaming it took care of the problem, thanks. Now two of the drop down menus work but the system one gives this error:

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in C:\Program Files\IndigoPerl\apache\htdocs\add_game.php on line 22

<html>
<head><link rel="stylesheet" type="text/css" href="styles.css" />
<title>Add A New Game to the Database</title</head>
<body>

<h3>Add A New Game to the Database</h3>

<form enctype="multipart/form-data" action="process_games.php" method="post">
<p><table border=0>
<TR>
<TD>Select A System</TD>
<TD>

<?php
  require_once ('mysqli_connect.php');

  $sql = "select systemid, systemName
           from systems
           order by systemName";

$str = "<select name='systemid'>";
while ($row = mysqli_fetch_array($result)) {
        $str .= '<OPTION VALUE=' .  $row['systemid'] . '>' . $row['systemName'] . '</OPTION>'.'<BR>' . "\n";
}
$str .= "</select>";


  echo $str
?>

</TD>
</TR>

<TR>
<TD>Select A Genre</TD>
<TD>

<?php
  require_once ('mysqli_connect.php');

  $sql = "select genreid, genre
           from genre
           order by genre";

  $result = mysqli_query($dbc, $sql) or die( "Could not execute query: $query" );

  $str = "<SELECT NAME=genreid><BR>\n";
  while ($row = mysqli_fetch_array($result)) {
        $str .= '<OPTION VALUE=' .  $row['genreid'] . '>' . $row['genre'] . '</OPTION>'.'<BR>' . "\n";
  }
  $str .= '</SELECT>';

  echo $str
?>

</TD>
</TR>

<TR>
<TD>What is the condtion of the game?</TD>
<TD>

<?php
  require_once ('mysqli_connect.php');

  $sql = "select conditionid, condition_name
           from condition_tbl
           order by condition_name";

  $result = mysqli_query($dbc, $sql) or die( "Could not execute query: $query" );

  $str = "<SELECT NAME=conditionid><BR>\n";
  while ($row = mysqli_fetch_array($result)) {
        $str .= '<OPTION VALUE=' .  $row['conditionid'] . '>' . $row['condition_name'] . '</OPTION>'.'<BR>' . "\n";
  }
  $str .= '</SELECT>';

  echo $str
?>

</TD>
</TR>

<input type="hidden" name="MAX_FILE_SIZE" value="1000000">

<TR>
<TR>
<TD>Game Title:</TD>
<TD><input type="text" name="product_name" size="41"></TD>
</TR>
<TR>
<TD>Product Quantity:</TD>
<TD><input type="text" name="quantity" size="41"></TD>
</TR>
<TR>
<TD>Product Price:</TD>
<TD><input type="text" name="price" size="41"></TD>
</TR>
<TR>
<TD>Upload game image: </TD>
<TD><input type="file" name="filename" size="41"></TD>
</TR>

</table>
<BR><BR>
<input type="submit" value="Submit">
</form>

</body>
</html>

Edited by gymangel812: n/a

0

on line 20 Add

$result = mysqli_query($dbc, $sql) or die( "Could not execute query: $query" );

You are using mysqli_fetch_array($result) on line 22 but $result is not defined when it is executed.

Edited by qualitybrains: n/a

This topic has been dead for over six months. 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.