PDA

View Full Version : make a query with the value of text



guif
08-12-2008, 12:59 PM
hi!

I have problems to give the value of a text.

I have in a PHP this:


<?php
$searchq = strip_tags($_GET['q']);
$getRecord_sql = 'select pkey from jiraissue where project = 10040 and pkey like "%'.$searchq.'%"';
$getRecord = mysql_query($getRecord_sql);
if(strlen($searchq)>0){
echo '<ul>';
while ($row = mysql_fetch_array($getRecord)) {
?>
<li><a href="lib/consultas.php?accion=E" onclick="load('lib/consultas.php?accion=E','consulta');return false;">

and in my file consultas.php, the case E:


case 'E':
$queEmp = "select pkey, created, UPDATED, reporter, assignee, summary, description from `jiraissue` where project = 10040 and pkey like ".$search-q2." ";
$resEmp = mysql_query($queEmp, $conexion) or die(mysql_error());
$totEmp = mysql_num_rows($resEmp);
if ($totEmp> 0) {
while ($rowEmp = mysql_fetch_assoc($resEmp)) {
echo "<strong>Incidencia:</strong> <u>".$rowEmp['pkey']."</u><br>";
echo "<strong>Data:</strong> ".$rowEmp['created']." / ".$rowEmp['UPDATED']."<br>";
echo "<strong>Tecnic Obre:</strong> ".$rowEmp['reporter']."<br>";
echo "<strong>Tecnic Actual:</strong> ".$rowEmp['assignee']."<br>";
echo "<strong>Descripcio incidencia:</strong> ".$rowEmp['summary']."<br>";
echo "<strong>Intervencions:</strong> ".$rowEmp['description']."<br><br>";
}
}
break;
mysql_close($conexion);


Why the result of my query is:

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 '0' at line 1

Nile
08-12-2008, 01:08 PM
Thats a very, very sloppy query. Change it to this:


$getRecord_sql = 'SELECT `pkey` FROM `jiraissue` WHERE project = "10040" and `pkey` LIKE "%'.$searchq.'%"';


For your second one just capitalize all of the commands such as SELECT, FROM, LIKE, WHERE, IN, AND more (haha), `tick` all of the table names or fields, and put double quotes after equal signs(like the highlighted above)

guif
08-12-2008, 02:33 PM
oh sorry!
The problem is the query of "CASE: E". It's return the error.

Nile
08-12-2008, 02:36 PM
For your second one just capitalize all of the commands such as SELECT, FROM, LIKE, WHERE, IN, AND more (haha), `tick` all of the table names or fields, and put double quotes after equal signs(like the highlighted above)

Read my whole post.

guif
08-12-2008, 03:13 PM
I change it.

next the case E I insert:

case 'E':
echo "hello value!: <br>";
echo ?????

in ???? what's the value of my selected AutoSuggest content into the text box?

Nile
08-12-2008, 03:40 PM
May I please see your changed code?

guif
08-12-2008, 03:49 PM
this is the text box into a index.php:


<input name="search-q2" id="search-q2" type="text" onkeyup="javascript:autosuggest2()"/>

and into the consultas.php, the case E:


case 'E':

$queEmp = "select `pkey`, `created`, `UPDATED`, `reporter`, `assignee`, `summary`, `description` from `jiraissue` where project = 10040 and `pkey` like ???VARIABLE???? ";
$resEmp = mysql_query($queEmp, $conexion) or die(mysql_error());
$totEmp = mysql_num_rows($resEmp);
if ($totEmp> 0) {
while ($rowEmp = mysql_fetch_assoc($resEmp)) {
echo "<strong>Incidencia:</strong> <u>".$rowEmp['pkey']."</u><br>";
echo "<strong>Data:</strong> ".$rowEmp['created']." / ".$rowEmp['UPDATED']."<br>";
echo "<strong>Tecnic Obre:</strong> ".$rowEmp['reporter']."<br>";
echo "<strong>Tecnic Actual:</strong> ".$rowEmp['assignee']."<br>";
echo "<strong>Descripcio incidencia:</strong> ".$rowEmp['summary']."<br>";
echo "<strong>Intervencions:</strong> ".$rowEmp['description']."<br><br>";
}
}
break;
mysql_close($conexion);

and I have a Framework:


function autosuggest1() {
q = document.getElementById('search-q2').value;
// Set te random number to add to URL request
nocache = Math.random();
http.open('get', 'lib/search_incidencias.php?q='+q+'&nocache = '+nocache);
http.onreadystatechange = autosuggestReply;
http.send(null);
}

function autosuggestReply() {
if(http.readyState == 4){
var response = http.responseText;
e = document.getElementById('results');
if(response!=""){
e.innerHTML=response;
e.style.display="block";
} else {
e.style.display="none";
}
}
}

and, search_incidencias.php:


<?php
$searchq = strip_tags($_GET['q']);
$getRecord_sql = 'SELECT `pkey` FROM `jiraissue` WHERE project = "10040" and `pkey` LIKE "%'.$searchq.'%"';
$getRecord = mysql_query($getRecord_sql);
if(strlen($searchq)>0){
echo '<ul>';
while ($row = mysql_fetch_array($getRecord)) {
?>
<li><a href="lib/consultas.php?accion=E" onclick="load('lib/consultas.php?accion=E','consulta');return false;">
<?php
echo $row['pkey'];
?>


here is all my code...

guif
08-13-2008, 10:19 AM
If I put echo $search-q2; the result is 0.
And, If I put echo $queEmp; i see a white page without results.

With PHP is possible to give a variable of another PHP file?

guif
08-13-2008, 12:08 PM
oh! I change $search-q2 for search_q2 because
"-" is not a valid character.
And, when I put echo $search_q2;. The result of echo is a white page without results.