My project is about Allergies and I am trying to add the allergies given in one table "List of Allergies" to another table "MyAllergies" with an onclick button "add" for each allergies given. What I want is when the user clicks on add button for one allergy, that specific allergy should automatically be added to the "MyAllergy.php". Please help me. I have been trying for 2 days and I got no where. However, I tried the query and it was almost correct. I would be so grateful. Thank you. Let me know if you want me to attach the other code or any more questions. :)
AddAllergy.php
<?php
include('Session.php');
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Allergen Details</title>
<div align="center">
<h1>Allergen Information</h1>
</div>
</head>
<body>
<?php
$allergysql = 'SELECT Allergy,Description,Symptoms FROM FoodAllergy';
$retrieve = mysqli_query($connection, $allergysql);
if(!$retrieve)
{
die("Could not get data!".mysqli_error($connection));
}
print "
<table border=\"5\" cellpadding=\"7\" style=\"border-collapse: collapse\" bordercolor=\"#85144b\" width=\"100%\" id=\"AutoNumber2\" bgcolor=\"#7FDBFF\"><tr>
<th width=100>Allergy:</th>
<th width=100>Description:</th>
<th width=100>Symptoms:</th>
<th width=100>Status:</th>
</tr>";
while($rowA = mysqli_fetch_assoc($retrieve))
{
print "<tr>";
print "<td>" . $rowA['Allergy'] . "</td>";
print "<td>" . $rowA['Description'] . "</td>";
print "<td>" . $rowA['Symptoms'] . "</td>"; ?>
<td> <div align ="center"> <button type ="button" onclick="addallergy()">Add</button></div></td>
<script>
function addallergy() {
// WHAT SHOULD I ADD HERE?? //
alert ('Added to your profile!');
}
</script>
<?php
print "</tr>";
}
print "</table>";
?>
</body>
</html>
Good Day to you.This is what I have been trying to do.
I have a php page where I have drop down list with options as lecturers and students.
Once I select any option, details regarding lecturers or students will be displayed in a div using ajax.
Code is as follows.(This will be called in onchange event of the drop down list with a javascript.
<?php
session_start();
require "configuration.php";
$q = intval($_GET['q']);
if($q==1)
{
$sql="SELECT * FROM temp_instructor_log";
$result = mysqli_query($con,$sql);
echo "<table>
<tr>
<th></th>
<th><u><B>NIC</u></B></th>
<th><u><B>Name</u></B></th>
<th><u><B>Email</u></B></th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>"?>
<input type="checkbox" name="emplist[]" value="<?php echo $row['nic']?>">
<?php echo "</td>";
echo "<td>" . $row['nic'] . "</td>";
echo "<td>" . $row['firstName'] ." ".$row['lastName']. "</td>";
echo "<td>" . $row['email']."</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
}
?>
Its working and giving me the display with checkboxes at the very beginning.
<?php session_start();
require "configuration.php";
?>
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Manage courses</title>
<script type="text/javascript">
</script>
</head>
<body>
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST')
{
if (isset($_POST['btnAccept']))
{
$utype=$_POST['category'];
$arr = $_POST['emplist'];
foreach( $arr as $item)
{
echo $item . "</br>"; /* Will print 1,2 and 3 (mind newlines)*/
}
First I tried to echo the values after checking some of the checkboxes.But it didnt work out.Your kind consideration given on this is highly appreciated.
Thanks in advance.
I have stored images in phpmyadmin in a BLOB format. When I try to display them on my webpage, weird symbols and letters show up. The pictures are a mix of jog and png. Please help.
Here is the code that I currently have.
<?php
session_start();
include 'dbConn.php';
if (!isset($_SESSION['username'])){
header("Location: clientLogin.php");
}
$query = "SELECT * FROM ip_games ";
$stmt = $dbConn->query($query);
$result = $stmt->fetchAll();
?>
<style>
body {
background-color: grey;
}
table {
margin: 0 auto;
}
td {
padding-right: 30px;
}
</style>
<html>
<body>
<div>
<form action="welcome.php">
<input type="submit" value="Sign out" />
</form>
</div>
<h1>Happy Face Emoji Games</h1>
<form>
Name: <?php echo $_SESSION['name'] ?> <br />
</form>
<table>
<?
for ($i=0; $i<count($result); $i++)
{
echo "<tr>";
echo "<td>" . $result[$i]["picture"] . "<br />" . $result[$i]["name"]. " <br /> " .$result[$i]["console"] . " <br />" . "$" . $result[$i]["cost"] . "</td>";
//echo "<td>".$result[$i]["console"]."</td>";
//echo "<td>".$result[$i]["description"]."</td>";
//echo "<td>".$result[$i]["cost"]."</td>";
echo "</tr>";
}
?>
</table>
</body>
</html>
To directly use the binary data as a an image source, you can use the data URI scheme, for example:
$uri = 'data:image/png;base64,'.base64_encode($row['binary-data']);
This URI can then be used directly as the image’s source:
background-image: url(<?php echo $uri; ?>)
<img src="<?php echo $uri; ?>">
not good practice, older browser issues, load issues and catching issues. cheer
You need to wrap your image in an <img> tag.
<img src="<?php echo $result[$i]["picture"]; ?>" />
Give that a try and let me know :).
Edit: I wrote that as if it was in the page, for your question you probably want:
echo "<td><img src='" . $result[$i]["picture"] . "' />" . "<br />"... etc.
Hello i'm new in php so i want to know if there's a way to get the text from a hyperlink that has been created by a loop?
is there any solution? my problem is that i can't get the name from the hyperlink so that i will pass that name to other page .
// i have this code which doesn't work.
<head>
<script language="javascript" type="text/javascript">
function GetText()
{
var linktext=document.getElementById('testlink').innerHTML;
<?php $_SESSION['name'] = "<script>document.write(lintext)</script>"?>
}
</script>
<title>Search</title>
<link rel="stylesheet" type="text/css" href="admincss.css" />
</head>
if($pic != "")
{
$total=mysql_affected_rows();
for($ff1=0;$ff1<$total;$ff1++)
{
print "<table width='100%' align='center' border='5'>";
print "<td width='20%'><img src=\"$pic\" height='100px' width='100px'/> </td>";
print "<td align = 'center' width='20%'><a onclick='GetText()' ' href='search.report.php' id='testlink'>$name</a></td>"; //
print "<td align = 'center'width='20%'>$bday</td>";
print "<td align = 'center'width='20%'>$no</td>";
print "<td align = 'center'width='20%'>$eadd </td>";
print "</table>";
}
}
I hope you are talking about this line:
print "<td align = 'center' width='20%'><a ' href='search.report.php' id='testlink'>$name</a></td>"; //
You need to write this line as below:
print "<td align='center' width='20%'><a href='search.report.php?name=$name' id='testlink'>$name</a></td>"; //
And then you can get the name on search.report.php file by this code:
$_SESSION['name'] = $_REQUEST['name'];
echo $_REQUEST['name'];
You cann't execute the PHP code in the JS file. so you need to send it on server as PHP is server side language.
I have a PHP variable inside a frame from a frameset that needs to be passed to two other frames simultaneously. One of those frames refreshes every 5 seconds and will easily grab the variable from the URL. The other frame does not refresh as it is a form. That frame/form needs to populate a disabled field before information is sent (perhaps doable in AJAX, I don't know).
I am not versed in anything other than HTML, CSS and basic PHP, so I have become hung up this problem.
Please refer to the code and for more explanation - Thanks!!
Well, I have a picture, but due to my reputation being too low, I cannot show you... figures.
Anyways, here's the code:
main frame page:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Incident Entry</title>
</head>
<frameset border="0" frameborder="0" rows="50%,50%">
<frameset border="0" frameborder="0" cols="40%,60%">
<frame src="incidententry.php" name="topleft">
<frameset border="0" frameborder="0" rows="56%,44%">
<frame src="detailentry.php" name="toprighttop">
<frame src="details.php" name="toprightbottom">
</frameset>
</frameset>
<frame src="incidents.php" name="bottom">
</frameset>
</html>
incidents.php:
<?php header ('Refresh: 5');
session_start();
if($username);
?>
<!DOCTYPE html>
<html lang="en">
<title>Incidents</title>
<?php mysql_connect("-----", "-----", "------");
#mysql_select_db(-----_incidents);
$sql2="SELECT * FROM incidents ORDER BY id DESC LIMIT 10";
$result2=mysql_query($sql2);
$num=mysql_numrows($result2);
?>
<head>
<link rel="stylesheet" type="text/css" href="output1.css">
<meta http-equiv="Page-Enter" content="blendTrans(Duration=0)">
<meta http-equiv="Page-Enter" content="revealtrans(duration=0.0">
<style type="text/css">
body{background-color:black}
body{font-family:'trebuchet ms' }
</style>
</head>
<body>
<font color="white">
<div class="CSSTableGenerator">
<table border='0' rules='all' width='75%'>
<tr class="hideextra">
<td>Inc #</td>
<td>Date</td>
<td>Time</td>
<td>City</td>
<td>Dept</td>
<td>Alarm Level</td>
<td>Incident Type</td>
<td>Address</td>
<td width="53px">User</td>
<td>Upgr</td>
</tr>
<?php
$_GET['id'];
while($row=mysql_fetch_array($result2)){
$id2 = $row['id'];
$id = str_pad($id2,9, "2013-0000", STR_PAD_LEFT);
$date=rtrim(ltrim($row['date'], "2013-"), "0..9,:");
$time=$row['time'];
$city=$row['city'];
$fire=$row['fire'];
$addy=$row['addy'];
$level=$row['level'];
$desc=$row['desc'];
$units=$row['units'];
$who=$row['who'];
echo "<tr>";
echo "<td style='white-space:nowrap;'><center> <a href='http://www.------.com/pages/CAD/details.php?inci_num=$id' target='toprightbottom'>" . str_pad($row['id'],9,"2013-00000",STR_PAD_LEFT) . "</a></center></td>";
echo "<td style='white-space:nowrap;'><center>" . str_pad($date,6,'0',STR_PAD_LEFT) . "</center></td>";
echo "<td>" . $row['time'] . "</td>";
echo "<td>" . $row['city'] . "</td>";
echo "<td>" . $row['fire'] . "</td>";
echo "<td>" . $row['level'] . "</td>";
echo "<td>" . $row['desc'] . "</td>";
echo "<td>" . $row['addy'] . "</td>";
echo "<td>" . strtoupper($row['who']) . "</td>";
echo "<td><center><a href='http://www.------.com/pages/CAD/upgrade.php?id=$id2' target='_self'><img src='http://www.------.com/images/arrow_red_up.gif' height='16'></a></center></td>";
echo "</tr>";
echo "</div>";
}
?>
</table>
</html>
details.php:
<?php header ('Refresh: 5'); ?>
<!DOCTYPE html>
<html lang="en">
<title>Incident Details</title>
<?php
mysql_connect("-------", "-------", "------");
#mysql_select_db(------);
$inci_num2=$_GET['inci_num'];
$sql3="SELECT * FROM notes2 WHERE inci_num='$inci_num2' ORDER BY id DESC";
$result4=mysql_query($sql3);
?>
<head>
<link rel="stylesheet" type="text/css" href="output1.css">
<style type="css/text">
body{background-color:black}
body{font-family:'trebuchet ms' }
</style>
</head>
<body bgcolor="black">
<font color="white">
<div class="CSSTableGenerator">
<table rules="all">
<tr class="hideextra">
<td>#</td>
<td width="46px">Time</td>
<td>Incident Notes</td>
<td width="53px">User</td>
</tr>
<?php
$_POST['inci_num'];
while($row=mysql_fetch_array($result4)){
$id=$row['id'];
$ipaddress=$row['ipaddress'];
$inci_num=$row['inci_num'];
$notes=$row['notes'];
$Time1=$row['Time1'];
$user=$row['who'];
echo "<tr>";
echo "<td> " . $row['inci_num'] . "</td>";
echo "<td>" . $row['Time1'] . "</td>";
echo "<td>" . $row['notes'] . "</td>";
echo "<td>" . $row['who'] . "</td>";
echo "</tr>";
echo "</div>";
}
?>
</table>
</body>
and finally, detailentry.php:
<?php
session_start();
if($username)
ini_set('display_errors', 1);
ini_set('log_errors', 1);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
error_reporting(E_ALL);
$id2=$_GET['inci_num2'];
if(isset($_POST['submit'])){
$db=mysql_connect("------", "-----", "------") or die ("Cant connect");
$mydb=mysql_select_db("----_incidents") or die ("Cant find db");
$notes = mysql_real_escape_string($_POST['notes']);
$who = strtoupper($_COOKIE['username']);
$ipaddress = $_SERVER['REMOTE_ADDR']."\r\n";
$inci_num1 = $_POST['inci_num'];
$inci_num = str_pad($inci_num1,9, "2013-0000", STR_PAD_LEFT);
if(!isset($_POST["auto"])){
$sql = "INSERT INTO `notes2` (`id` , `inci_num` , `notes` , `who` , `ipaddress` , `Date` , `Time1`) VALUES (NULL, '".$inci_num."' , '".$notes."' , '".$who."' , '".$ipaddress."' , NOW(), DATE_ADD(NOW(),INTERVAL 120 MINUTE))";
}else{
$sql = "INSERT INTO `notes2` (`id` , `inci_num` , `notes` , `who` , `ipaddress` , `Date` , `Time1`) VALUES (NULL, '".$inci_num."' , '".$notes."' , '".$who."' , '".$ipaddress."' , NOW(), DATE_ADD(NOW(),INTERVAL 120 MINUTE))";
}
$result = mysql_query($sql) or die ("Cant insert ".mysql_error());
if($result)
{
}
else
{
}}
?>
<title>Detail Entry</title
<head>
<style type="css/text">
body{overflow-y:hidden;
white-space-collapse:collapse;}
body{background-color:black}
body{font-family:'trebuchet ms' }
.body{font-family:'trebuchet ms' }
.hide{visibility:collapse; }
#hide{visibility:collapse; }
.nopad{padding-bottom:0px; margin-bottom:0px; }
.borders{ }
</style>
</head>
<body bgcolor="black" class="body" style="font-family:'trebuchet ms';">
<form action="detailentry.php" method="POST" style="white-space-collapse:collapse;">
<font color="white">
<table border="0" class="borders">
<tr>
<td><font color="white" size="3">Inc #:</font></td>
<td><font color="white"><input type="text" maxlength="11" value="<?php echo $id2;?>" required name="inci_num">  RM911 ID:</font></td>
<td><center><font color="white"><? echo strtoupper($_COOKIE['username']);?></font></center></td>
</tr>
<tr>
<td><font color="white">Notes:</td>
<td colspan="2"><textarea placeholder="Enter Incident Notes here" required rows="4" cols="36" name="notes"></textarea></td>
</tr><input id="hide" style="visibility:collapse;" class="hide" hidden type="checkbox" name="auto" value="auto" checked>
<tr class="nopad">
<td class="nopad" colspan="3" align="center"><input class="nopad" type="submit" name="submit" value="Submit"><input class="nopad" type="reset"></td>
</tr>
</table>
</form>
</body>
</html>
**Note: I know I should be using the new syntax, one thing at a time please. Also, I realize that the code be made nicer and easier to read. Again, that's secondary to fixing this problem.
This is what I am trying to accomplish:
I need to take the $id2 variable from the incidents.php page and simultaneously transfer it to both details.php and detailentry.php when the user clicks on the incident number on incidents.php. On detailentry.php, $id2 needs to be in the Inc #: text input box.
Thank you for your help in advance!!!
hmm. An 8 year old question nobody answered. and 2 "answers" that were just dismissive comments.
Here's a real answer: You can pass the data between frames by making a session variable. Session variables are accessible between frames. https://www.php.net/manual/en/reserved.variables.session.php has full info.
I see you have session_start() in two of your 3 php files. Add it to the top of the third one. Then assign a session variable with whatever value you want to pass to another frame:
$_SESSION['vartopass']=$varyouwanttopass;
now $_SESSION['vartopass'] is available in your other frames that start with session_start().
$variwantedinthisframe=$_SESSION['vartopass'];
So, yeah, 8 years late. You probably figured this out by now, but someone else hasn't, and I hate dismissive statements that don't help anyone.