1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

make a query with the value of text

Discussion in 'PHP' started by guif, Aug 12, 2008.

  1. guif

    guif New Member

    Joined:
    Jul 25, 2008
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    0
    hi!

    I have problems to give the value of a text.

    I have in a PHP this:

    Code:
    <?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:

    Code:
    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
     
  2. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    PHP:
    // This line
    $queEmp    "select pkey, created, UPDATED, reporter, assignee, summary, description from `jiraissue` where project = 10040 and pkey like ".$search-q2." ";  
    // Should be
    $queEmp    "select pkey, created, UPDATED, reporter, assignee, summary, description from `jiraissue` where project = 10040 and pkey like '".$search-q2."'";  
     
  3. guif

    guif New Member

    Joined:
    Jul 25, 2008
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    0
    no... not's run.
    Is it possible with php read the variable of another file?

    I put all my code:

    this is the text box into a index.php:

    Code:
    <input name="search-q2" id="search-q2" type="text" onkeyup="javascript:autosuggest2()"/>
    and into the consultas.php, the case E:

    Code:
    case 'E':		
    	
    $queEmp	= "select `pkey`, `created`, `UPDATED`, `reporter`, `assignee`, `summary`, `description` from `jiraissue` where project = 10040 and `pkey` like [B]???VARIABLE????[/B]   ";		
    $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:

    Code:
    function autosuggest1() {
    q = document.getElementById('[B]search-q2[/B]').value;
    // Set te random number to add to URL request
    nocache = Math.random();
    http.open('get', 'lib/[B]search_incidencias.php[/B]?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:

    Code:
    <?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/[B]consultas.php[/B]?accion=E" onclick="load('lib/consultas.php?accion=E','consulta');return false;">
    <?php 
    echo $row['pkey']; 
    ?> 

    here is all my code...
     
  4. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    PHP:
    // This line
    $queEmp    "select pkey, created, UPDATED, reporter, assignee, summary, description from `jiraissue` where project = 10040 and pkey like ".$search-q2." ";  
    // Should be
    $queEmp    "select pkey, created, UPDATED, reporter, assignee, summary, description from `jiraissue` where project = 10040 and pkey like '".$search-q2."'";  
     
  5. guif

    guif New Member

    Joined:
    Jul 25, 2008
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    0
    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?
     
  6. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    $search-q2 is an invalid variable name '-' is not a valid character for variables, try usinh '_' instead.
     
  7. guif

    guif New Member

    Joined:
    Jul 25, 2008
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    0
    I change it. I put search_q2.
    and.. I insert: echo search_q2;. The result of echo: search_q2!!!!
    why?
     
  8. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    echo $search_q2; ??
     
  9. guif

    guif New Member

    Joined:
    Jul 25, 2008
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    0
    sorry. I put echo $search_q2;.
    The result is a white page without results.
     
  10. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    In your code I see that you have defined $searchq and you are using $search_q
     
  11. guif

    guif New Member

    Joined:
    Jul 25, 2008
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    0
    search_q2 is the name of the text.
    $search_q is the result of my query.
     
  12. guif

    guif New Member

    Joined:
    Jul 25, 2008
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    0
    Yes, the searchq is the variable, but I would like to use the name of the text.
    And... how can I use this in my php?
    I defined into the search_incidencias.php but not into consultas.php and... my text box is in the index.php.
     
  13. guif

    guif New Member

    Joined:
    Jul 25, 2008
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    0
    but, how can i include one variable of another file?
     

Share This Page