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.
Related
I am populating an HTML table with information from a database and want to trigger it with a button.
Can someone help me with this, and perhaps add some links to relevant website with examples?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div method="GET">
<table>
<thead>
<tr>
<th>ID</th>
<th>Nombre</th>
<th>Usuario</th>
</tr>
<?php
include "php/populate.php";
?>
</thead>
</table>
<input type="button" value="button" id="button">
</div>
</body>
</html>
<?php
$result = mysqli_query($enlace,"SELECT * FROM tb_personas");
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . $row['txt_nombre'] . "</td>";
echo "<td>" . $row['txt_usuario'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($enlace);
?>
You need to use jQuery (the easiest way to use ajax)
take a look at this question on stackoverflow how to call a php script on a html button click
additionally you are including your data at table's header, instead they should be included in table's body.
<table>
<thead>
<tr>
<th>ID</th>
<th>Nombre</th>
<th>Usuario</th>
</tr>
</thead>
<tbody>
<?php include "php/populate.php"; ?>
</tbody>
</table>
I finally get reviews to work, which will allow user to post their review about the product and display them in a review page with product details, however I can't get it to work perfectly. When a user posts their review, it will update in the table but only the second post will show up.
The following image is from the test i was running,
Before posting a review
After posting the first review
After posting the second review
As the images display, the first review will never show up, only starting from the second and above,
Here my code for review page updated with full code
<?php
if (!isset($_SESSION)) {session_start();} //start session
if (!isset($_SESSION['client_ID'])) {
//echo "<script>alert('not logged in');</script>";
header("Location: index.html" );
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="keywords" content="Games, Gaming, PS4, PS3, XBOX, Video games">
<meta name="description" content="Games 4 You">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Games 4 You</title>
<link rel="stylesheet" type="text/css" href="Styles/ProductsStyle.css">
<!-- javascript/jQuery -->
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
</head>
<body>
<!--Add the following script at the bottom of the web page (before </body></html>)
Support system using MyLiveChat.com
-->
<script type="text/javascript" async="async" defer="defer" data-cfasync="false" src="https://mylivechat.com/chatinline.aspx?hccid=42206151"></script>
<script>// disable zoom to keep image fit and always in position
document.firstElementChild.style.zoom = "reset";
// the above script will disable zoom in and out
</script>
<script type="text/javascript">
// this will auto change the background image to the following 7 images which are in the root Images/
// this is set to change every five second
// declare list of backgrounds
var images = ['bg-01.jpg', 'bg-02.jpg', 'bg-03.jpg', 'bg-04.jpg', 'bg-05.jpg', 'bg-06.jpg', 'bg-07.jpg'];
// declare function that changes the background
function setRandomBackground() {
// choose random background
var randomBackground = images[Math.floor(Math.random() * images.length)];
// set background with jQuery
$('body').css('background-image', 'url("Images/' + randomBackground + '")');
}
// declare function that sets the initial background, and starts the loop.
function startLoop() {
// Set initial background.
setRandomBackground();
// Tell browser to execute the setRandomBackground every 5 seconds.
setInterval(setRandomBackground, 5 * 1000);
}
// One the page has finished loading, execute the startLoop function
$(document).ready(startLoop);
</script>
<header id="header">
<div class="container">
<center><img src="Images/Title.png" alt="Title"></div>
</center>
</header>
<center>
<nav>
<?php
echo "<p> Welcome ".$_SESSION['client_name']."</p>";
//create connection
$con = new mysqli("localhost", "student", "student", "cib4003_h00233671_at");
if ($con->connect_errno) { //failed
echo "Failed to connect to MySQL: (" . $con->connect_errno . ") " . $con->connect_error;
}?>
<div class="wrapper">
<ul id="category" >
<li>Home</li>
<li>Products</li>
<li>View Cart</li>
<li>About</li>
<li>Settings</li>
<li>Logoff</li>
</ul>
</nav>
</div>
</center>
<main>
<h3>Available Products</h3>
<?php
$product = $_GET["RID"];
$_SESSION["product_name_RID"] = $_GET["RID"];
$sql="SELECT * FROM products,reviews WHERE products.Product_Name = '$product' AND reviews.Product_Name = '$product'";
//$sql="SELECT * FROM reviews WHERE Product_Name = '$product'";
// $sql="SELECT * FROM pizza,pizzacart WHERE pizza.Pizza_ID=pizzacart.Pizza_ID AND pizzacart.client_ID=".$_SESSION['client_ID'];
//echo "connected to DB";
//run SQL query
$result = mysqli_query($con,$sql);
//output result
if(mysqli_num_rows($result)==0) //no records found
{
$sql="SELECT * FROM products WHERE Product_Name = '$product'";
$result = mysqli_query($con,$sql);
// echo "<p>no records in DB".mysqli_num_rows($result)."</p>";
// echo "<p><a href=products.php></a>";
// link has been disable because i am using the <a for something else so i can't force the image to be in the center when using <a
// so the result will only be image that tell the customers no products found click all or search with different data
?>
<table class="table-style-one">
<tr>
<th>Product Image</th>
<th>Product Name</th>
<th>Description</th>
<th>Product Type</th>
<th>Console Type</th>
</tr>
<?php
while($row = mysqli_fetch_array($result)) { //loops through records
echo "<tr>";
echo "<td><img src='".$row['picture']."'/>";
echo "<td>".$row['Product_Name']."</td>";
echo "<td>".$row['Description']." <center><b><br>".$row['Trailer']."<br></b></center></td>";
echo "<td>".$row['Product_Type']."</td>";
echo "<td>".$row['Console_Type']."</td>";
echo "</tr>";
}
//end of loop
echo "</table>";
echo "<p>No Reviews available for this product.<br> To post a review of this product, fill up the below form.</p>";
//end of else
}
else
{
?>
<table class="table-style-one">
<tr>
<th>Product Image</th>
<th>Product Name</th>
<th>Description</th>
<th>Product Type</th>
<th>Console Type</th>
</tr>
<?php
while($row = mysqli_fetch_array($result)) { //loops through records
echo "<tr>";
echo "<td><img src='".$row['picture']."'/>";
echo "<td>".$row['Product_Name']."</td>";
echo "<td>".$row['Description']." <center><b><br>".$row['Trailer']."<br></b></center></td>";
echo "<td>".$row['Product_Type']."</td>";
echo "<td>".$row['Console_Type']."</td>";
echo "</tr>";
echo "<br>";
?>
<?php
while($row = mysqli_fetch_array($result)) {
echo "<table class=table-style-one align=center>";
// echo "<tr><th>Review ID</th><td>".$row['Review_ID']."</td></tr>";
echo "<tr><th>Review By:</th><td>".$_SESSION['client_name']."</td></tr>";
echo "<tr><th>Review Title</th><td>".$row['Review_Title']."</td></tr>";
echo "<tr><th>Rate:</th><td>".$row['Review_Rate']."/5</td></tr>";
echo "<tr><th>Review</th><td colspan=2>".$row['Review']."</td></tr>";
echo "<tr><th>Submitted On</th><td>".$row['Review_Date']."</td></tr>";
echo "<br>";
?>
<?php
}
//end of loop
echo "</table>";
//end of else
}
}
?>
<table class="table-style-one" align="center">
<tr>
<form method="POST" action="submitreview.php">
<!--<th>Product Name:</th><td> <input type="text" size="30" id="ReviewTitle" name="ReviewTitle" pattern=".{5,}" required title="5 characters minimum" placeholder="Review Title"></td> -->
<th>Review Title:</th><td> <input type="text" required size="30" id="ReviewTitle" name="ReviewTitle" pattern=".{5,}" required title="5 characters minimum" placeholder="Review Title"> </td>
<th>Rate: </th>
<td>
<select name="Review_Rate" required>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</td>
<tr>
<td colspan="4">
<textarea name="WriteReview" id="WriteReview" required rows="10" cols="50" wrap="physical" placeholder="Write your Review here" style="margin: 0px; width: 437px; height: 150px;"></textarea>
</td>
</tr>
<td align="center" colspan="2"><input type="submit" value="submit"></td>
<td colspan="2"><input type="Reset"></td>
</form> </tr>
</table>
</h2>
<br>
<br>
<br>
</main>
</body>
<footer>
<p>Made by Humaid Al Ali - H00233671</p>
<div id="google_translate_element"></div><script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: 'en', layout: google.translate.TranslateElement.InlineLayout.HORIZONTAL, multilanguagePage: true}, 'google_translate_element');
}
</script><script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
</footer>
</html>
and here the php file where I insert the review into the table
<?php
if (!isset($_SESSION)) {session_start();} //start session
if (!isset($_SESSION['client_ID'])) {
//echo "<script>alert('not logged in');</script>";
header("Location: index.html" );
}
?>
<?php
//new connection
$con = new mysqli("localhost", "student", "student", "cib4003_h00233671_at");
if ($con->connect_errno) { //failed
echo "Failed to connect to MySQL: (" . $con->connect_errno . ") " . $con->connect_error;
}
//success
//if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// run sql
$sql ="INSERT INTO `cib4003_h00233671_at`.`reviews`(`Review_ID`, `Product_Name`, `client_ID`, `Review_Title`, `Review_Rate`, `Review`) VALUES (NULL, '".$_SESSION['product_name_RID']."', '".$_SESSION['client_ID']."', '".$_POST["ReviewTitle"]."', '".$_POST['Review_Rate']."', '".$_POST['WriteReview']."');";
if ($con->query($sql) === TRUE) {echo "<h3> New record created successfully</h3>";
header('Location: '. $_SERVER['HTTP_REFERER'] );
} else {
echo "Error : " . $sql . "<br>" . $con->error;
}
$con->close();
?>
Problem:
As the images display, the first review will never show up, only starting from the second and above
That's because you're fetching the first row which includes the first review but you don't display it, rather you starting fetching next reviews and display them. Look at the two conditions in while block inside the else block.
Solution:
To display reviews, you should do something like this:
<?php
// your code
if(mysqli_num_rows($result)==0){
// your code
}else{
echo "<table class='table-style-one'>";
echo "<tr>";
echo "<th>Product Image</th>";
echo "<th>Product Name</th>";
echo "<th>Description</th>";
echo "<th>Product Type</th>";
echo "<th>Console Type</th>";
echo "</tr>";
// fetch first row, which also contains first review
$row = mysqli_fetch_array($result);
echo "<tr>";
echo "<td><img src='" . $row['picture'] . "'/>";
echo "<td>" . $row['Product_Name'] . "</td>";
echo "<td>" . $row['Description'] . "<center><b><br>" . $row['Trailer'] . "<br></b></center></td>";
echo "<td>" . $row['Product_Type'] . "</td>";
echo "<td>" . $row['Console_Type'] . "</td>";
echo "</tr>";
echo "</table>";
echo "<table class=table-style-one align=center>";
echo "<tr>";
echo "<th>Review ID</th>";
echo "<th>Review By:</th>";
echo "<th>Review Title</th>";
echo "<th>Rate:</th>";
echo "<th>Review</th>";
echo "<th>Submitted On</th>";
echo "</tr>";
do{
// display first review and then fetch rest of the reviews
echo "<tr>";
echo "<td>" . $row['Review_ID'] . "</td>";
echo "<td>" . $_SESSION['client_name'] . "</td>";
echo "<td>" . $row['Review_Title'] . "</td>";
echo "<td>" . $row['Review_Rate'] . "/5</td>";
echo "<td colspan=2>" . $row['Review'] . "</td>";
echo "<td>" . $row['Review_Date'] . "</td>";
echo "</tr>";
}while($row = mysqli_fetch_array($result));
echo "</table>";
?>
</table>
<?php
}
// your code
?>
The problem looks to me to be in your SQL query. It looks as though your SQL query should actually be doing a join on the related column to bring together data across two different tables
$sql="SELECT *
FROM products AS p,
JOIN reviews AS r
ON p.Product_Name = r.Product_Name
WHERE products.Product_Name = '$product'";
But I think the easiest solution would be to run another query within the table output loop where you get the reviews for the product name you are currently outputting and loop over those.
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>
Hello to everyone I'm new to this and I'm trying to make a simple dynamic HTML. I have written the following code but it seems dose not work. Can someone help me. Because All I get is the following line
$row[name]"); echo (""); echo (""); echo (""); echo (""); } ?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table>
<tr>
<td align="center">EDIT DATA</td>
</tr>
<tr>
<td>
<table border="1">
<?
mysql_connect("localhost","user","pass");
mysql_select_db("Computers");
$order = "SELECT * FROM vnc";
$result = mysql_query($order);
while ($row=mysql_fetch_array($result)){
echo ("<td>$row[name]</td>");
echo ("<td>$row[department]</td>");
echo ("<td>$row[phone]</td>");
echo ("<td>$row[ip]</td>");
echo ("<td>Edit</td></tr>");
}
?>
</table>
</td>
</tr>
</table>
</body>
</html>
Thank you in advance
This should work for you
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table>
<tr>
<td align="center">EDIT DATA</td>
</tr>
<tr>
<td>
<table border="1">
<?php
mysql_connect("localhost","user","pass");
mysql_select_db("Computers");
$order = "SELECT * FROM vnc";
$result = mysql_query($order);
while ($row=mysql_fetch_array($result)){
echo "<td>" . $row[name] . "</td>
<td>" . $row[department] . "</td>
<td>" . $row[phone] . "</td>
<td>" . $row[ip] . "</td>
<td>Edit</td></tr>";
}
?>
</table>
</td>
</tr>
</table>
</body>
</html>
I'm not sure why you used the parenthesis, but what you're looking for is something similar to this:
echo "<td>" . $row[name] . "</td>";
Anything written inside the quotations will be displayed explicitly, which is why you have to end the quotes, add a period, then give the array, followed by another period and opening quotes.
The
<? should be <?php .... It apprears that short tags is turned off on your webserver. also echo does not need parentheses
The correct syntax is this:
echo "<td>".$row['name']."</td>";
If your queries are working well, it should print something.
echo ("<td>Edit</td></tr>");
This line is problematic. You're trying to print double quotes in a double-quoted string. Try using single quotes instead.
There are some sintax error in your code you don't need to use parethesis
echo "<td>$row[name]</td>";
echo "<td>$row[department]</td>";
echo "<td>$row[phone]</td>";
echo "<td>$row[ip]</td>";
Also this line needs to be fixed because of double quotes used in anchor, you can either change to single quote or escape it with a backslash
echo '<td>Edit</td>';
Or
echo "<td>Edit</td>";
I would finally advise you to switch to long tags <?php
I want to display all users that a "super" user is responsible for. Then the "super" user can send a comment to any of the users by clicking on their user id.
The first part of showing all the users is working fine! My problem is in sending a comment by the super user. I want to store the user id (ie suid) in the database. So I think to use the $_Get function. But when I tried it, nothing stores in the database. I think I made a mistake in it. So can anyone help me on that?
This is the code that will show all users to the super user:
<?php
session_start();?>
<?php
require("noCache.php");
$uid=$_SESSION['uid'];
?>
<html>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Send a comment</title>
<meta charset="utf-8">
<link rel="stylesheet" href="css/reset.css" type="text/css" media="all">
<link rel="stylesheet" href="css/layout.css" type="text/css" media="all">
<link rel="stylesheet" href="css/style.css" type="text/css" media="all">
<script type="text/javascript" src="js/jquery-1.4.2.js" ></script>
<script type="text/javascript" src="js/cufon-yui.js"></script>
<script type="text/javascript" src="js/cufon-replace.js"></script>
<script type="text/javascript" src="js/Myriad_Pro_400.font.js"></script>
<script type="text/javascript" src="js/Myriad_Pro_700.font.js"></script>
<script type="text/javascript" src="js/Myriad_Pro_600.font.js"></script>
</head>
<body>
<div class="main">
<header>
<div class="wrapper">
<h1> Biz</h1>
</div>
<nav>
<ul id="menu">
<li class="alpha"><span><span>Home</span></span></li>
<li><span><span>About</span></span> </li>
<li><span><span>Projects</span></span></li>
<li><span><span>Contacts</span></span></li>
<li class="omega"><span><span>Services</span></span></li>
</ul>
</nav>
</br></br>
</header>
<head>
<!-- CSS Stylesheet -->
<style type="text/css">
html{
}
body{
text-align:center;
}
</style>
</head>
<?php
$dbh=mysql_connect("localhost", "root", "hahaha1") or die (mysql_error());
mysql_select_db ("senior");
$result = mysql_query("SELECT * FROM sensorusers where uid=$uid");
echo "<html><body>";
echo "<table cellspacing=10 cellpadding=5 ><tr> <th>ID</th><th>Name</th><th>Username</th><th>Password</th><th>Date of Registeration</th><th>Phone</th></tr>";
while ($row = mysql_fetch_array($result))
{ echo "<form method='post' action='sendcomment.php'>";
echo "<tr><td><input type='submit' name='suid' value='".$row['suid']."' /></td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['dusername'] . "</td>";
echo "<td>" . $row['password'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "<td>" . $row['phone'] . "</td></tr></form>";
$_GET['suid'] = $row['suid'];
}
echo "</table></body></html>";
mysql_close($dbh);
?>
<html>
<body>
<!-- CSS Stylesheet -->
<style type="text/css">
body {
font-family:"Andalus"
font: 16px ;
color:black;
padding: 30px 5px;
text-align: center;
}
</style></body></html>
Here is the part that I want to ask about:
echo "<table cellspacing=10 cellpadding=5 ><tr> <th>ID</th><th>Name</th><th>Username</th><th>Password</th><th>Date of Registeration</th><th>Phone</th></tr>";
while ($row = mysql_fetch_array($result))
{ echo "<form method='post' action='sendcomment.php'>";
echo "<tr><td><input type='submit' name='suid' value='".$row['suid']."' /></td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['dusername'] . "</td>";
echo "<td>" . $row['password'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "<td>" . $row['phone'] . "</td></tr></form>";
$_GET['suid'] = $row['suid'];
}
Solution:
Thank you all for helping. I fixed the code. I used method post to save the value of suid the first time. Then I print it as a hidden input. Finally I save the value of the hidden input in the sql and it works!
you have POST I DONT SEE GETin your code , and its depend on your html inputs (u didnt post them)if u make method GET or POST.
if your method is GET then you use GET
but try use this
if(isset($_POST['submit'])){
instead of
if($submit){
EDIT .
you are using method='post'
then you must use POST not GET
EDIT2:
you have an error in your sql , you used VALUE and it should be VALUES
instead of this
$place="INSERT INTO comments VALUE
replace it by
$place="INSERT INTO comments (columns here ,..., ,..) VALUES
How to use $_GET:
Put the data in the URL like so:
sendcomment.php?suid=blahblahblah
Then you can use $_GET, like so:
$suid = $_GET['suid']
Currently your code uses POST to send suid
Or change your form method.
echo "<form method='post' action='sendcomment.php?suid=".$row['suid']."'>";
There are multiple issues in your code. I will try to list the biggest ones, but may still miss some.
Code 1 -
Issue 1-
You have multiple <html></html>,<head></head>, and <body></body> blocks.
<html>
...
<head>
...
</head>
<body>
...
<head>
...
</head>
...
echo "<html><body>";
...
echo "...</body></html>";
...
<html>
<body>
...
</body>
</html>
Issue 2-
Your <form> is around a <td> block, which is invalid, so it will not POST properly. It either needs to be around the table <form><table></table></form>, or inside a cell <td><form></form></td>.
echo "<table cellspacing=10 cellpadding=5 ><tr> <th>ID</th><th>Name</th><th>Username</th><th>Password</th><th>Date of Registeration</th><th>Phone</th></tr>";
while ($row = mysql_fetch_array($result))
{ echo "<form method='post' action='sendcomment.php'>";
echo "<tr><td><input type='submit' name='suid' value='".$row['suid']."' /></td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['dusername'] . "</td>";
echo "<td>" . $row['password'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "<td>" . $row['phone'] . "</td></tr></form>";
$_GET['suid'] = $row['suid'];
}
echo "</table></body></html>";
Issue 3-
You are misusing $_GET and it is outside your <form></form> tags. $_GET is used to get value from the url.
$_GET['suid'] = $row['suid'];
Code 2-
Issue 1-
You are setting $id1=$_GET["suid"];, but in your form in Code #1, you are using method="post".
$id1=$_GET["suid"];
Issue 2-
When you are posting from Code #1 to Code #2 (<form><input type='submit' name='suid' value='".$row['suid']."' /></form>), you are only sending name='suid', so all your $_GET & $_POST vars will not be set to be used in the INSERT-
$id1=$_GET["suid"];
...
$name=$_POST['sent_by'];
$id=$_POST['hidden_id'];
$id2=$_POST['hidden_id2'];
$message=$_POST['message'];
$submit= $_POST['submit'];
...
Issue 3-
You have errors in you query. It should be VALUES, not VALUE, you should include the columns before `INSERT INTO comments (id,name,message,receiver,sender,date,time) VALUES ('','$name','$message','$id','$id1','$date','$time')
$place="INSERT INTO comments VALUE('','$name','$message','$id','$id1','$date','$time')";
$run = mysql_query("$place");
Issue 4-
All your value= in your form is missing the quotes '' around the values.
<form action="sendcomment.php" method="post">
<input type ='hidden' name='hidden_id' value = <?php print $uid; ?> >
<input type ='hidden' name='hidden_id2' value = <?php print $id1; ?> >
Name : <input type ='name' name='sent_by' value = <?php print $username; ?>></br>
Message: <textarea name='message'></textarea></br>
<input type='submit' value='submit' name="submit" /></br>
</form>
I know that you have accepted an answer, but you have a lot of code issues to still address. Each of these will cause you issues with your form and inserting into your database. Plus they will cause you more issues.
Just simply this
$id1=$_GET["suid"];
replace with
$id1=$_POST["suid"];
When using $_GET varible shuld be in the url.
When using $_POST variable isn't shown in url