I have a form, where the user can fill in his name, email, address, phone, age and they can also order something like a product.
After submitting the form, all information will be stored in a database & also phpmail will send an email with all the information.
But after the submit, I want the user to see this :
This is your details: http://example.com/order.php?unique=21434612
On clicking link, they will see a page with all the information they had filled in the form. Like this :
```
Your name is : $name
Your age is: $age
etc.
```
So how can I generate auto HTML pages after submit?
write this code on the page where you want the detail.configure your details. like dbname and row details etc. yes this data is printed in table format. if you dont like it just remove it.
.
if(isset($_POST['submit']))
{
$con=mysqli_connect("localhost", "root", " ") or die (mysqli_error ());
// Select database
mysqli_select_db($con,"rdb") or die(mysqli_error());
// SQL query
$strSQL = "SELECT * FROM tablename";
// Execute the query (the recordset $rs contains the result)
$rs = mysqli_query($con,$strSQL);
print "
<table border=\"5\" cellpadding=\"5\" cellspacing=\"0\" style=\"border- collapse: collapse\" bordercolor=\"#808080\" width=\"100%\" id=\"AutoNumber2\" bgcolor=\"#C0C0C0\">
<tr>
<td width=100>ID:</td>
<td width=100>First Name</td>
<td width=100>Last Name</td>
<td width=100>Email</td>
<td width=100>User Name</td>
<td width=100>Password</td>
<td width=100>Date Of Birth</td>
<td width=100>Gender</td>
</tr>";
while($row = mysqli_fetch_array($rs))
{
print "<tr>";
print "<td>" . $row['id'] . "</td>";
print "<td>" . $row['fname'] . "</td>";
print "<td>" . $row['lname'] . "</td>";
print "<td>" . $row['Email'] . "</td>";
print "<td>" . $row['uname'] . "</td>";
print "<td>" . $row['password'] . "</td>";
print "<td>" . $row['dob'] . "</td>";
print "<td>" . $row['gender'] . "</td>";
print "</tr>";
}
print "</table>";
}
}
Related
I have a page which contains a table. The 'change_id' field contains hyperlinks which direct the user to a different page with an overview of that change_id's details.
'<td>' . $row['change_id'] . '</td>';
Now, just to test that the change_id is being received on the home2.php page, I used the following code:
<?php
include 'config.php';
$change_id=$_GET['change_id'];
print_r($_GET);
?>
This test successfully displayed the correct change id's:
Array ( [changeid] => 1006 )
Now, when I go to query the SQL Database using the change_id it doesn't work as desired.
<?php
include 'config.php';
$change_id=$_GET['change_id'];
$query1 = "SELECT * FROM `change_request_tbl` WHERE `change_id` = $change_id";
$result = mysqli_query($conn, $query1);
echo "<fieldset><legend><strong>New Requests:</legend></strong>
<table border=4 bordercolor=black class=table>
<tr>
<th>Change ID:</th>
<th>Customer Name:</th>
<th>Change Requestor:</th>
<th>Date CR raised:</th>
<th>CPM/Ticket:</th>
<th>Out of Hours:</th>
<th>Change Category:</th>
</tr>";
while ($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['change_id'] . "</td>";
echo "<td>" . $row['customer_name'] . "</td>";
echo "<td>" . $row['change_requestor'] . "</td>";
echo "<td>" . $row['date_cr_raised'] . "</td>";
echo "<td>" . $row['cpm_ticket'] . "</td>";
echo "<td>" . $row['out_of_hours'] . "</td>";
echo "<td>" . $row['category_of_change'] . "</td>";
echo "</tr>";
}
echo "</table></fieldset><br><br><br>";
?>
The table are headers are shown without any data. Any ideas on how to fix? Thanks in advance
You are setting $change_id to $_GET['change_id']
However you are passing $_GET the parameter name of changeid
If you change
$change_id = $_GET['change_id'];
To
$change_id = $_GET['changeid'];
It should work as expected :)
I want some information that is stored in my database to be an header in a table.
Basically its got a list of competitors down the side with theirs scores running in rows. Each competitor has their own row. At the top of the table is the name of the event they took part in. I cant manage to make the event name come from the database so got to edit the page each time I add a set of scores.
I have attempted as you will see in the code below;
<?php
require("db_connect.php");
$result = mysql_query("SELECT *, (ct1 + ct2 + ct3 + ct4 + ct5 + ct6) AS results FROM resultsopen WHERE ct='1'");
if(mysql_num_rows($result) == 0) { echo 'No competitors found'; } else {
echo "<table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\" align=\"center\">
<tr align=\"center\">
<td>Competitor</td>
<td>Member No</td>
<td>" . $row['cta'] . "</td>
<td>E2</td>
<td>E3</td>
<td>E4</td>
<td>E5</td>
<td>E6</td>
<td>E7</td>
<td>Overall</td>
<td></td>
</tr>";
$x=1;
while($row = mysql_fetch_array($result))
{
if($x%2): $rowbgcolor = "#FFFFFF"; else: $rowbgcolor = "#EEEEEE"; endif;
echo "<tr align=\"center\" bgcolor=\"" .$rowbgcolor. "\">";
echo "<td>" . $row['competitor'] . "</td>";
echo "<td>" . $row['memberno'] . "</td>";
echo "<td>" . $row['ct1'] . "</td>";
The line in question is <td>" . $row['cta'] . "</td>
The other lines are just text which I manually change each time.
I also know that mysql should be changed to mysqli but I am not confident in the change just yet.
I have a comments/testimonials form which saves data into MySQL database testimonials. Now through admin page I want to edit and enable or disable the comments which should show on my comments page. I don't know how to do this.
$query=mysql_query("SELECT * FROM `testimonials` ORDER BY
`t_id` DESC") or die(mysql_error());
if(!$query) {echo "Error!";} else { echo "Testimonials";}
echo "<table border='1'>
<tr>
<th>ID</th>
<th>Name,City</th>
<th>Email</th>
<th>Comment</th>
<th>Enable</th>
<th>Edit</th>
</tr>";
while($row = mysql_fetch_array($query))
{
echo "<tr>";
echo "<td>" . $row['t_id'] . "</td>";
echo "<td>" . $row['t_name'] . "</td>";
echo "<td>" . $row['t_email'] . "</td>";
echo "<td>" . $row['t_message'] . "</td>";
echo "<td>" . $row['enable'] . "</td>";
echo "<td>" . $row['edit'] . "</td>";
echo "</tr>";
}
echo "</table>";
Now I want a checkbox to show where $row['enable'] is and an Edit & Save/Update button where $row['edit'] is. When I click 'edit' button I can edit the fields and save them to Database. When I check the checkbox the value in 'enable' field pertaining to those particular comments in database is updated to 'True' so that those can display on the Testimonials page.
Please kindly look into my code and help me fix the errors in my code. only my first data displays on the table on my view page but the other data displays on the view page not on the table.
my image name and the image itself successfully inserted in my database and my image directory which i name "upload" but the image wont display on my view page.
<?php
include ("config.php");
// Retrieve data from database
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
echo "<table border='1'>
<tr>
<th>id</th>
<th>firstname</th>
<th>lastname</th>
<th>address</th>
<th>nationality</th>
<th>accountnumber</th>
<th>accounttype</th>
<th>balance</th>
<th>passport</th>
<th>username</th>
<th>passport</th>
<th>update</th>
<th>delete</th>
</tr>";
while($row = mysql_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['lastname'] . "</td>";
echo "<td>" . $row['address'] . "</td>";
echo "<td>" . $row['nationality'] . "</td>";
echo "<td>" . $row['account'] . "</td>";
echo "<td>" . $row['accounttype'] . "</td>";
echo "<td>" . $row['balance'] . "</td>";
echo "<td><h1><img src=\"upload/\" height=35 width=35 /> $row[id]</h1></td>";
echo "<td>" . $row['username'] . "</td>";
echo "<td>" . $row['password'] . "</td>";``
echo "<td>update</td>";
echo "<td>delete</td>";
echo "</table>";
// close while loop
}
?>
With a quick view, I see you are closing the table inside the while loop. You should change it for a
</tr>
and remember using the thead and tbody tags.
Close tbody and table after ending the loop.
This needs to be outside your while loop.
echo "</table>";
And
<img src=\"upload/\"
Is only pointing to the upload directory, you aren't specifying an actual image. Try something like:
echo "<td><h1><img src=\"upload/$row['image']\" height=35 width=35 /> $row['id']</h1></td>";
Moving the table closing tab out side the while loop will solve the first issue.
Change the code as follows to solve the image problem.
echo '<td><img src="upload/'.$row['your image name'].'" height=35 width=35 ></td>';
Your code should be as follows.
<?php
include ("config.php");
// Retrieve data from database
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
echo "<table border='1'>
<tr>
<th>id</th>
<th>firstname</th>
<th>lastname</th>
<th>address</th>
<th>nationality</th>
<th>accountnumber</th>
<th>accounttype</th>
<th>balance</th>
<th>passport</th>
<th>username</th>
<th>passport</th>
<th>update</th>
<th>delete</th>
</tr>";
while($row = mysql_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['lastname'] . "</td>";
echo "<td>" . $row['address'] . "</td>";
echo "<td>" . $row['nationality'] . "</td>";
echo "<td>" . $row['account'] . "</td>";
echo "<td>" . $row['accounttype'] . "</td>";
echo "<td>" . $row['balance'] . "</td>";
echo '<td><img src="upload/'.$row['your image name'].'" height=35 width=35 ></td>';
echo "<td>" . $row['username'] . "</td>";
echo "<td>" . $row['password'] . "</td>";``
echo "<td>update</td>";
echo "<td>delete</td>";
echo "</tr>";
// close while loop
}
echo "</table>";
?>
i am having a little difficulty in displaying my id info on my update page. i have two entries 6 and 7 if i click update on id 6 , it will show on my update page but if i click update on id 7, on the address bar, it will indicate that the id =7 but it will still show id 6 infos.
here is my display code that display data on my update page
<?ph
include ('config.php');
// Retrieve data from database
$sql="SELECT * FROM $tbl_name ";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
?>
secondly if i change data my update page, the change wont reflect on my view page.
<?php
include('config.php');
//This is the directory where images will be saved
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$address=$_POST['address'];
$nationality=$_POST['nationality'];
$accountnumber=$_POST['account'];
$accounttype=$_POST['accounttype'];
$balance=$_POST['balance'];
$username=$_POST['username'];
$password=$_POST['password'];
$id=$_POST['id'];
// update data in mysql database
$sql="UPDATE $tbl_name SET firstname='$firstname', lastname='$lastname', address='$address', nationality='$nationality',accountnumber='$account',accounttype='$accounttype',balance='$balance',username='$username',password='$password'
WHERE id='$id'";
$result=mysql_query($sql);
header ("Location: details.php");
?>
I have a code that populates data from a mysql table into an html table. I also have a text box and a button at the end of each row. I want to send all the variables in the row including the text in the textbox to update.php. Could not do that somehow. Here is the code I am trying. Please help. I can send it through GET method. But I want to use POST.
<?php
require 'config.php';
mysql_connect ($dbhost, $dbusername, $dbuserpass);
mysql_select_db($dbname) or die('Cannot select database');
$query = "SELECT * FROM cust_info;";
$result = mysql_query($query) or die(mysql_error());
echo "</br>";
echo "<table border='1'>
<tr>
<th>Pop Code</th>
<th>Open_Date</th>
<th>Maturity_Date</th>
<th>Amount</th>
<th>Balance</th>
<th>Collection Amount</th>
</tr>";
while($row1 = mysql_fetch_array($result))
{
echo "<div class=\"addform\"><form method='post' action=\"update.php?upd=".$row1['pop_code']."\">\n";
echo "<tr>";
echo "<td>" . $row1['pop_code'] . "</td>";
echo "<td>" . $row1['open_date'] . "</td>";
echo "<td>" . $row1['mat_date'] . "</td>";
echo "<td>" . $row1['depoamt'] . "</td>";
echo "<td>" . $row1['balance'] . "</td>";
echo "<td>" . " <input type=\"text\" name=\"amount\"/>\n" . "</td>";
echo "<td>" . " <input type=\"image\" src=\"images/update.png\" alt=\"Update Row\" class=\"update\" title=\"Update Row\">\n" . "</td>";
echo "</tr>";
echo "</form></div>";
}
echo "</table>";
?>
Change your table code to something like this:
echo "<td><input type='hidden' name='pop_code' value='".$row1['pop_code']."'>" . $row1['pop_code'] . "</td>";
It looks like your code isn't actually sending anything, just displaying it on the page. This will display it as well as sending a hidden field when the form is submitted.
Edit: Another way to do it would be to have a single form on your page outside your loop and have the button run a javascript function that copies the data to the form and submits the form. Probably easier the way you have it at the moment, but a javascript like that would be able to pick up other information off the user/page easily and send it via a single form to the next page.
You can make the fields hidden:
echo "<td><input type='hidden' name='pop_code' value='" . $row1['pop_code'] . "' />" . $row1['pop_code'] . "</td>";
echo "<td><input type='hidden' name='open_date' value='" . $row1['open_date'] . "' />" . $row1['open_date'] . "</td>";
your HTML is broken, <table> only allows <thead>, <tbody>, <tfoot> and <tr> as direct children, try fix this first because this will cause your Browser to close Tags automatically