I have an SQL-database with many tables. Now I would like to create an input-form to be able to get data into the db without writing the entire sql-code every time. And this should work as follows:
All table names are listed in a drop-down menu. After having selected a table name, a new table with 4 columns is created automatically:
The first column of this table simply contains an increasing number.
The second column contains the field-names of the selected table.
In the third column there are empty input fields to enter the values for the database. Only in the third line (=product name) there is a drop-down menu with all product names from the main-table of the db.
The fourth column contains the data type (e.g. int or varchar)
All tables in the database have the same structure in the first 3 columns: the first column contains the table-id, the second column the foreign-key (=master_id) and the third column the product_name.
Up to this point, the script works well with the following 2 php-files (javasql.php and getuser.php):
javasql.php:
enter code here
<!DOCTYPE html>
<html>
<head>
<script>
function showUser(str) {
if (str=="") {
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (this.readyState==4 && this.status==200) {
document.getElementById("txtHint").innerHTML=this.responseText;
}
}
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form>
<select name="users" onchange="showUser(this.value)">
<option value="" class="optdrugs">please select</option>
<?php
include("files/zugriff.inc.php"); // database Access
$sql = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE
TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA = 'product'";
$result = mysqli_query($db, $sql);
while ($row = mysqli_fetch_assoc($result)) {
echo '<option class="optdrugs" value="'. $row['TABLE_NAME'] . '">' .
$row['TABLE_NAME']. '</option>';
echo '<br>';
}
?>
</select>
</form>
<br>
<div id="txtHint"><b>Bitte Tabelle auswählen:</b>
<br>
<?php
if (isset($_POST["submit"])) {
$sent = $_POST['sent'];
$q = $_POST['tablename'];
$column_passed = unserialize($_POST['column']); // content of array
$column is passed from getuser.php
foreach ($_POST["insertvalue"] as $key => $value) {
echo $value . "<br>";
$werte[] = "'$value'";
}
$sql="INSERT INTO $q ($column_passed) VALUES (" .
implode(", ", $werte) . ")"; // data entry
mysqli_query($db, $sql);
if (mysqli_affected_rows($db) > 0) {
echo "<h3 style='color:blue'>successful</h3>";
} else {
echo "<h3 style='color:red'>not
successful</h3>";
}
}
?>
</div>
</body>
</html>
enter code here
getuser.php:
<!DOCTYPE html>
<html>
<head>
<style>
table {
width: 100%;
border-collapse: collapse;
}
table, td, th {
border: 1px solid black;
padding: 5px;
}
th {text-align: left;}
</style>
</head>
<body>
<form id="formdatabase" name="formdatabase" action="javasql.php"
method="post">
<input type="hidden" name="sent" value="yes">
<?php
$q = strval($_GET['q']);
$con = mysqli_connect('localhost','root','','product');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"ajax_demo");
$sql="SELECT * FROM $q";
$result = mysqli_query($con,$sql);
$numcols = mysqli_num_fields($result); // gets number of columns in result table
$field = mysqli_fetch_fields($result); // gets the column names from the result table
$data_type_array = array(
1=>'tinyint',
2=>'smallint',
3=>'int',
4=>'float',
5=>'double',
7=>'timestamp',
8=>'bigint',
9=>'mediumint',
10=>'date',
11=>'time',
12=>'datetime',
13=>'year',
16=>'bit',
252=>'text',
253=>'varchar',
254=>'char',
246=>'decimal'
);
$data_type_array = array_flip($data_type_array);
echo "<table>";
echo "<tr>";
echo "<th>" . 'Nr' . "</th><th>" . 'Column names' . "</th>
<th>" . 'Values for db-entry' . "</th><th>" . 'Type' . "</th>";
echo "</tr>";
echo "<tr>";
$nr = 1;
for($x=0;$x<$numcols;$x++):?>
<td><?= $nr; ?></td>
<td><?= $field[$x]->name; ?></td>
<?= $column[] = $field[$x]->name; ?>
<td>
<?php
if ($field[$x]->name == 'Name') { // if-Beginn
?>
<select name="insertvalue[<?= $x; ?>]" id="insertvalue<?=
$x; ?>" size="1" onchange = "javascript:getSelectedRow()">
<?php
include("files/zugriff.inc.php");
$sql = "SELECT * FROM product_main ORDER BY Name";
$result = mysqli_query($db, $sql);
while ($row = mysqli_fetch_assoc($result)) {
echo '<option class="optdrugs" value='. $row['Name'] . '>' .
$row['Name'] . '</option>';
echo '<br>';
}
?>
</select>
<?php
$name_option = "";
} else {
$name_option = "<input type='text' id='insertvalue" . $x . "'
name='insertvalue[" . $x . "]' size='50'>";
echo $name_option;
}
?>
</td>
<?php
$key = array_search($field[$x]->type, $data_type_array);
if($key !== false){
echo "<td>" . $key . "</td>";
}else{
echo "<td>" . $field[$x]->type . "</td>";
}
?>
<td><?= $field[$x]->type; ?></td>
<?= $nr = $nr + 1; ?>
</tr>
<?php endfor;
echo "</table>";
mysqli_close($con);
?>
<input type="hidden" name="tablename" value="<?= $q; ?>">
<input type="hidden" name="column" value="<?php echo htmlentities
(serialize($column)); ?>">
<input type="submit" value="Enter values" name="submit">
</form>
</body>
</html>
Since I need the master_id (= foreign key) in addition to the product-name for database entry, I would like to extend my script, so that the respective master_id is automatically sent to the input field in line 2, when a product-name is selected in line 3 ... without clicking a button. I tried to do this with javascript but it didn´t work. As far as I know, the solution would be to use AJAX but unfortunately, I am not very used to AJAX.
I would be more than happy, if someone could help me to solve this problem!
Related
I'm making something for a stocktake.
I have a form that generates with 4 fields. item_code, item_name, packing, quantity
<form action="goods.php" method="post">
<table>
<!-- Headers -->
<tr>
<td><b>Item Code</b></td>
<td><b>Description</b></td>
<td><b>Packing</b></td>
<td><b>Quantity</b></td>
</tr>
<?php
for ($i = 0; $i <= 50; $i++) {
?>
<tr>
<td>
<INPUT TYPE="TEXT" NAME="item_code[<?php echo $i; ?>]" SIZE="6" VALUE="
<?php
if (!empty($_POST["item_code"][($i)])) {
echo $_POST["item_code"][($i)];
}
?>"></td>
<td><?php
if (!empty($_POST["item_code"][($i)])) {
$result = FetchData($_POST["item_code"][($i)]);
echo $result['category'];
}
?>
</td>
<td>
<?php
if (!empty($_POST["item_code"][($i)])) {
echo $result['item_name'];
}
?></td>
<td>
<?php
if (!empty($_POST["item_code"][($i)])) {
echo $result['packing'];
}
?></td>
<td><INPUT TYPE="TEXT" NAME="quantity[<?php echo $i; ?>]" SIZE="5" VALUE="
<?php
if (!empty($_POST["quantity"][($i)])) {
echo $_POST["quantity"][($i)];
} else {
echo "";
}
?>"></td>
A js function for the button
<script>
function fillForm(value) {
document.getElementById('value').innerHTML = value;
}
</script>
and a list that is generated with 3 fields. item_code, item_name, packing
<?php
$dbh = dbh_get();
$sql = 'SELECT * FROM goods as goods(item_code, sort) order by human_sort(goods.item_code)';
$v = array();
$stmt = $dbh->prepare($sql);
$stmt->execute();
while (true) {
$r = $stmt->fetch();
if (is_bool($r)) break;
print '
<tr>
<td class="buttonL" id="<php ' . $r['item_code'] . ' ?>" onclick="fillForm()">' . $r['item_code'] . '</td>
<td>' . $r['item_name'] . '</td>
<td>' . $r['packing'] . '</td>
</tr>' . "\n";
}
dbh_free($dbh);
?>
}
I want to put a button on each list row and when it's clicked it populates the first three fields in the form, leaving quantity to be filled out. Then when another is clicked it populates the next form row etc,. It's working fine manually entering from the list, but the list is nearly 5000 items so it's a hassle to keep searching then scrolling up and entering the values.
I don't see how to do this with PHP so I assume I need a javascript function, which is where I'm lost. Let me know if you need more info.
I'm having a hard time displaying the title and note on each row of my database. I want to display one row (with the title and note) after each
from a form in a page heading to the displaying of row datas page.
This is my code below:
//
Let's say that we have 4 rows of datas. In my code, I can only display the first row, because it keeps having the first row's data. This is because the form is in the first php file. Then after I submit the form, it's directed to this file, and it keeps getting the first row.
<?php $con=mysqli_connect("localhost","root","","task");?>
<?php $results = mysqli_query($con, "SELECT * FROM note"); ?>
<?php while ($row = mysqli_fetch_array($results)) { ?>
<?php
$id=$row['id'];
echo ' ';
echo '<button class="call_modal" data-id="$id" style="cursor:pointer;">'. $row['title'] . '</button>';
?>
<?php
}?>
<?php $results = mysqli_query($con, "SELECT * FROM note"); ?>
<?php while ($row = mysqli_fetch_array($results)) { ?>
<div class="note" data-id="<?= $row['id'] ?>">
<div class="modal">
<div class="modal_close close"></div>
<div class="modal_main">
<?php
echo '<br><br>';
echo '<div class="padding">'.$row['title'].'';
echo '<br><br><br><br>';
echo ''.$row['note'].'</div>';
?>
</div>
</div>
<?php
}?>
<?php
<?php
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
} ?>
The code below is not tested but it should be correct and give you a better idea of what you are doing right/wrong. I hope it helps..
<?php
$con=mysqli_connect("localhost","root","","task");
$results = mysqli_query($con, "SELECT * FROM note");
while ($row = mysqli_fetch_array($results)) { //starting your data row loop
$id=$row['id'];// you are creating a variable here but not using it two lines down.
echo ' ';
//YOUR OLD CODE echo '<button class="call_modal" data-id="$id" style="cursor:pointer;">'. $row['title'] . '</button>';
echo '<button class="call_modal" data-id="$id" style="cursor:pointer;">'. $id . '</button>';// use the variable "$id" that you created here
// You dont need the next two lines, you already did a query and have the data loaded in the "$results" array
/* $results = mysqli_query($con, "SELECT * FROM note");
while ($row = mysqli_fetch_array($results)) */
?> // close the php tag if you are going to switch to html instead of "echoing html"
/* OLD CODE <div class="note" data-id="<?= $row['id'] ?>"> you were missing the "php" in the php tags */
<div class="note" data-id="<?php echo $id; ?>"> // corrected code
<div class="modal">
<div class="modal_close close"></div>
<div class="modal_main">
<?php //switching back to php so create your open tag again...
echo '<br><br>';
echo '<div class="padding">'.$row['title'].'';
echo '<br><br><br><br>';
echo ''.$row['note'].'</div>';// you dont NEED the '' before .$row.... unless you want it but its just essentially a blank string
?>
</div>
</div>
<?php
} // ending your "for each data row" here
?>
<?php
// PS you're not using this function anywhere unless its in ommited code?
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
} ?>
In your loop you're using mysqli_fetch_array, which returns an array with each element in that array containing the field value.
What you want is mysqli_fetch_assoc instead, this will return a hash which you can then use the way you're using it now.
Another thing is that you don't need to have 2 loops in there querying the database. And please indent your code, it makes it really hard for you and everyone else to read it.
Here is the updated/cleaned up version of your code. This has been tested, you can find a sample code with instructions to run on my Github here.
<?php
$con = mysqli_connect("localhost", "root", "", "task");
$results = mysqli_query($con, "SELECT * FROM note");
while ($row = mysqli_fetch_assoc($results)) {
$id = $row['id'];
echo ' ';
echo '<button class="call_modal" data-id="' . $id . '" style="cursor:pointer;">'. $row['title'] . '</button>';
?>
<div class="note" data-id="<?= $row['id'] ?>">
<div class="modal">
<div class="modal_close close"></div>
<div class="modal_main">
<?php
echo '<br /><br />';
echo '<div class="padding">' . $row['title'];
echo '<br /><br /><br /><br />';
echo $row['note'];
echo '</div>'
?>
</div>
</div>
</div>
</div>
<?php
}
?>
<?php
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
Here is the function I am working on. I need to get the selected option which is inside a while loop.
Every time I am trying to get the selected value through select id, it's only getting the last selected value for the rest of the row.
Please help me. How can I get and store the full table data?
function generate_schedule($con,$sy,$year_id){
$time = array(1=>'9:30-11:00',2=>'11:30-1:00',3=>'1:30-3:00',4=>'3:15-4:45');
$days = array(1=>'Sunday',2=>'Monday',3=>'Tuesday',4=>'Wednesday',5=>'Thursday',6=>'Friday',7=>'Saturday');
$rooms=array(1=>'302',2=>'303',3=>'304',4=>'701',5=>'702',6=>'704',7=>'901',8=>'902',9=>'1402',10=>'1405');
$yls=mysqli_query($con,"SELECT * FROM year_level_subject as yls join subjects as s on yls.subj_id=s.subj_id where yls.year_id='$year_id'");
$num=mysqli_num_rows($yls);
$x = 0;
echo '<table class="table table-bordered table-hover" id=" datatable">';
echo '<thead><tr><th>Time</th><th>Days</th><th>Subject</th><th>Teacher</th><th>Room</th></tr></thead>';
while($row=mysqli_fetch_assoc($yls)){
extract($row);
echo '<tr>';
echo '<td><select id ="seltime" ><option value=0>Select Time</option>';
foreach($time as $key => $value) {
echo '<option value='.$key.'>';
echo $value .'</option>';
}
echo '</select></td>';
echo '<td><select class="selday" ><option value=0>Select Day</option>';
foreach($days as $key => $value) {
echo '<option value='.$key.'>';
echo $value .'</option>';
}
echo '</select></td>';
echo '<td>'.$subj_desc.'</td>';
$teach = mysqli_query($con,"SELECT * FROM teachers");
echo '<td><select id="selteacher" onchange="schedata(this)"><option value=0>Select Teacher</option>';
while($row=mysqli_fetch_assoc($teach)){
extract($row);
echo '<option value='.$teach_id.'>'.$teach_fname.' '.$teach_mname.' '.$teach_lname.'</option>';
}
echo '</select></td>';
echo '</select></td>';
echo '<td><select name ="selroom" ><option value=0>Select Room</option>';
foreach($rooms as $key => $value) {
echo '<option value='.$key.'>';
echo $value .'</option>';
}
echo '</select></td>';
echo '</tr>';
}
echo '</table>';
}
you did't give the name atribute to your select element
echo '<td><select id="selteacher" onchange="schedata(this)" >
give a name for this as
echo '<td><select id="selteacher" name="selteacher" onchange="schedata(this)" >
I am trying to delete the entry in php and redirect the page in php.
I need to redirect the page based on condition as header("Location: report2.php?region=$region"); after deletion page doesnt get redirected to header("Location: report2.php?region=$region");
It doesnt delete also. It only redirects to report2.php?delete_id=103
Here is the code
?php
//Give your mysql username password and database name
include_once "db.php";
if(isset($_REQUEST['region']))
{
$region=$_REQUEST['region'];
//connection to the database
$qresult = mysql_query("SELECT * FROM registration where region='".$region."'");
echo "<h1>Registration Details of $region Region.</h1>";
if (mysql_num_rows($qresult) == 0) {
echo "<h3 style=color:#0000cc;text-align:center;>No Registrations Done..!</h3>";
} else {
echo "<table border='1' cellpadding='0' cellspacing='0' class='reports'>";
echo "<tr>" .
"<td style='background: #f1f1f1; font-weight: bold;text-align:center;'>Registration Number</td>" .
"<td style='background: #f1f1f1; font-weight: bold;text-align:center;'>Name</td>" .
"</tr>";
while($row = mysql_fetch_assoc($qresult)) {
echo "<tr>" .
"<td style=text-align:center;>" . $row['id'] . "</td>" .
"<td style=text-align:center;>". $row['name'] . "</td>";
?>
<td><img src="images/delete21.png" alt="Delete" /></td>
</tr>
<?php
}
}}
?>
</table>
<?php
if(isset($_GET['delete_id']))
{
$sql_query="DELETE FROM registration WHERE id=".$_GET['delete_id'];
mysql_query($sql_query);
header("Location: report2.php?region=$region");
exit;
}
?>
I think your problem is based on bad formatting, therefore you didn't notice that your if doesn't close before the next if-statement, which I don't think you intended.
Here is your fixed and formatted code:
<?php
include_once "db.php";
if(isset($_REQUEST['region']))
{
$region=$_REQUEST['region'];
$sql_query="SELECT * FROM registration where region='".$region."' ";
$result_set=mysql_query($sql_query);
}
if(isset($_GET['delete_id']))
{
$sql_query="SELECT * FROM registration where id='".$_GET['delete_id']."' ";
$result=mysql_query($sql_query);
while($row = mysql_fetch_assoc($result)) {
$region = $row['region'];
}
$sql_query="DELETE FROM registration WHERE id=".$_GET['delete_id'];
mysql_query($sql_query);
header("Location: report2.php?region=".$region);
exit;
}
?>
<script type="text/javascript">
function delete_id(id) {
if(confirm('Sure To Remove This Record ?')) {
window.location.href='report2.php?delete_id='+id;
}
}
</script>
I am trying to pass the value of a dynamically created JavaScript form (or pretty much just one select/option field of it) to another php file.
Here's the whole code of my request.php (which happens to use php, JavaScript and HTML):
<?php
include ("DbVerbindung.php");
?>
<!-- Verbindung zur Datenbank aufbauen -->
<?php
include "header.php";
?>
<!-- Kopfteil des Webfrontends holen -->
<!-- Hauptinhaltbereich -->
<div class="float">
<script>
<!-- dynamische Abfrage für Optionsfeld -->
function showUser(str) {
if (str=="") {
document.getElementById("gang").innerHTML="";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("gang").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getStudiengang.php?q="+str,true);
xmlhttp.send();
}
</script>
<h2>Daten des Wählers auswählen</h2>
<table id="auswahl">
<!-- Optionen zur Abfrage der Wählerdaten -->
<form action="speichern.php" method="POST">
<tr>
<td>Fachbereich:</td>
<td id="fachbereich">
<select size="1" maxlength="20" name="fachbereich" onChange="showUser(this.value)">
<option>Fachbereich auswählen</option>
<?php $sql = "SELECT * FROM bereich";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
echo '<option value="' . $row[0] . '">' . $row[1] . '</option>';
}
?>
</select>
</tr>
<tr>
<td>Studiengang:</td>
<td id="gang"></td>
</tr>
<tr>
<td>Geschlecht:</td>
<td id="geschlecht">
<select size="1" maxlength="20" name="geschlecht">
<?php $sql = "SELECT * FROM geschlecht";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
echo '<option value="' . $row[0] . '">' . $row[1] . '</option>';
}
?>
</select></td>
</tr>
<tr>
<td>Name:</td>
<td id="name"><select size="1" maxlength="30" name="name" onClick="getName.p"</td>
</tr>
<tr>
<td>Wahllokal:</td>
<td id="lokal">
<select size="1" maxlength="50" name="lokal">
<?php $sql = "SELECT * FROM lokal";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
echo '<option value="' . $row[0] . '">' . $row[1] . '</option>';
}
?>
</select></td>
</tr>
<tr>
<td id="submit">
<input type="submit" name="waehlt" value="Wähler wählt..!">
</td>
</tr>
</form>
</table>
</div>
<?php
include "footer.php";
?>
The JS script uses yet another php file -> getStudiengang.php. Here's its code:
<?php
$q = intval($_GET['q']);
include ("DbVerbindung.php");
$sql = "SELECT * FROM studiengang WHERE fs_b = '" . $q . "'";
$result = mysql_query($sql);
echo "<select size='1' name='studiengang'>";
while ($row = mysql_fetch_array($result)) {
echo '<option value="' . $row[0] . '">' . $row[1] . '</option>';
}
echo "</select">;
?>
And last but not least, the php the values should get passed to (speichern.php):
if ($_POST[waehlt]) {
$uhrzeit = date('G:i:s');
echo "Wähler tritt seine Wahl an. Uhrzeit: $uhrzeit<br>";
echo "Übergebene Daten:<br>";
echo "Fachbereich: ";
$sql = "SELECT * FROM bereich where b_id = '" . $_POST[fachbereich] . "'";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
echo "$row[1]<br>";
}
echo "Studiengang: ";
echo $_POST['studiengang'];
/*$sql = "SELECT * FROM studiengang where s_id = '" . $_POST[studiengang] . "'";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
echo "$row[1]<br>";
}
*/
echo "Geschlecht: ";
$sql = "SELECT * FROM geschlecht where g_id = '" . $_POST[geschlecht] . "'";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
echo "$row[1]<br>";
}
echo "Wahllokal: ";
$sql = "SELECT * FROM lokal where l_id = '" . $_POST[lokal] . "'";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
echo "$row[1]<br>";
}
}
Note that all variables except the 'studiengang' variable (which happens to be dynamically generated) gets passed and displayed just fine.
Any help will be appreciated!
You will need to use .appendChild so the browser understands that the item is added to the form. To make the fewest modifications to your code that should still work,
replace document.getElementById("gang").innerHTML=xmlhttp.responseText; with:
var gang = document.getElementById("gang");
while (gang.firstChild) {
gang.removeChild(gang.firstChild); //clear all elements
}
var div = document.createElement('div');
/*make a div to attach the response text to
if you didn't send the select in the responseText, you could createElement('select')*/
div.innerHTML = xmlhttp.responseText;
gang.appendChild(div); //attach the select
We finally resolved the issue.
For whatever reason it was necessary to 'hardcode' the select-box in HTML already and have it not created dynamically by Javascript.
Javascript now does only dynamically generate the option-fields within the section, this does in fact solve the issue.
Latest version with changes already applied:
JavaScript in request.php:
<script>
function showUser(str) {
if (str=="") {
document.getElementById("gang").innerHTML="";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("gang").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getStudiengang.php?q="+str,true);
xmlhttp.send();
}
</script>
Request.php (important piece of code):
<form action="save.php" method="POST">
<tr>
<td>Studiengang:</td>
<td>
<select id="gang" size="1" name="studiengang"></select>
</td>
</tr>
</form>
getStudiengang.php:
<?php
$q = intval($_GET['q']);
include ("DbVerbindung.php");
$sql = "SELECT * FROM studiengang WHERE fs_b = '" . $q . "'";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
echo '<option value="' . $row[0] . '">' . $row[1] . '</option>';
}
?>
Thanks for all the help. The answer given by serakfalcon has a good point and may be useful later on. It's not an requirement though.