Why cannot call the div #popup1? - php

Why cannot call the div #popup1? I want to pass the $row['staffId'] to div and call the popup to show the information .
$result = mysql_query("SELECT * FROM Staff WHERE companyId='$companyIdResult'");
echo "<div>
<table >";
while($row = mysql_fetch_array($result)){
echo "<tr>";
echo "<td >" . $row['staffName'] . "</td>";
echo "<td>" . $row['staffPhone'] . "</td>";
echo "<td><a class ='editbutton' href=' #popup1?edit_id=".$row['staffId'] ."'>Edit</a></td>";
echo "</tr>";
}
echo "</table>";
echo "</div>";
if($_GET['edit_id'] != ""){
$staffId = $_GET['edit_id'];
$sql2 = mysql_query("SELECT *FROM Staff WHERE staffId='".$staffId."'");
echo '<div id="popup1" class="overlay" >';
echo '<div class="popup">';
echo '<input type="text" name="staffName" value= ".$row['staffName']." ><br>';
echo '<input type="text" name="staffPhone" value=".$row['staffPhone']."><br>';
echo '</div>';
echo '</div>';
}

First of all you cannot append query parameters (?edit_id=...) to an anchor like #popup1, also you seem to misunderstand how PHP and the browser interact, you cannot open a popup and create it dynamically on the server side the way you seem to plan to. You could use AJAX to load the matching form for the staffId into your popup or generate a popup for every staffId beforehand (and create matching links with different anchors), but you try to open a popup1 with values generated on the server side and that doesn't work in this way.

Related

Lightbox not showing php

I'm working for a system by the use of php. We have an admin.php page where all the list of applicants were listed. And we want that when we click on a specific applicant's name, a lightbox would appear that will show more information about the applicant. But, these codes below seems to be not working and I don't know why. I am a newbie in php btw.
<?php
include('config.php');
$result = mysql_query("SELECT * FROM employee as t1")
or die(mysql_error());
echo "<table border='0' cellpadding='15' text-align = 'center' >";
echo "<tr>";
echo " <caption><b><font size = '5'> <h2>List of Applicants </h2> </b> </font><hr></caption>";
echo "<th>Applicant ID</th>";
echo "<th>Application Date</th>";
echo "<th>Name</th>";
echo "<th>Job</th>";
echo "</tr>";
while($row = mysql_fetch_array( $result ))
{
echo "<tr class='gradeC'>";
echo '<td><b><font color="#663300">' . $row['employee_id'] . '</font></b></td>';
echo '<td><b><font color="#663300">' . $row['date'] . '</font></b></td>';
echo '<td><b><font color="#663300">' . $row['fname'] . '</font></b></td>';
echo '<td><td>';
echo "</tr>";
}
echo "</table>";
function runMyFunction() {
echo "<div onclick =\"document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'\"></div>";
echo "<div id=\"light\" class=\"white_content\">This is the lightbox content. Close</div>";
echo "<div id=\"fade\" class=\"black_overlay\"></div>";
}
if (isset($_GET['hello'])) {
runMyFunction();
}
?>
I'm not sure but I think the problem is in the function, or the way I'm using the codes for lightbox to appear.
Can you rewrite this line
function runMyFunction() {
echo "<div onclick =\"document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'\"></div>";
echo "<div id=\"light\" class=\"white_content\">This is the lightbox content. Close</div>";
echo "<div id=\"fade\" class=\"black_overlay\"></div>";
}
to
function runMyFunction() {
?>
<div onclick ="document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'"></div>
<div id="light" class="white_content">This is the lightbox content.
Close</div>
<div id="fade" class="black_overlay"></div>
<?php }
By eliminating the slashes could help make the code easier to process.
I hope this help.

Can't retrieve values from post variables that have a space in their name

