PHP click Ref No. link and Populate that Ref No info from mySQL db into Existing

I am new with php and mysql and is attempting to write a small little ‘stats’ page. I want the users to insert the information onto a page ‘savespec.html’ where it goes to the db, this works.
Then I made a search function that can search the unique number named ‘codes’ that has a hyperlink on the specific Unique number, the search works fine, but I cannot link that specific unique code to a html page nor an existing html page to populate the information into that page. I think my knowledge has been depleted :frowning: Can someone please assist with this code, I don’t even know where to start.

I have placed a hyperlink on the unique number so when pressed this should take one to a html or an existing html with the information of that unique number populated.
I am desperate please help :-[ ???

Post some code.

Are you putting PHP in a .html extension? Is your server configured for this?

Thank you for replying.

Yes my server is set up and most of the functionality is up and running, but this part I cannot get working. Please excuse my code I am beginner :smiley: I am using mostly php and html and some MySQL.

This is the search function:
[php]//connect to database
include (‘connect.php’);

$category = $_POST[‘category’];
$criteria = $_POST[‘criteria’];
$query = “SELECT * FROM savespec WHERE $category LIKE '%”.$criteria."%’ ";
$result = mysqli_query($dbcon, $query)or die(‘Cannot Connect to Database’);
$num_rows = mysqli_num_rows($result);

echo “$num_rows results found”;
echo "

";

while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
echo “

";
echo “";
echo “";
echo “";
echo “";
echo “";
echo “";
echo “";

}
echo “

Reference Number Department Head Test Analyst Description Receive Date To Log Send to Revision Received from Revision
” . “<a href='post9.php=” . $row[‘codes’] . “’>”.$row[‘codes’]."
"."
” . $row[‘depthead’] ."” . $row[‘person’] ."” . $row[‘description’] ."” . $row[‘recdate’] ."” . $row[‘log’] ."” . $row[‘senttorev’] ."” . $row[‘recfromrev’] ."
”;
};

?>

[/php]

Then the little bit I have to try and get the data into my existing html is:

[php]<?php

/* connect to the db */
$conn = mysql_connect(“localhost”,“root”,"");
$db = mysql_select_db(‘sdm’,$conn);

/* show tables */
$result = mysql_query(‘SHOW TABLES’,$connection) or die(‘cannot show tables’);
while($savespec = mysql_fetch_row($result)) {

$table = $savespec[0];

$query = “SELECT * FROM savespec WHERE codes =codes LIMIT 0 , 100”;

echo '<h3>',$table,'</h3>';
$result2 = mysql_query('SHOW COLUMNS FROM '.$table) or die('cannot show columns from '.$table);
if(mysql_num_rows($result2)) {
	echo '<table cellpadding="0" cellspacing="0" class="db-table">';
	echo '<tr><th>Field</th><th>Type</th><th>Null</th><th>Key</th><th>Default<th>Extra</th></tr>';
	while($row2 = mysql_fetch_row($result2)) {
		echo '<tr>';
		foreach($row2 as $key=>$value) {
			echo '<td>',$value,'</td>';
		}
		echo '</tr>';
	}
	echo '</table><br />';
}

}
?>[/php]

It’s not much I know, but I have run out of ideas on how to do this.

I would really appreciate any help you can give.

Thanking you in advance…

You went from using PDO back to deprecated obsolete Mysql?

??? I know i am not very familiar with php and that is why i asked some help…

Which is why you would do better for yourself to study a few php tutorials before you try to make something. The PHP manual is available free and there are numerous tutorials. Just make sure they are PDO or Mysli tutorials as far as database related stuff. Better to start with the basics of php before you get into database tutorials.

Why are you using SHOW TABLES and SHOW COLUMNS? I’m confused about what this code is supposed to do

Hi There,

I have taken your advice and seriously read up about it, however after reading through everything I cannot get the rows to display, can you please look at my code and tell me what I have left out?

My Functions.php
[php]

<?php $config = array ( 'username' => 'root', 'password' => '' ); function connect($config) { try { $conn = new PDO('mysql:host=localhost;dbname=sdm', $config['username'], $config['password'] ); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); return $conn; } catch(Exception $e){ return false; } } function query($query, $bindings, $conn) { $stmt = $conn->prepare($query); $stmt->execute($bindings); $results = $stmt->fetchAll(); return $results ? $results : false; } Function get($tableName, $conn) { try{ $result = $conn->query("SELECT * FROM $tableName"); return ( $result->rowcount() > 0 ) ? $result : false; } catch(Exception $e){} } [/php] and my post9.php now looks like this: [php] <?php require 'functions.php'; $conn = connect($config); if($conn ){ $codes = isset($_GET['codes']) ? (int)$_GET['codes'] : 0; $row = query("SELECT * FROM savespec WHERE codes = :codes", array('codes' => $codes), $conn)[0]; } ?> Stats <?php if ($row) : ?> <?php print_r($row); die(); ?>

<?=$row['codes'];?>

<?php endif; ?> [/php]

Am I a little bit closer to the truth ?

Hope to hear from you soon :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service