i have a system where a user searches for a film and reviews appear on a page with a button next to each review. The button can be selected to look at the individual review but i basically want a button that when selected it will look at all reviews on one page, the code i am using for the individual review is this
<?php
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);
$searchfilm=$_POST['searchfilm'];
//Connect to database
//Filter search
$searchfilm = strtoupper($searchfilm);
$searchfilm = strip_tags($searchfilm);
$searchfilm = trim ($searchfilm);
$query = mysql_fetch_assoc(mysql_query("SELECT filmreview FROM review WHERE id = '$id'"));
$data = mysql_query("SELECT film.filmname, review.filmreview, review.reviewtitle, review.id FROM film, review WHERE film.filmid = review.filmid AND filmname = '$searchfilm'");
while($row = mysql_fetch_assoc($data))
{
// echo $row['filmname'];
// echo "<b>Film Name:</b> " .$searchfilm;
echo "<table border=\"2\" align=\"left\">";
echo "<tr><td>";
echo "<b>Review Title:</b> " .$row['reviewtitle'];
echo "<tr><td>";
echo $row['filmreview'];
echo "<p>";
echo "<form method='post' action='analyse1.php'>";
echo "<input type='hidden' name='reviewid' value='".$row['id']."'>";
echo "<input type='submit' name='submit' value='Analyse'>";
echo "</form>";
echo "</table>";
}
?>
you can fetch film reviews since film id inside review table
you could modify your code above and add another form to get all film reviews
when user click on a button it will redirect him/her to film_reviews.php
<?php
if(isset($_POST['submit']) && $_POST['submit'] == "getAllReviews"){
$filmID = mysql_real_escape_string($_POST['filmid']);
$sql = "SELECT * FROM review WHERE filmid = '$filmID'";
$res = mysql_query($sql);
if(is_resource($res)){
while($row = mysql_fetch_array($res)){
echo "<p>".$row['reviewtitle']."</p>";
echo "<p>".$row['filmreview']."</p>";
}
}
}
Related
i want to send the cookie to another page that store the id from database retrieve value .
the thing is it is send to the next page and also working. there is book record retrieve from database with image and one button . i have store the id of the book. but when it goes to next page it displays first book id no matter which book i select by the button
this is code where i set cookie
echo "<form action='issue.php' method='get'>";
while ($row= mysqli_fetch_array($result)) {
echo "<div id='img_div'> ";
echo "<img src='books/".$row['image']."'>";
// echo "</div>";<div id='text'>
echo " <table>";
echo "<tr><td> NAME</td><td> ".$row['name']."</td></tr>";
echo "<tr><td> AVAILABILITY</td><td> ".$row['availabilty']."</td></tr>";
echo "<tr><td> CATEGORY</td><td> ".$row['category']."</td></tr>";
echo "<tr><td colspan='2'>
<button type='submit' name='issue'>issue</button></td></tr>";
echo "</table>";
echo "</div><br/>";
if (isset($_GET['issue'])) {
# code...
$bookid=$row['isbn'];
setcookie("bid",$bookid);
if(!isset($_COOKIE['bid'])){
echo "COOKIE NOT SET";
}
else{
echo "COOKIE SET SUCCESSFULLY";
}
}
And this is code where i access the cookie next page
$id=$_SESSION['user']['username'];
$query = "select id from user_account where username='$id'";
$result=mysqli_query($con,$query);
$row= mysqli_fetch_assoc($result);
$uid=$row['id'];
// if (mysqli_num_rows($results) == 1) {
// $row= mysqli_fetch_assoc($results);
//
// }
$bookid=$_COOKIE['bid'];
echo "$uid";
echo "<br/>";
echo "$bookid";
$query = "INSERT INTO issue (bookid, userid)
VALUES ('$bookid', '$uid')";
mysqli_query($con, $query)or die(mysqli_error($con));
I have managed to create dropdown from Mysql column and also get query result with get method but here webpage is directed to other page when hit button.
I am looking to get query output with some default option set in dropdown when page loads or want query result on same page reloading it again when user changes option.
Any help will be appreciated.
Code on main page for dropdown:
$result = $conn->query("SELECT DISTINCT nx_version FROM workflow1 ORDER BY id");
echo "<form action='process.php' method='get'>";
echo "<html>";
echo "<body>";
echo "<p></p>";
echo "<center>";
echo "<strong> Select Base Verison To Compare With : </strong>";
echo "<select name=nx_version>";
while ($row = $result->fetch_assoc()) {
unset($nx_version);
$nx_version = $row['nx_version'];
echo '<option value>'.$nx_version.'</option>';
}
echo "</select>";
echo " <button type='submit'>See items</button>";
echo "</center>";
echo "</body>";
echo "</html>";
echo "<p></p>";
echo "<form>";
Code I wrote when hit button and gives query output (in process.php):
$nx_version = $_GET['nx_version']; // The name attribute of the select
$query = "SELECT step1 FROM workflow1 WHERE nx_version = '$nx_version' ORDER BY id DESC";
$query1 = mysqli_query($conn, $query);
$array = Array();
while($result1 = $query1->fetch_assoc()) {
$array[] = $result1['step1'];
}
print_r($array);
process.php file should be like this -
<?php
session_start();
$nx_version = $_GET['nx_version']; // The name attribute of the select
$query = "SELECT step1 FROM workflow1 WHERE nx_version = '$nx_version' ORDER BY id DESC";
$query1 = mysqli_query($conn, $query);
$array = Array();
while($result1 = $query1->fetch_assoc()){
$array[] = $result1['step1'];
}
$_SESSION['data'] = $array;
// storing the data as session
header("location:main_page.php");
?>
Now get back the data from session in your main page by adding this-
$array = $_SESSION['data'];
I'm doing a table where the user can introduce the number of the products he want to buy and submit them pressing the submission button. I build the content of the table using a sql query (SELECT) setting the name of the input(text) like in the code below. My problem is that, probably, the form doesn't submit nothing because, if a check the variable $_REQUEST with isset(), it return FALSE. Someone can help me? Thanks!
$con=mysqli_connect("localhost","uPower","","info");
if (mysqli_connect_errno())
printf("<p>Error!!: %s<p>\n", mysqli_connect_error());
else{
$query = "SELECT * FROM product";
$result = mysqli_query ($con, $query);
echo "<form name=\"buy\" action=\"confirm.php\" method=\"POST\" onSubmit=\"return checkInputQty(qty.value) \">";
echo"<table>";
echo"<tr><th>Product name</th><th>Price</th><th>Available</th><th>Qty</th></tr>";
while ($row = mysqli_fetch_assoc($result)){
$pid = $row["pid"];
$name = $row["name"];
$qty = $row["qty"];
$price = ($row['price'])/100;
echo"<tr><th>$name</th><th>".number_format($price,2,',', '')." €</th><th>$qty</th><th><input type=\"text\" id=".$pid." name=".$name."></th></tr>";
}
echo"</table>";
echo "<p><input type=\"submit\" value=\"BUY\" class=\"button\" ><input type=\"button\" onclick=\"clearText()\" value=\"DELETE\" class=\"button\"></p>";
echo "</form>";
mysqli_free_result($result);
mysqli_close($con);
there is the part of confirm.php. It is a function in head that i called from the body of the page. It does a summary of what the user selected to buy. The control with if(isset($_REQUEST)) is false, so the page is blank....
<?php
function checkInputQty(){
$con=mysqli_connect("localhost","uPower","","info");
if (mysqli_connect_errno())
echo "error DB";
else{
$query = "SELECT * FROM product";
$result = mysqli_query ($con, $query);
while($row = mysqli_fetch_assoc($result)){
$nome = $row["name"];
if(isset($_REQUEST["$name"])){
$qty = trim($_REQUEST['$row["name"]']);
if($qty>0 && $qty<=$row["qty"]){
$new_qty = $row["qty"]-$qty;
$query2 = "UPDATE product SET qty = '$new_qty' WHERE qty = '".$row["qty"]."' ";
$result2 = mysqli_query ($con, $query2);
if($result){
echo "<table>";
echo "<tr><th>Name</th><th></th><th>Price</th></tr>";
do_content($row["name"],$qty,$row["price"]/100);
echo "</table>";
}
else
echo "Error!";
}
}e
}
mysqli_free_result($result);
}
mysqli_close($con);
}
?>
<?php
function do_content($name,$to_buy,$price){
echo "<tr><th>$name</th><th>$to_buy</th><th>$price</th></tr>";
}
?>
I'm having problems to find how to create an hyperlink in a table column result and then, on click, open another page with all fields (textboxes) filled. Imagine when a click an ID, i do a select * from table where column_id = ID... Is there a way to do it?
Thanks.
Best regards
I'm not completely sure what you are asking, but this may help you a bit.
First make a Javascript.
<script type="text/JavaScript">
function selectID() {
var ID = document.getElementById("ID").value;
document.location.href ="yoursite.php?ID="+ID;
}
</script>
Then connect to your database to query the table for a link ID (or more) for example by changing the variable $value.
<?php
//Connect to database
mysql_connect("host", "user", "pass");
mysql_select_db("db_name");
$value = 'something';
$ID = $_GET['ID'];
if (!$ID) {
$ID = 0;
}
if ($ID == 0) {
$query = "SELECT * FROM table WHERE `column_1` = '$value'";
$result = mysql_query($query);
echo "<table>";
while($myrow = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>";
echo "ID";
echo "</td>";
echo "</tr>";
}
echo "</table>";
}
elseif ($ID > 0) {
$query2 = "SELECT * FROM table WHERE `column_id` = '$ID'";
$result2 = mysql_query($query2);
while($myrow2 = mysql_fetch_array($result2)) {
$value1 = $myrow2['column_1'];
$value2 = $myrow2['column_2'];
}
echo "<form type=\"GET\" action=\"$PHP_SELF\">";
echo "<input type=\"text\" id=\"ID\" name=\"ID\" value=\"$ID\"><br>";
echo "<input type=\"text\" id=\"value1\" name=\"value1\" value=\"$value1\"><br>";
echo "<input type=\"text\" id=\"value2\" name=\"value2\" value=\"$value2\"><br>";
echo "<input type=\"hidden\" id=\"search\" name=\"search\" value=\"searching\">";
echo "<input type=\"submit\" id=\"submitbutton\" name=\"submitbutton\" value=\" Search \">";
echo "</form>";
}
?>
i try to store the booking booths into database based on user selection, there are 10 check boxes for each booths and user can choose which day they want to reserve booths. For each check box has it own field in database, if user choose booth A01, D1 and D2, when he press reserve button, it will insert value into D1 and D2. But I dont know how to get the checked checkbox value to store in database
my booth interface
http://i.imgur.com/umYcI.gif
my table structure
http://i.imgur.com/vKh6R.gif
My coding
<?php
session_start();
if ( !isset($_SESSION['AUTHORIZED_USERNAME']) || empty($_SESSION['AUTHORIZED_USERNAME']) ) {
header("location:index.php");
}else{
$user=$_SESSION['AUTHORIZED_USERNAME'];
}
include('db.php');
if($_REQUEST){
$id = $_REQUEST['search_category_id'];
$query2 = mysql_query("SELECT filenameBig, filename, url FROM eventinfo where eventID ='$id'");
$row = mysql_fetch_array($query2, MYSQL_ASSOC);
if($id == -1)
{
echo "<style type='text/css'>#btn_submit{visibility:hidden}</style>";
}
else{
/*echo "<a href='{$row['url']}'>Click me!</a>";*/
echo "<p><br><img src='{$row['filename']}' alt='' /></p>";
echo "<p></p>";
echo "<p align='right'><a href='$row[filenameBig]' target='_blank'>Click to view large image</a></p>";
echo "<hr size='1'>";
echo "<div style='padding-left:4px;' align='left'><strong>Booths Listing</strong>";
echo "<p></p>";
$query = "select boothAlias, totalDay from booths, eventinfo where booths.eventID=eventinfo.eventID && booths.eventID = ".$id."";
$_SESSION['EVENT_ID']=$id;
$result = mysql_query($query);
$result2= mysql_query($query);
echo "<table border='0' style='width:400px;table-layout:fixed' >";
$rows2 = mysql_fetch_array($result);
$Day=$rows2['totalDay'];
echo "<table>";
for ($day = 0; $day <= $Day; ++$day) {
if($day==0){
echo "<th>Booth</th>";
}else{
echo "<th>D".$day."</th>";
}
}
while($rows = mysql_fetch_array($result2)){
$boothAlias=$rows['boothAlias'];
$totalDay=$rows['totalDay'];
echo "<tr><td>$boothAlias</td>";
for ($day2 = 1; $day2 <= $totalDay; ++$day2) {
echo "<td><input name='day2[]' type='checkbox' value='$day2' /></td>";
}
echo "</tr>";
}
echo "</table>";
}
}
?>
I think that SET type would be good solution for this.
http://dev.mysql.com/doc/refman/5.0/en/set.html