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><a href="index.php" id="logo"> Biz</a></h1>
</div>
<nav>
<ul id="menu">
<li class="alpha"><a href="index.php"><span><span>Home</span></span></a></li>
<li><a href="About.html"><span><span>About</span></span> </a></li>
<li><a href="Projects.html"><span><span>Projects</span></span></a></li>
<li><a href="Contacts.php"><span><span>Contacts</span></span></a></li>
<li class="omega"><a href="Services.html"><span><span>Services</span></span></a></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
POSTI DONT SEEGETin 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
instead of
EDIT .
you are using
method='post'then you must use
POSTnotGETEDIT2:
you have an error in your sql , you used
VALUEand it should beVALUESinstead of this
replace it by