0

I want to fetch data of row buy clicking "apply" button in another page. Which code should I use for hyberlink on the row? also which code should I use for the another page which will show the row date?

This is the code I use:

<?php


/////// Update your database login details here /////
$dbhost_name = "localhost:1234"; // Your host name 
$database = $CONFIG->dbname;       // Your database name
$username = $CONFIG->dbuser;            // Your login userid 
$password = $CONFIG->dbpass;            // Your password 
$conn = mysql_connect($dbhost_name, $username, $password);
   


  if(! $conn ) {
      die('Could not connect: ' . mysql_error());
   }
   
   $sql = 'SELECT * FROM jobs';
   mysql_select_db($database);
   $retval = mysql_query( $sql, $conn );
   
   if(! $retval ) {
      die('Could not get data: ' . mysql_error());
   }
   ?>

          
<?php
   while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
   ?>

<table border="2">
        <thead>
            
            <tr>          
                    <td><?php echo $row['jobid']; ?></td>
                    <td><?php echo $row['title']; ?></td>
                    <td><?php echo $row['company']; ?></td>
                    <td>
                        
                        <form name="search" action="submit.php" method="POST">
                            <?php echo $row['jobid']; ?>
                        <input type="submit" value="apply" name="submit" />
                        </form>
                    </td>

                </tr>
 
            </tbody>
        </table>

<?php
   }
   
 
   
   mysql_close($conn);
   
?>
Samir Junaid
  • 113
  • 1
  • 3
  • 17

2 Answers2

1

If you want to send data from database to submit.php use hidden input type and and echo your data in the value section. Eg:

<form name="search" action="submit.php" method="POST">
<input type="hidden" name="jobid" value="<?php echo $row['jobid']; ?>" />
<input type="hidden" name="title" value="<?php echo $row['title']; ?>" />
<input type="hidden" name="company" value="<?php echo $row['company']; ?>" />
<input type="submit" value="apply" name="submit" />

And in processing page that is your submit.php use $_POST to fetch the data eg:

<?php
$jobid = $_POST['jobid'];
?>

How ever you are using mysql_* which is clearly outdated and removed from new php vevrsion. I recommend to use mqsqli or PDO. And start using prepare statements to remove the risk of sql injection.

0

You are describing something called AJAX. Don't be worried, it is actually quite easy.

See this example for an overview of what you want to do.

See this answer for some simple examples of AJAX to get you started.

Note that the PHP page with the AJAX javascript code, and the PHP page the AJAX sends data to, cannot be the same page. Although that is possible with <form> constructs, it is not possible with AJAX. (Instead of receiving the desired output, you will receive back the full HTML of the page)

Community
  • 1
  • 1
cssyphus
  • 37,875
  • 18
  • 96
  • 111