The following code is not my own. I'm trying to learn how to make a shopping cart but i'm stuck on this part of the tutorial. Please verify the code and tell me what i'm doing wrong.
This is products.php:
if(isset($_GET['action']) && $_GET['action']=="add"){
$id=intval($_GET['id']);
if(isset($_SESSION['cart'][$id])){
$_SESSION['cart'][$id]['quantity']++;
}else{
$query_s=mysql_query($sql_s);
$row_s=mysql_fetch_array($query_s);
$_SESSION['cart'][$row_s'id_product']]=array(
"quantity" => 1,
"price" => $row_s['price']
);
}
}
?>
<h1>Product List</h1>
<?php
echo print_r($_SESSION['cart']);
?>
<table>
<tr>
<th>Name</th>
<th>Description</th>
<th>Price</th>
<th>Action</th>
</tr>
<?php
$sql = "SELECT * FROM products ORDER BY name ASC";
$query = mysql_query($sql);
while($row=mysql_fetch_array($query))
{
?>
<tr>
<td><?php echo $row['name'] ?> </td>
<td><?php echo $row['description'] ?> </td>
<td><?php echo $row['price'] ?>$</td>
<td>Add to cart</td>
</tr>
<?php
}
?>
</table>
This is index.php:
<?php
session_start();
include("connection.php");
if(isset($_GET['page']))
{
$pages=array("products","cart");
if(in_array($_GET['page'], $pages)) {
$_page=$_GET['page'];
}else{
$_page="products";
}
}
else {
$_page="products";
}
?>
<!DOCTYPE html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<title>Shopping cart</title>
</head>
<body>
<div id="container">
<div id="main">
<?php require($_page.".php"); ?>
</div> <!--end of main-->
<div id="sidebar">
</div> <!--end of sidebar-->
</div> <!--end of container-->
</body>
</html>
This is the css file style.css:
a {
color: #48577D;
text-decoration:none;
}
a:hover{
text-decoration:underline;
}
body {
font-family: Verdana;
font-size: 12px;
color: #444;
}
h1, h2 { margin-bottom: 15px;}
h1 { font-size:18px;}
h2 {font-size: 16px;}
#container {
width:700px;
margin: 150px auto;
background-color:#eee;
padding:15px;
overflow:hidden;
}
#main {
width: 490px;
float: left;
}
#main table {
width: 480px;
}
#main table th {
padding: 10px;
background-color: #48577D;
color: #fff;
text-align: left;
}
#main table td {
padding: 5px;
}
#sidebar {
width: 200px;
float: left;
}
This is the connection.php:
<?php
$con=mysql_connect("localhost","root","");
$database=mysql_select_db('tutorials');
?>
This is cart.php:
This is your cart
It's not incrementing the values properly. Thanks.
There is a syntax error here:
$_SESSION['cart'][$row_s'id_product']]
I think it's supposed to be:
$_SESSION['cart'][$row_s['id_product']]
You will easily catch these errors if you turn on error reporting. There is no reason to not have it turned on in development.
Related
I have tables that are the publish date of a article and a columns article summary, and those are clickable and should go to a edit page when you click on this. The article should be filled in when you click on it, so you can easy edit the text. I have make the table rows linked but I think I need to take the ID from the tables so it knows what the edit page should be filled in with.
Here is my current code:
<?php
include 'index.php';
include 'login2.php';
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="alleartikelen.css">
</head>
<body>
<h2> Widget news admin </h2>
<!-- Echo username -->
<?php
$user = $_SESSION['user'];
echo "<p>You are logged in as <b>$user</b>.</p>";
?>
<a class="logout" href="index.php">Log out </a>
<hr>
<h1> All Articles </h1>
<?php
$sql = "SELECT art_date, art_head FROM article";
$result = $conn->query($sql); //it makes the query
?>
<style>
.table td {
font-family: Merriweather, serif;
font-size: 16px;
padding: 10px 5px;
overflow: hidden;
word-break: normal;
}
.table th:first-child,
.table td:first-child {
width: 14%;
height: 10%;
}
td,th{
font-family: "Calibri ";
}
tr:nth-child(even){
background-color: #ddd;
}
tr:hover {
background-color: #F6F6F6;
}
th{
color:white;
}
.aa {
text-decoration: none;
color: inherit;
}
</style>
<section>
<div class="container">
<table class="table">
<tr>
<th>Publication date</th>
<th>Article</th>
</tr>
<?php
$res=$result->fetch_all(MYSQL_ASSOC); //Splitting all rows in arrays
$keys = array_keys($res[0]); //Arrays getting attached to $keys
// Make the results as rows
echo "<tbody>";
foreach($res as $rows)
{
echo "<tr>";
foreach($rows as $date)
{
echo "<td><a href='bewerkartikel.php'class ='aa'>$date</a>";
echo "</td>";
}
echo "</tr>";
}
echo "</tr>";
}
?>
</section>
</body>
</html>
Add article id to your link ?art_id=some_id
<?php
include 'index.php';
include 'login2.php';
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="alleartikelen.css">
<style>
.table td {
font-family: Merriweather, serif;
font-size: 16px;
padding: 10px 5px;
overflow: hidden;
word-break: normal;
}
.table th:first-child,
.table td:first-child {
width: 14%;
height: 10%;
}
td,th {
font-family: "Calibri ";
}
tr:nth-child(even){
background-color: #ddd;
}
tr:hover {
background-color: #F6F6F6;
}
th {
color:white;
}
.aa {
text-decoration: none;
color: inherit;
}
</style>
</head>
<body>
<h2> Widget news admin </h2>
<!-- Echo username -->
<?php
$user = $_SESSION['user'];
echo "<p>You are logged in as <b>$user</b>.</p>";
?>
<a class="logout" href="index.php">Log out </a>
<hr>
<h1> All Articles </h1>
<?php
$sql = "SELECT art_date, art_head, art_id FROM article"; //get article id too
$result = $conn->query($sql); //it makes the query
?>
<section>
<div class="container">
<table class="table">
<tr>
<th>Publication date</th>
<th>Article</th>
</tr>
<?php
echo "<tbody>";
while($rows = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>". $rows['art_date'] . "</td>";
echo "<td><a href='bewerkartikel.php?art_id=" . $rows['id'] . "' class ='aa'> " . $rows['art_head'] . "</a>";
echo "</td>";
echo "</tr>";
}
echo "</tr>";
?>
</section>
</body>
</html>
Screenshot
You need to pass the id to next page so what you need to do is add a id to url
like below
"<td><a href='bewerkartikel.php?id=".$date['id']." ' class='aa' >$date</a></td>";
and get the id on bewerkartikel page using
$id = $_GET['id'];
and then you get the particular id to edit.
I have this php file where I want to retrieve data from database and show in a tabular format.
<html>
<head>
<title>Admin</title>
<link rel="stylesheet" type="text/css" href="adminPanel.css"/>
</head>
<body>
<div class="header">
<h1>Admin</h1>
</div>
<div class="center">
<?php
include "db_connection.php";
$sql = "SELECT * FROM appointments;";
$result = mysqli_query($db,$sql);
If(mysqli_query($db,$sql) == TRUE){
?>
<table>
<th>Name</th>
<th>Address</th>
<th>Phone</th>
<th>License</th>
<th>Engine</th>
<th>Appointment Date</th>
<th>Preferred Mechanic</th>
<?php
while($row = mysqli_fetch_assoc($result)){
?>
<td><?php echo $row['Name'];?></td></br>
<td><?php echo $row['Address'];?></td>
<td><?php echo $row['Phone'];?></td>
<td><?php echo $row['Car_license_No'];?></td>
<td><?php echo $row['Car_Engine_No'];?></td>
<td><?php echo $row['Date'];?></td>
<td><?php echo $row['Mechanic'];?></td>
<?php
}
?>
</table>
<?php
}
?>
</div>
<div class="footer">
<p id="lastMod">
<script language="Javascript">
document.write("Last modified on " + document.lastModified + " ");
</script>
</p>
</div>
</body>
</html>
But the problem is I can`t change the style of data showing in the table. The .footer, .center, .header these are showing up with the perfect style. But styles of html elements that are written within the php blocks are not working, such as , , .
Here is my style sheet
.header{
background-color: black;
color: DC143C;
height: 150px;
margin-bottom: 0px;
font-family: "Impact"
}
.center{
background-image: url(background.jpg);
height: 400px;
margin-top: 0px;
margin-bottom: 0px;
}
.footer{
background-color: black;
font-family: "Impact";
color: DC143C;
margin-top: 82px;
height: 95px;
}
th, td{
color: white;
}
#lastMod{
margin-top: 0px;
padding: 5px;
}
Searched a lot but havn`t found any relevant answer. Thanks in advance.
You should apply the classes to cells then you could style it.
<td class="name"><?php echo $row['Name'];?></td></br>
...
<td class="mechanic"><?php echo $row['Mechanic'];?></td>
<style>
td.name {
background-color: #0f0;
}
....
td.mechanic {
background-color: #f00;
}
</style>
you didn't added any class in your php you should add class in your table like
<table class="mytable">
and style it by pointing with parent such as
<style>
.mytable th { color:#fff; }
</style>
I have created a database named Magazine and it has a table social_media. The table has 5 columns namely ID, Headline, Author, Content Short, Content. The Content Short column contains the shorter version of the entire article(which will be displayed in the following code) and the Content column contains the entire article(which will be displayed on clicking the Read More button). I have created a homepage where all the articles from the social_media are displayed in the Content_Left div(NOTE: The Content Short column is displayed and not Content). At the end of each entry from the database there is a 'Read More' button. On clicking on that read more button I want the user to be redirected to a new page 'article.php' where the Headline, Author and Content of the corresponding article will be displayed(The Longer version of the content and not the Content Short). How do I do it? I have created the following webpage:
<?php require_once('connections/connection.php'); ?>
<?php
session_start();
$stmt = $con->query("SELECT * FROM social_media");
?>
<!doctype html>
<html>
<head>
<link href="CSS/Layout.css" rel="stylesheet" type="text/css" />
<link href="CSS/menu.css" rel="stylesheet" type="text/css" />
<style type="text/css">
</style>
<meta charset="utf-8">
<title>Home</title>
</head>
<body style="background-color:#E0DDDD">
<div id="Container">
<div id="Header"></div>
<div id="NavBar">
<nav>
<ul>
<li>Home</li>
<li>Social Media</li>
<li>Tech</li>
<li>Tips & Tricks</li>
</ul>
</nav>
</div>
<div id="Content">
<div id="Content_Left">
<h1><center>Social Media</center></h1>
<table>
<?php
while($records=$stmt->fetch_assoc()) {
$_SESSION["ID"] = $records['ID'];
echo "<tr>";
echo "<th><h3>".$records['Headline']."</h3></th>";
echo "</tr>";
echo "<tr>";
echo "<td>By <strong>".$records['Author']."</strong></td>";
echo "</tr>";
echo "<tr>";
echo "<td>".$records['Content_short']." Read More...</td>";
echo "</tr>";
}
?>
</table>
</div>
<div id="Content_Center">
<h1>Header Here </h1>
<p>Text Goes Here!</p>
</div>
<div id="Content_Right">
<h1>Header Here </h1>
<p>Text Goes Here!</p>
</div>
</div>
<div id="Footer">
<center>Your Copyright Message</center>
</div>
</div>
</body>
</html>
And here is the CSS file(Layout.css):
body{
margin:0;
padding: 0;
}
#Container {
width: 980px;
height:auto;
margin-left:auto;
margin-right:auto;
margin-top:20px;
margin-bottom:21px;
}
#Header {
height:120px;
background-image:url(../Assets/Untitled-1.png);
background-repeat:no-repeat;
margin-bottom:21px;
}
#NavBar {
height:60px;
background-color:#000000;
}
#Content {
background-color:#FFFFFF;
margin-top: 20px;
padding: 5px;
overflow:hidden;
}
#Content_Left {
height: auto;
width: 210px;
padding:5px;
float:left;
background-color: lightblue
}
#Content_Center {
height: auto;
padding:5px;
width: 500px;
float:left;
margin-left: 10px;
margin-right: 10px;
background-color: lightblue
}
#Content_Right {
height: auto;
padding:5px;
width: 210px;
float: right;
background-color: lightblue
}
#Container #Content h1 {
font-family: "Gill Sans", "Gill Sans MT", "Myriad Pro", "DejaVu Sans Condensed", Helvetica, Arial, sans-serif;
font-style: normal;
font-variant: normal;
font-weight: bolder;
text-shadow: 0px 0px;
}
#Footer {
padding-top: 10px;
height: 100px;
}
And here is the CSS file(menu.css):
nav ul {
margin:0;
padding:0;
}
nav ul li {
list-style-type:none;
display:block;
width:150px;
height:60px;
float:left;
text-align:center;
line-height:55px;
font-family:Baskerville, "Palatino Linotype", Palatino, "Century Schoolbook L", "Times New Roman", serif;
font-size:17px;
}
nav ul li a {
text-decoration:none;
color:#FFF;
}
nav ul li:hover {
background-color:#BBB5B5;
}
nav ul li:hover a {
display:block;
color:Black;
}
I want to display that article in the new page but with the same background theme. Or is there any other way to display the entire article? I hope this much detail is enough. In case any more information is needed please ask.
EDIT: As per the suggestions of the fellow members I have edited the code. My article.php file now looks like this:
<?php require_once('connections/connection.php');?>
<?php
$articleId = $_GET['articleId'];
// you need to fetch only one record this time for showing only the article that wanted to be read. so use `where` condition
$stmt = $con->query("SELECT * FROM social_media WHERE id = $articleId ");
?>
<!doctype html>
<html>
<head>
<link href="CSS/Layout.css" rel="stylesheet" type="text/css" />
<link href="CSS/menu.css" rel="stylesheet" type="text/css" />
<style type="text/css">
</style>
<meta charset="utf-8">
<title>Home</title>
</head>
<body style="background-color:#E0DDDD">
<div id="Container">
<div id="Header"></div>
<div id="NavBar">
<nav>
<ul>
<li>Home</li>
<li>Social Media</li>
<li>Tech</li>
<li>Tips & Tricks</li>
</ul>
</nav>
</div>
<div id="Content">
<div id="Content_Full">
<table>
<?php
while($records=$stmt->fetch_assoc()) {
echo "<tr>";
echo "<th><h1>".$records['Headline']."</h1></th>";
echo "</tr>";
echo "<tr>";
echo "<td>By <strong>".$records['Author']."</strong></td>";
echo "</tr>";
echo "<tr>";
echo "<td>".$records['Content']."</td>";
echo "</tr>";
}
?>
</table>
</div>
</div>
<div id="Footer">
<center>Your Copyright Message</center>
</div>
</div>
</body>
</html>
However, I am getting the following error:
Fatal error: Call to a member function fetch_assoc() on a non-object
How do I resolve this problem?
Change few thing
in php file
echo "<td>".$records['Content_short']." <a href='article.php'>Read More...</a></td>";
to
echo "<td>".$records['Content_short']." <a href='article.php?articleId= " . $records['ID']. "'>Read More...</a></td>";
then in your article.php
<?php
if(isset($_GET['articleId'])){
$articleId = $_GET['articleId'];
}else{
echo "Invalid access"; die;
}
// you need to fetch only one record this time for showing only the article that wanted to be read. so use `where` condition
$stmt = $con->query("SELECT * FROM social_media WHERE id = $articleId ");
Follow same html code of your article listing page on article.php
Change your below line
echo "<td>".$records['Content_short']." <a href='article.php'>Read More...</a></td>";
To:
echo "<td>".$records['Content_short']." Read More...</td>";
Now you've to get details by ID and display data accordingly.
here is sample image
<!DOCTYPE html>
<html class="bg-black">
<head>
<meta charset="UTF-8">
<title><?php if(isset($title)) echo $title.' | '; ?> Sales agent management software (SAMS) </title>
<style>
body{
font-size: 9px;
margin: 20px;
}
th,td,p,div,table,h3{margin:0;padding:0}
#page { margin: 20px; }
.header{
border-bottom: 1px solid #dddddd;
text-align: center;
position: fixed; top: 0;
}
.footer { position: fixed; bottom: 0px; text-align: center }
.pagenum:before { content: counter(page); }
</style>
</head>
<body>
<div class="header">
<h2><?php echo get_option('company_name'); ?> Catalog</h2>
</div>
<br /><br />
<div class="footer">Page: <span class="pagenum"></span>, creation time : <?php echo date('l jS \of F Y h:i:s A') ?>, create by: <?php echo user_full_name(singleDbTableRow(loggedInUserData()['user_id'])); ?></div>
<br />
<div class="box-body">
<?php
$usd = get_option('lkr_per_usd', 134);
?>
<?php
$result = array_chunk($products->result_array(), 3);
foreach($result as $products){ ?>
<table style="width:100% style="page-break-after:always;" >
<tr>
<?php
foreach($products as $productArray){
$product = (object) $productArray;
echo '<td>';
?>
<div style="width: 100%; height: 210px; border: 1px solid #dddddd; margin: 10px; padding: 5px;">
<div class="box-header">
<p class="box-title"><FONT SIZE=12><?php echo $product->product_name; ?></FONT></p>
</div>
<div style="height: 80px; text-align: center;">
<?php echo '<img src="'.'uploads/'. $product->photo.'" class="img-responsive" style="height:80px !important; width: 150px !important" />'; ?>
</div>
<div style="clear: both"></div>
<table class="table table-responsive">
<tr>
<th><FONT SIZE=12>ID</FONT></th>
<td><FONT SIZE=14><?php echo $product->product_id; ?></FONT></td>
</tr>
<tr>
<th><FONT SIZE=12>LKR</FONT></th>
<td><FONT SIZE=14><?php $lkr = get_selling_price($product);
echo number_format(round($lkr, get_option('round_precision')) ); ?></FONT>
</td>
</tr>
<tr>
<th> <FONT SIZE=12>US $</FONT></th>
<td><FONT SIZE=14><?php echo number_format(round(lkr_to_usd($lkr), get_option('round_precision')) ); ?></FONT></td>
</tr>
</table>
</div>
</td>
<?php } ?>
</tr>
<?php } ?>
</table>
</div><!-- /.box-body -->
</body>
</body>
</html>
when i try to generate pdf it's always coming like this. i added my generate pdf code above .
2 nd page is not coming like 1st page.. i searched and found other dompdf solution for other peoples problem. but my problem is on 2nd page it's not coming as 1stpage.
There's some buggy behavior here on the part of dompdf. For some reason styling the DIV containing your product info with width: 100% is breaking the layout when the table row is paged. If you remove that styling from the DIV then the document should render as expected. The default DIV layout is full-width so you can leave the width styling on the DIV out
I'm trying to view the contents of a database into a webpage. I'm using this code:
<?php
error_reporting(0);
$host="localhost";
$username="root";
$password="";
$database="pncollege";
mysql_connect($host,$username,$password);
#mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM data";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
echo "";
$i=0;
while ($i < $num) {
$email=mysql_result($result,$i,"email");
$name=mysql_result($result,$i,"name");
echo "";
$i++;
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Free Guidance Website Template | Programs :: w3layouts</title>
<link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href='http://fonts.googleapis.com/css?family=Montserrat+Alternates' rel='stylesheet' type='text/css'>
<!------ Light Box ------>
<script src="js/jquery.min.js"></script>
<link rel="stylesheet" href="css/swipebox.css">
<script src="js/ios-orientationchange-fix.js"></script>
<script src="js/jquery.swipebox.min.js"></script>
<script type="text/javascript">
jQuery(function($) {
$(".swipebox").swipebox();
});
</script>
<style>
/*
Max width before this PARTICULAR table gets nasty
This query will take effect for any screen smaller than 760px
and also iPads specifically.
*/
#media
only screen and (max-width: 760px),
(min-device-width: 768px) and (max-device-width: 1024px) {
/* Force table to not be like tables anymore */
table, thead, tbody, th, td, tr {
display: block;
}
/* Hide table headers (but not display: none;, for accessibility) */
thead tr {
position: absolute;
top: -9999px;
left: -9999px;
}
tr { border: 1px solid #ccc; }
td {
/* Behave like a "row" */
border: none;
border-bottom: 1px solid #eee;
position: relative;
padding-left: 50%;
}
td:before {
/* Now like a table header */
position: absolute;
/* Top/left values mimic padding */
top: 6px;
left: 6px;
width: 45%;
padding-right: 10px;
white-space: nowrap;
}
/*
Label the data
*/
td:nth-of-type(1):before { content: "First Name"; }
td:nth-of-type(2):before { content: "Last Name"; }
td:nth-of-type(3):before { content: "Job Title"; }
td:nth-of-type(4):before { content: "Favorite Color"; }
td:nth-of-type(5):before { content: "Wars of Trek?"; }
td:nth-of-type(6):before { content: "Porn Name"; }
td:nth-of-type(7):before { content: "Date of Birth"; }
td:nth-of-type(8):before { content: "Dream Vacation City"; }
td:nth-of-type(9):before { content: "GPA"; }
td:nth-of-type(10):before { content: "Arbitrary Data"; }
}
/* Smartphones (portrait and landscape) ----------- */
#media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
body {
padding: 0;
margin: 0;
width: 320px; }
}
/* iPads (portrait and landscape) ----------- */
#media only screen and (min-device-width: 768px) and (max-device-width: 1024px) {
body {
width: 495px;
}
}
* {
margin: 0;
padding: 0;
}
body {
font: 14px/1.4 Georgia, Serif;
}
#page-wrap {
margin: 50px;
}
p {
margin: 20px 0;
}
/*
Generic Styling, for Desktops/Laptops
*/
table {
width: 100%;
border-collapse: collapse;
}
/* Zebra striping */
tr:nth-of-type(odd) {
background: #eee;
}
th {
background: #333;
color: white;
font-weight: bold;
}
td, th {
padding: 6px;
border: 1px solid #ccc;
text-align: left;
}
</style>
<!------ Eng Light Box ------>
</head>
<body>
<div class="header-bg">
<div class="wrap">
<div class="total-box">
<div class="total">
<div class="header_top">
<div class="menu">
<ul>
<li>Home</li>
<li>About</li>
<li>Faculties</li>
<li>Picture Gallery</li>
<li class="active">Principal's Desk</li>
<li>Contact</li>
<div class="clear"></div>
</ul>
</div>
<ul class="follow_icon">
<li><img src="images/fb.png" alt=""></li>
<li><img src="images/tw.png" alt=""></li>
<li><img src="images/rss.png" alt=""></li>
</ul>
<div class="clear"></div>
</div>
<div class="header-bottom">
<div class="logo">
<img src="images/logo.png">
</div>
<div class="logo">
<h1>P.N. College, Parsa</h1>
<h2> ( A constituent unit of Jaiprakash University )</h2>
</div>
<div class="search">
<form>
<input type="text" value="">
<input type="submit" value="">
</form>
</div>
<div class="clear"></div>
</div>
</div>
</div>
</div>
</div>
<div class="banner-box">
<div class="wrap">
<div class="main-top">
<div class="main">
<div class="heading3">
<h3 style="text-align:center">Admin Panel</h3>
<hr><br>
</div>
<div class="section group">
<center>
<table>
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Message</th>
</tr>
</thead>
<tbody>
<tr>
<td><?php echo "$userName"; ?></td>
<td><?php echo "$userEmail"; ?></td>
<td><?php echo "$userMsg"; ?></td>
</tr>
</tbody>
</table>
</center>
<div class="clear"></div>
</div>
</div>
</div>
</div>
</div>
<div class="copy-right">
<p style="letter-spacing:4px;border-radius:15px 0 15px 0;background-color:#000;padding-top:15px;padding-bottom:15px;width:100%">© P.N. COLLEGE | DESIGNED BY INCREDIBLE SAURAV</p>
</div>
</body>
</html>
Can anyone help me and guide me where I've made a mistake? I know the code is a little messy and I'm sorry for that. I just can't figure out where I've made a mistake.
Change your loop to fetch an array for each row -
while ($row = mysql_fetch_array($result)) {
$email = $row['email']; // assign this array part to a variable
$name = $row['name'];
echo $name ." " .$email . "<br />"; // echo the variables
}
// now you can close the connection, after you have used the results
mysql_close();
Please, stop using mysql_* functions. They are no longer maintained and are officially deprecated. Learn about prepared statements instead, and consider using PDO, it's not as hard as you think.