Schrijven van SQL-query's niet mogelijk
Ik hem een probleempje ik wil graag via een SQL-query schrijven naar een mysql server. Nu heb ik het schript wel gevonden maar het werkt niet.
Ik krijg geen fout melding maar het lijkt er op dat er gewoon niets word uitgevoerd. Maar als ik bijvoorbeeld een verzoek vraag van "SHOW DATABASES" dan geeft hij niet weer. Weet iemand wat ik fout doe?
Ik heb het schript hieronder geplaatst:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<!-- Program Name: mysql_send.php
Description: PHP program that sends an SQL query to the
MySQL server and displays the results.
-->
<html>
<head>
<title>SQL Query Sender</title>
</head>
<body>
<?php
$user="xxxxxxxxxxxxx";
$host="localhost";
$password="xxxxxxxxxxxx";
/* Section that executes query */
if (@$form == "yes")
{
mysql_connect($host,$user,$password);
mysql_select_db($database);
$query = stripSlashes($query) ;
$result = mysql_query($query);
echo "Database Selected: <b>$database</b><br>
Query: <b>$query</b>
<h3>Results</h3>
<hr>";
if ($result == 0)
echo("<b>Error " . mysql_errno() . ": " . mysql_error() . "</b>");
elseif (@mysql_num_rows($result) == 0)
echo("<b>Query completed. No results returned.</b><br>");
else
{
echo "<table border='1'>
<thead>
<tr>";
for ($i = 0; $i < mysql_num_fields($result); $i++)
{
echo("<th>" . mysql_field_name($result,$i) . "</th>");
}
echo " </tr>
</thead>
<tbody>";
for ($i = 0; $i < mysql_num_rows($result); $i++)
{
echo "<tr>";
$row = mysql_fetch_row($result);
for ($j = 0; $j < mysql_num_fields($result); $j++)
{
echo("<td>" . $row[$j] . "</td>");
}
echo "</tr>";
}
echo "</tbody>
</table>";
}
echo "<hr><br>
<form action=$PHP_SELF method=post>
<input type=hidden name=query value=\"$query\">
<input type=hidden name=database value=$database>
<input type=submit name=\"queryButton\" value=\"New Query\">
<input type=submit name=\"queryButton\" value=\"Edit Query\">
</form>";
unset($form);
exit();
}
/* Section that requests user input of query */
@$query = stripSlashes($query);
if (@$queryButton != "Edit Query")
{
$database = " ";
$query = " ";
}
?>
<form action=<?php echo $PHP_SELF ?>?form=yes method="post">
<table>
<tr>
<td align="right"><b>Type in database name</b></td>
<td>
<input type=text name="database" value=<?php echo $database ?> >
</td>
</tr>
<tr>
<td align="right" valign="top"><b>Type in SQL query</b></td>
<td><textarea name="query" cols="60" rows="10"><?php echo $query ?></textarea>
</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Submit Query"></td>
</tr>
</table>
</form>
</body>
</html>
Description: PHP program that sends an SQL query to the
MySQL server and displays the results.
-->
<html>
<head>
<title>SQL Query Sender</title>
</head>
<body>
<?php
$user="xxxxxxxxxxxxx";
$host="localhost";
$password="xxxxxxxxxxxx";
/* Section that executes query */
if (@$form == "yes")
{
mysql_connect($host,$user,$password);
mysql_select_db($database);
$query = stripSlashes($query) ;
$result = mysql_query($query);
echo "Database Selected: <b>$database</b><br>
Query: <b>$query</b>
<h3>Results</h3>
<hr>";
if ($result == 0)
echo("<b>Error " . mysql_errno() . ": " . mysql_error() . "</b>");
elseif (@mysql_num_rows($result) == 0)
echo("<b>Query completed. No results returned.</b><br>");
else
{
echo "<table border='1'>
<thead>
<tr>";
for ($i = 0; $i < mysql_num_fields($result); $i++)
{
echo("<th>" . mysql_field_name($result,$i) . "</th>");
}
echo " </tr>
</thead>
<tbody>";
for ($i = 0; $i < mysql_num_rows($result); $i++)
{
echo "<tr>";
$row = mysql_fetch_row($result);
for ($j = 0; $j < mysql_num_fields($result); $j++)
{
echo("<td>" . $row[$j] . "</td>");
}
echo "</tr>";
}
echo "</tbody>
</table>";
}
echo "<hr><br>
<form action=$PHP_SELF method=post>
<input type=hidden name=query value=\"$query\">
<input type=hidden name=database value=$database>
<input type=submit name=\"queryButton\" value=\"New Query\">
<input type=submit name=\"queryButton\" value=\"Edit Query\">
</form>";
unset($form);
exit();
}
/* Section that requests user input of query */
@$query = stripSlashes($query);
if (@$queryButton != "Edit Query")
{
$database = " ";
$query = " ";
}
?>
<form action=<?php echo $PHP_SELF ?>?form=yes method="post">
<table>
<tr>
<td align="right"><b>Type in database name</b></td>
<td>
<input type=text name="database" value=<?php echo $database ?> >
</td>
</tr>
<tr>
<td align="right" valign="top"><b>Type in SQL query</b></td>
<td><textarea name="query" cols="60" rows="10"><?php echo $query ?></textarea>
</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Submit Query"></td>
</tr>
</table>
</form>
</body>
</html>
Gewijzigd op 01/01/1970 01:00:00 door Paul
Volgens mij krijg je dan te zien dat $query nooit gemaakt is, of ben je vergeten om die in dit script te zetten?
Maar in ieder geval bedankt.
Code (php)
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
<?php
if (!($res = mysql_query ($sql))) {
trigger_error (mysql_error ());
}
else {
while ($row = mysql_fetch_assoc ($res)) {
// hier je resultaten echoën
}
}
?>
if (!($res = mysql_query ($sql))) {
trigger_error (mysql_error ());
}
else {
while ($row = mysql_fetch_assoc ($res)) {
// hier je resultaten echoën
}
}
?>
Je gebruikt geen $_POST en geen $_GET om je vars op te halen.