jes___per
03-01-2009, 09:42 PM
Hi
are working on a php site where u can make a SQL question
by choosing from different options from a php dropdown meny:
<b>Select:</b>
<select name="Select">
<option>Välj</option>
<option>Alla (*)</option>
<option>Förnamn</option>
<option>Efternamn</option>
<option>Adress</option>
<option>Telefon</option>
<option>E-post</option>
<option>Personnummer</option>
</select>
<b>From:</b>
<select name="From">
<option>Välj</option>
<option>DB</option>
<option>DB2</option>
</select>
<b>Where:</b>
<select name="Where">
<option>Välj</option>
<option>Alla (*)</option>
<option>Förnamn</option>
<option>Efternamn</option>
<option>Adress</option>
<option>Telefon</option>
<option>E-post</option>
<option>Personnummer</option>
</select>
<select name="Where2">
<option>Välj</option>
<option>=</option>
<option>></option>
<option><Less then</option>
<option>>=</option>
<option><=</option>
<option><></option>
<option>LIKE</option>
</select>
<b>Optional:</b>
<input type="text" size="30" name="Optional"></br>
The php dokument:
<?php
mysql_connect("localhost", "admin", "") or die('Du är inte välkomen här!!!');
mysql_select_db('test');
$Select=$_POST['Select'];
$From=$_POST['From'];
$Where=$_POST['Where'];
$Where2=$_POST['Where2'];
$Optional=$_POST['Optional'];
if ($Select==$_POST['Select'] && $From=$_POST['From'] && $Where=$_POST['Where'] && $Where2=$_POST['Where2'] && $Optional=$_POST['Optional'])
{
echo "Data ur databas $From med följande SQL kod:", "</p>";
echo "<b>Select</b> $Select <b>From</b> $From <b>Where</b> $Where <b>Where2</b> $Where2 <b>Optional</b> $Optional";
// Make a MySQL Connection
$query = "SELECT $Select FROM $From WHERE $Where$Where2 '$Optional'";
$result = mysql_query($query) or die(mysql_error());
echo "<table border =1> </br>";
echo "<tr>
<th>$Select</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>".
"<td>".$row[$Select]."</td>".
"</tr>";
}
echo "</table>";
}
else
{
echo "...";
}
?>
but i cant get it to work the problom starts when it are defining the where question, do any1 have any idée what the problom is and have a solution to it?
are working on a php site where u can make a SQL question
by choosing from different options from a php dropdown meny:
<b>Select:</b>
<select name="Select">
<option>Välj</option>
<option>Alla (*)</option>
<option>Förnamn</option>
<option>Efternamn</option>
<option>Adress</option>
<option>Telefon</option>
<option>E-post</option>
<option>Personnummer</option>
</select>
<b>From:</b>
<select name="From">
<option>Välj</option>
<option>DB</option>
<option>DB2</option>
</select>
<b>Where:</b>
<select name="Where">
<option>Välj</option>
<option>Alla (*)</option>
<option>Förnamn</option>
<option>Efternamn</option>
<option>Adress</option>
<option>Telefon</option>
<option>E-post</option>
<option>Personnummer</option>
</select>
<select name="Where2">
<option>Välj</option>
<option>=</option>
<option>></option>
<option><Less then</option>
<option>>=</option>
<option><=</option>
<option><></option>
<option>LIKE</option>
</select>
<b>Optional:</b>
<input type="text" size="30" name="Optional"></br>
The php dokument:
<?php
mysql_connect("localhost", "admin", "") or die('Du är inte välkomen här!!!');
mysql_select_db('test');
$Select=$_POST['Select'];
$From=$_POST['From'];
$Where=$_POST['Where'];
$Where2=$_POST['Where2'];
$Optional=$_POST['Optional'];
if ($Select==$_POST['Select'] && $From=$_POST['From'] && $Where=$_POST['Where'] && $Where2=$_POST['Where2'] && $Optional=$_POST['Optional'])
{
echo "Data ur databas $From med följande SQL kod:", "</p>";
echo "<b>Select</b> $Select <b>From</b> $From <b>Where</b> $Where <b>Where2</b> $Where2 <b>Optional</b> $Optional";
// Make a MySQL Connection
$query = "SELECT $Select FROM $From WHERE $Where$Where2 '$Optional'";
$result = mysql_query($query) or die(mysql_error());
echo "<table border =1> </br>";
echo "<tr>
<th>$Select</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>".
"<td>".$row[$Select]."</td>".
"</tr>";
}
echo "</table>";
}
else
{
echo "...";
}
?>
but i cant get it to work the problom starts when it are defining the where question, do any1 have any idée what the problom is and have a solution to it?