I have a simple form which is designed to allow a user to enter numeric values and then sent them to a page which calculates the result.
The problem I'm having is that post variables that includes a space in their name don't seem to be recognised.
The form is created like so:
<?php
$minerals = mysqli_query($con, "SELECT * FROM items");
?>
<table border='1'>
<tr>
<td>Product: </td>
<td>Quanitity: </td>
<td>Buyback Price: </td>
</tr>
Minerals
</br>
</br>
<?php
while($row = mysqli_fetch_array($minerals)) {
echo "<tr>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . "Amount: <input type='text' value='0' name='" . $row['name'] . "'>" . "</td>";
echo "<td>" . $row['price'] . "</td>";
echo "</tr>";
if($row['name'] == "Morphite") {
break;
}
}
echo "</table>";
?>
And I'm trying to retrieve the post data like so:
echo '<table border="1">';
echo '<tr><td>Product</td><td>Value</td></tr>';
while($item = mysqli_fetch_array($items)) {
echo '<tr>';
echo '<td>';
echo $item['name'];
echo '</td>';
echo '<td>';
echo $_POST[$item['name']];
echo '</td>';
echo '</tr>';
}
echo '<tr><td>Total</td><td></td></tr>';
echo '</table>';
But any 'name' in the database that contains a space causes nothing to be displayed on the other end.
Since you can never be sure what is written in the database (invalid characters for html etc) you should encode this value before using it as inputs name-attribute. So try maybe htmlspecialchars or strip off the spaces and non-printable and invalid characters. Also if you have a primary key (integer) in your database you could use this to identify the record instead of the name.
Try replacing
echo $_POST[$item['name']];
with
echo $_POST["{$item['name']}"];

Display MySQL data when linking to new page

I have a php script that connects to my database and returns results: name, and price, however, now I am trying to also create a link - that opens a new php page "more_info.php" and displays the correct description that corresponds to correct name.
I have been trying to accomplish this, but I haven't been able to get it working.
while($row = mysqli_fetch_array($result)) //mysql_fetch_array bring back an object, in this case the $result of the mysql query and puts it into a variable $row
{
echo "<td align='center'>" . $row['name'] . "</td> <td align='center'> <input type='button' value='More Info'; onclick=\"window.location='?start=' . $row['name.description'] . ?more_info.php?';\"> </td>";
within the onclick, I want the new window to open up, and bring in the description that matches the name, into the more_info.php
I input that code, but obviously it isn't working. Does this look like i'm on the right path at all?
Change it like this.
echo '<table>';
while($row = mysqli_fetch_array($result))
{
echo '<tr>';
echo '<td align="center">' . $row['name'] . '</td>';
echo '<td align="center">';
echo '<input type="button" value="More Info" onclick="window.location=\'more_info.php?start=' . urlencode($row['description']) . ' \';" />';
echo '</td>';
echo '</tr>';
}
echo '</table>';
and read it in more_info.php like:
<?php
$start = (!empty($_GET['start']) ? $_GET['start'] : false);
echo '<h1>Info about: ' . $start . '</h1>';
?>
shouldn't it be:
window.location='more_info.php?start=' . $row['name.description']
an alternative to using JS triggers on buttons for navigation is you could also just use a link and css style it to look like a button <a href="more_info.php?start=' . $row['name.description'].'" class="button">

Coding dynamic anchor tags

I want to link an anchor tag from one page to another. The second of which is a view all page that pulls data from the database. When run the code below, the second page is loaded but doesn't move to the tag. Here is the code for the 1st page:
echo "<h2>$dd. $info and ID is
**$id**</h2><hr />";
Here is the code for the page it should point to:
while($row = mysql_fetch_array( $result )) {
**$ggg = $row['id'];**
echo "<tr>";
echo '<td><input type="button" value="Delete"></td>**<a name="$ggg"></a>**';
echo '<td>' . $row['id'] . '</td>';
echo '<td>' . $row['info'] . '</td>';
echo "</tr>";
}
Your php variable $ggg will not be parsed as it is being echo'ed inside single quotes '' so your <a> anchor will not be correct-
echo '<td><input type="button" value="Delete"></td><a name="$ggg"></a>';
Change it to -
...<a name="'.$ggg.'"></a>...
so it is now -
echo '<td><input type="button" value="Delete"></td><a name="'.$ggg.'"></a>';

attach hyperlink to dynamic table cell

I have a table in generated using PHP using data collected from MYSQL. How do I append a hyperlink to a row?
Here is the code for the dynamic table I am using:
mydata = mysql_query($sql,$con);
echo "<table id='name',table border=0>
<tr>
<th>Users</th>
<th>Status<th>
</tr>";
while($record = mysql_fetch_array($mydata)){
echo "<tr>";
echo "<td>" . $record['user_id'] . "</td>";
if (strtolower(trim($record['activity']))!=strtolower('LOGIN')){
echo "<td>" . $default1 . "</td>";
}else{
echo "<td>" . $default . "</td>";
}
echo "</tr>";
}
echo "</table>";
;
I have tried appending a href="..." style="display:block;"> but cannot get it to work.
Try echoing out a hyperlink.
echo "<a href='http://www.google.com/'>Google</a>";
If you want other functionality, such as clicking on a table row to work as a hyperlink, you would need to implement that in javascript as a table cell/row is not a hyperlink.

Categories