Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

how to correct search key

baebae Posts: 45Member
my problem is the keyword not working.
<?php
include('connect_login.php');
?>


 






<?
$title=$_POST['title'];
$query = "Select * from 'developer' where title='$title'";
$result = mysql_query($query);
while($result_row = mysql_fetch_row($result))
{
$input = $result_row[1];
}
if($input == "")
{ ?>

window.alert('You have inserted wrong title, please try again ...');

<?
}
else
{
?>






<?
}
?>
ID
Title
Student Name
<? echo $result_row[1]; ?> <? echo $result_row[2]; ?> <? echo $result_row[4]; ?>






how to correct the code in order to display the output?

Comments

  • AgbagbaraAgbagbara Posts: 24Member
    [code]
    <?php
    include('connect_login.php');
    ?>

     







    <?
    $title=$_POST['title'];
    $query = "Select * from developer where title='$title'";
    $result = mysql_query($query);
    $num_rows = mysql_num_rows($result);
    if($num_rows > 0){
    while($result_row = mysql_fetch_row($result)){
    //$input = $result_row[1];
    $all_data[] = $result_row;
    ?>





    <?
    }
    }else{ ?>

    window.alert('You have inserted wrong title, please try again ...');
    <?
    }?>
    ID
    Title
    Student Name
    <? echo $result_row[1]; ?> <? echo $result_row[2]; ?> <? echo $result_row[4]; ?>


    [/code]


    Basically the code you have is correct.
    You have included your configuration,
    Extracted you php post variables from $_POST, although you may have to do some escaping but that is along the way.
    You have created your query and gotten the result.

    It would be good to count the number of rows returned from the query,
    if it is more than zero, then write out all the results.
    else if it is equal to zero, then you have to do your page redirect, but I dont see any reason why.

    You might as well write a no result or no row message on the current page.

    Hope this helps.

    And please provide some feedback even if it don't.

    Thanks.
  • baebae Posts: 45Member
    well, i have started from row 1 due to $title=$_POST['title'];<<<<according to this command has begun from this row. Also, the row zero is id no need to assign because it is auto_increment(auto adding). However, the error are occur;

    mysql_fetch_row() : supplied argument is not a valid MySQL result resource

    via this line
    while($result_row = mysql_fetch_row($result))


    thanks for your answer
  • AgbagbaraAgbagbara Posts: 24Member
    There is nothing wrong with the command, it is straigth forward, there must be something wrong with you configuration.

    Try this command
    $result = mysql_query($query) or die('Query failed: ' . mysql_error());
    if you dont get any error, then u know that there is something else wrong.

    Make sure that you have a database selected, in your config file using.
    mysql_select_db('my_database') or die('Could not select database');

    also check that the configuration is correct? check for typographical errors.

Sign In or Register to comment.