Ok i have created a forum posting page where they input the data then its stored in a table then echoed out on a different page with links but i want the links to generate a page with the post then i can allow the user to comment but i have an idea for the comments i just need help with the generation of the page. The code where the user can click...
$connect = mysql_connect("localhost", "root", "123");
$database = mysql_select_db('phplogin');
$data = "SELECT * FROM forum ORDER BY time DESC";
$result = mysql_query($data);
if($connect) {
while($row = mysql_fetch_array($result)){
echo "<div class='post'>" . "<div class='leftside'>" . "<h3 class='by'>" . $row['user'] . "</h3>" . "<h6 class='when'>" . $row['time'] . "</h6>" . "</div>" . "<div class='middle'>" . "<h3 class='questiontitle'>" . htmlspecialchars($row['title']) . "</h3>" . "<p class='description'>" . htmlspecialchars($row['description']) . "</p>" . "</div>" . "<div class='rightside'>" . "<a href='#' class='answer'>Answer it</a>" . "</div>" . "</div>";
}
Related
I am using php and mysql to display all the user information of different users and i have a button which gets the id which will be redirected to another page and the id will be displayed in the url. What i am trying to do now is display the user information with the selected id on the redirected page
$sql = "SELECT * FROM users";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_array($result)){
echo "<div class='users-data'>";
echo "<p>" . $row['username'] . "</p>";
echo "<p>" . $row['full_name'] . "</p>";
echo "<p>" . $row['age'] . "</p>";
echo "<p>" . $row['gender'] . "</p>";
echo "<p>" . $row['email'] . "</p>";
echo "<p>" . $row['medical_condition'] . "</p>";
echo "<img src=images/".$row['image'] ."/>";
echo '<td><a href="view-user-information.php?id='.$row['id'].'"><button>View Details</button></td>';
echo "</div>";
}
// Free result set
mysqli_free_result($result);
} else{
echo "No records matching your query were found.";
}
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
Use this code;
if(isset($_GET['u'])){
$id = $_GET['u'];
$sql = "SELECT * FROM `users` WHERE `id` = '$id'";
$result = mysqli_query ($link,$sql);
$row = mysqli_fetch_assoc($result);
echo "<div class='users-data'>";
echo "<p>" . $row['username'] . "</p>";
echo "<p>" . $row['full_name'] . "</p>";
echo "<p>" . $row['age'] . "</p>";
echo "<p>" . $row['gender'] . "</p>";
echo "<p>" . $row['email'] . "</p>";
echo "<p>" . $row['medical_condition'] . "</p>";
echo "<img src=images/".$row['image'] ."/>"
}
else
{
//you can redirect it to back to the previous page if no id exist in url;
header("LOCATION:index.php"); // change the index.php to your privious page url
}
I am trying to make a button on a page that prints out data from the database and then you can press 2 different buttons, one that deletes them from the database and the other one inserts it into another table in the database and deletes the data from the database, but it keeps inserting it twice into the new table and I have no clue why, this here prints out the data and session variables + buttons:
if(!isset($_POST['orderby'])) {
foreach ($requests as $row) {
echo "<div class='requests'>" . "<li class='refunds'>" . "Palauttajan nimi: ".
$row['customer_name'] . "</br>" ."Palautettavat tuotteet: ".$row['product_name']."<br> "."Määrä: ".
$row['product_qty'] . " "
. "<br>Kommentti: " . $row['comment'] . "<br> " . "Hinta: " . $row['refund_total'] . "€ " .
"<br>" . "Päivämäärä: " . $row['request_date'] . " " .
"<a class='right' href='admin-page?deleteid=" . $row['request_id'] . "'>Hylkää</a></li>" .
"<li class='refundaccepts'><a href='admin-page?acceptid=" . $row['request_id']
. "'>Hyväksy</a></li>" . "</div>";
$_SESSION['custname'] = $row['customer_name'];
$_SESSION['prodname'] = $row['product_name'];
}
} else {
foreach ($pergele as $row) {
echo "<div class='requests'>" . "<li class='refunds2'>" . "Palauttajan nimi: ".
$row['customer_name'] . "</br>" ."Palautettavat tuotteet: ".$row['product_name']."<br> "."Määrä: ".
$row['product_qty'] . " "
. "<br>Kommentti: " . $row['comment'] . "<br> " . "Hinta: " . $row['refund_total'] . "€ " .
"<br>" . "Päivämäärä: " . $row['request_date'] . " " .
"<a class='right' href='admin-page?deleteid=" . $row['request_id'] . "'>Hylkää</a></li>" .
"<li class='refundaccepts'><a href='admin-page?acceptid=" . $row['request_id']
. "'>Hyväksy</a></li>" . "</div>";
$_SESSION['custname'] = $row['customer_name'];
$_SESSION['prodname'] = $row['product_name'];
}
}
and this should insert it into the database once and delete the data from the old table:
if(isset($_GET['acceptid'])) {
$accept = $_GET['acceptid'];
$custname = $_SESSION['custname'];
$prodname = $_SESSION['prodname'];
/* Query to do whatever here */
$wpdb->insert("wp_acceptedrequests", [
"customer_name" => "$custname",
"name_product" => "$prodname",
"date" => date("Y/m/d/G:i:sa") ,
]);
$wpdb->query("DELETE FROM wp_refundrequests WHERE request_id = $accept");
}
What makes them insert twice and how do I prevent it from doing that?
I just ran into a similar situation where $wpdb inserts where being duplicated.
In my case it was happening if I was authenticated and browser inspector was open.
I have read a lot of submissions, I haven't been able to find an answer to my exact question.
I am filling out an HTML form that is sent into mysql database - I am good there.
The results are displayed using php in a html table. I would like the website URL to show as a hyperlink. Everything I do results in an error.
Does anyone know how I can update my code to allow for the website url to show as a hyperlink?
[$dbname = "seller";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT website, url, price, name, email FROM listing";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table><tr><th>Website</th><th>URL</th><th>Price</th><th>Contact Name</th><th>Email</th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row["website"]. "</td><td>" . $row["url"]. " </td><td>" . $row["price"]. "</td><td>" . $row["name"]. "</td><td> " . $row["email"]. "</td></tr>";
}
echo "</table>";
} else {
echo "0 results";
}
$conn->close();
?>]
Thanks
Have you tried this...
echo "<tr><td></td><td><a href='" . $row['url']. "'>" . $row['website']. "</a> </td><td>" . $row["price"]. "</td><td>" . $row["name"]. "</td><td> " . $row["email"]. "</td></tr>";
You could also just change 'Link to website' to " . $row["website"]. " for it to display the link
If you use an a tag it should work.
URL
echo "<tr><td><a href=\"{$row['url']}>{$row['website']}</a></td>...etc
You should also consider closing the tags to get a cleaner code:
<?php if ($condition) { ?>
<div>HTML code!</a>
<?php } ?>
Add an anchor tag <a href=""> inside the table data tag <td> inside your while loop.
Change this line:
echo "<tr><td>".$row["website"]."</td><td>".$row["url"]." </td><td>".$row["price"]."</td><td>".$row["name"]."</td><td> ".$row["email"]."</td></tr>";
Into this:
echo "<tr><td><a href='".$row["website"]."'>".$row["website"]."</a></td><td>".$row["url"]." </td><td>".$row["price"]."</td><td>".$row["name"]."</td><td> ".$row["email"]."</td></tr>";
That will be great if you can show me the error otherwise
Try this:
while($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row["website"]. "</td><td><a href='".$row["url"]."'>Link</a> </td><td>" . $row["price"]. "</td><td>" . $row["name"]. "</td><td> " . $row["email"]. "</td></tr>";
}
use this
echo '<tr><td>' . $row["website"]. '</td><td>'; echo $row["name"]; echo' </td><td>' . $row["price"]. '</td><td>' . '</td><td> ' . $row["email"]. '</td></tr>';
instead of
echo "<tr><td>" . $row["website"]. "</td><td>" . $row["url"]. " </td><td>" . $row["price"]. "</td><td>" . $row["name"]. "</td><td> " . $row["email"]. "</td></tr>";
use <a> tag, please see this link.
'' . $row['url'] . ''
I copied this code from a website for using ajax jquery pagination in php with mysql. I have a mysql table with 5 columns. I want to show all columns of the mysql table - not only two.
I edited the while loop but I cannot insert more columns. Please help me - I am new here and it may be difficult to understand my question. sorry in advance.
$query_pag_data = "SELECT * from ebook LIMIT $start, $per_page";
$result_pag_data = mysql_query($query_pag_data) or die('MySql Error' . mysql_error());
$msg = "";
while ($row = mysql_fetch_array($result_pag_data)) {
$htmlmsg=htmlentities($row['title']); //HTML entries filter
$msg .= "<li><b>" . $row['id'] . "</b> " . $htmlmsg . "</li>";
}
$msg = "<div class='data'><ul>" . $msg . "</ul></div>"; // Content for Data
I have linked all code
http://www.9lessons.info/2010/10/pagination-with-jquery-php-ajax-and.html
You only show $row['id'] and $row['title'], just add some extra with the row names ;)
Example:
$msg .= "<li><b>" . $row['id'] . "</b> <i>" . $row['another_row_name'] . "</i>" . $htmlmsg . "</li>";
while ($row = mysql_fetch_array($result_pag_data)) {
$htmlmsg=htmlentities($row['title']); //HTML entries filter
$msg .= "<li><b>" . $row['id'] . "</b> " . $htmlmsg . "</b> " . $row['somefield'] ."</li>";
}
The different values are accessed by the $row array so it depends on what your column names are for the 5 columns.
you might what something like
$msg .= "<li><b>" . $row['colname1'] . "</b> " . $row['colname2'] . " " . $row['colname3'] . <insert more columns here> . "</li>" ;
How can I have my php page only return rows with a certain id. I am working on a webpage set up like a blog, i post using mysql, i it to only show entries with the id of 1, so i don't have to worry about deleting old posts or having 100 posts on 1 page.
<?php
include ("includes/includes.php");
$blogPosts = GetBlogPosts();
foreach ($blogPosts as $post)
{
echo "<div class='post'>";
echo "<h2>" . $post->title . "</h2>";
echo "<p>" . $post->post . "</p>";
echo "<br />";
echo "<span>Posted By: " . $post->author . "  Posted On: " . $post->datePosted . "  Tags: " . $post->tags . "</span>";
echo "</div>";
}
?>
$result = mysql_query("SELECT * FROM entries WHERE id=1");