my member profile page not showing result? [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
This is my member profile page where I want the details of user to come ... but everything is getting printed including user id... but not the user record... I am new to this php and will appreciate any one help. screen shot is http://postimg.com/image/146000/screenshot-145081.jpg
<?php
session_start();
if(!isset($_SESSION["sess_user"])){
header("location:login.php");
} else {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<h2>Welcome, <?=$_SESSION['sess_user'];?>! Logout</h2>
<table width="1105" height="140" border="0" align="center" cellpadding="3" cellspacing="3">
<tr>
<th colspan="12"> </th>
</tr>
<tr>
<th colspan="7"><?php if(isset($_GET["msg"])) echo $_GET["msg"];?></th>
</tr>
<tr>
<td>Name</td>
<td>Company Name</td>
<td>Mobile no.</td>
<td>Email</td>
<td>City</td>
<td>State</td>
<td>Country</td>
<td>Category</td>
<td>Registration</td>
<td>DOJ</td>
<td>Action</td>
</tr>
<?php
require("includes/connections.php");//to make connection with database
$id=$_SESSION['sess_user'];
$sql="select * from stonemember where id='$id'";//select query from table stonemember
$result=mysql_query($sql);//result of select query in $result varialble
while($row=mysql_fetch_array($result))
{
?>
<tr>
<td><?php echo $row["Name"];?></td>
<td><?php echo $row["CompanyName"];?></td>
<td><?php echo $row["mobileno"];?></td>
<td><?php echo $row["email"];?></td>
<td><?php echo $row["city"];?></td>
<td><?php echo $row["state"];?></td>
<td><?php echo $row["Country"];?></td>
<td><?php echo $row["cat"];?></td>
<td><?php echo $row["registered"];?></td>
<td><?php echo $row["Date"];?></td>
<td><a href="admin/edit.php?id=<?php echo $row["id"];?>"Edit</a></td>
</tr>
<tr>
<?php
}
?>
</tr>
</table>
</body>
</html>
<?php }?>

You are going to need to learn to debug your scripts. Use google, others may have had the same problems.
1. In your php script, before everything, use:
erorr_reporting(E_ALL);
ini_set('display_errors', 'On');
usually, this will show ALL your script errors.
2. Instead of:
$result=mysql_query($sql);
use
$result=mysql_query($sql) or die(mysql_error());
this way, if you get a mysql error, it will stop the script and show the error.
3. Learn to use var_dump and print_r.
Example: after this part
$id=$_SESSION['sess_user'];
put this code:
var_dump($id);
this will show you if there is a value in $id variable and its type

Related

Image name appears after every image i echo on my php table. How do i hide this text? (mysql and php) [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
As you can see in the picture below, the name of the picture file appears after every image. I dont want the image name to be displayed. Is there any way of hiding the name so per.jfif, ola.jfif and arne.jfif doesnt appear?
I have been searching on here for an answer, but it doesnt seem to have been asked on here before. Thanks for the help in advance,
Below this text you can see my messy code.
<?php
$tilkobling = mysqli_connect("localhost","root","","oppgave_normalisering");
$sql = "SELECT person_table.personr, person_table.navn, person_table.adresse, person_table.mobilnr, person_table.postnr, person_table.bilde, mobil_table.model, sted_table.sted FROM mobil_table, person_table, sted_table WHERE person_table.personr = sted_table.stednr AND person_table.personr = mobil_table.modelnr";
$datasett = $tilkobling->query($sql)
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Startside</title>
<link rel="stylesheet" href="startside.css">
</head>
<body>
<nav>
<ul>
<li>Per</li>
<li>Ola</li>
<li>Arne</li>
</ul>
</nav>
<table >
<tr>
<td style="text-align:center"><b>Nr<b></td>
<td style="text-align:center"><b>Navn<b></td>
<td style="text-align:center"><b>Adresse<b></td>
<td style="text-align:center"><b>Postnr</b></td>
<td style="text-align:center"><b>Sted</b></td>
<td style="text-align:center"><b>Mobilnr</b></td>
<td style="text-align:center"><b>Modell</b></td>
<td style="text-align:center"><b>Bilde</b></td>
</tr>
<?php while ($rad = mysqli_fetch_array($datasett)) { ?>
<tr>
<td style="text-align:center"><?php echo $rad["personr"]; ?></td>
<td style="text-align:center"><?php echo $rad["navn"]; ?></td>
<td style="text-align:center"><?php echo $rad["adresse"]; ?></td>
<td style="text-align:center"><?php echo $rad["postnr"]; ?></td>
<td style="text-align:center"><?php echo $rad["sted"]; ?></td>
<td style="text-align:center"><?php echo $rad["mobilnr"]; ?></td>
<td style="text-align:center"><?php echo $rad["model"]; ?></td>
<td><img src="<?= $rad['bilde'] ?>" alt="" style="height:100px; width:140px;" id="bilde"> <?php echo $rad["bilde"]; ?></td>
</tr>
<?php } ?>
</table>
</body>
</html>
You print image name in your last td. Just remove <?php echo $rad["bilde"]; ?>.
<td>
<!-- ↓↓ this is image element -->
<img src="<?= $rad['bilde'] ?>" alt="" style="height:100px; width:140px;" id="bilde">
<!-- ↓↓ delete this ↓↓ -->
<?php echo $rad["bilde"]; ?>
</td>
Dont Need This part
<?php echo $rad["bilde"]; ?>

How use session variable in sql using php

I have a problem with displaying files added by the logged user.
I do not know how to pass the variable correctly to the sql query.
Can anyone help me with this?
Currently, the code looks like this:
<?php
include_once 'dbconnect.php';
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>File Uploading With PHP and MySql</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div id="header">
<label>File Uploading With PHP and MySql</label>
</div>
<div id="body">
<table width="80%" border="1">
<tr>
<th colspan="4">your uploads...<label>upload new files...</label></th>
</tr>
<tr>
<td>File Name</td>
<td>File Type</td>
<td>File Size(KB)</td>
<td>View</td>
</tr>
<?php
$sql="SELECT * FROM files";
$result_set=mysql_query($sql);
while($row=mysql_fetch_array($result_set))
{
?>
<tr>
<td><?php echo $row['file'] ?></td>
<td><?php echo $row['type'] ?></td>
<td><?php echo $row['size'] ?></td>
<td>view file</td>
</tr>
<?php
}
?>
</table>
</div>
</body>
</html>
I am trying to change this record :
$sql="SELECT * FROM files";
to
$sql="SELECT file, type, size FROM files WHERE userId ='$_SESSION[userId]'";
but I still do not get the correct result. Can anyone help?
It looks like the issue with that line is in how you are including the $_SESSION variable. You should have quotes around userId like $_SESSION['userId'] or {$_SESSION['userId']}.
More importantly you should avoid entering variables directly into MySQL queries. I would recommend using MySQLi or PDO instead of MySQL, and look into prepared statements (here or here, for example).

my records are not displaying

in my project i try to display data from database and this is my code.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="prac.css">
<title>PHP Practical</title>
</head>
<body>
<div class="main">
<table class="table">
<tr>
<th>Employee ID</th>
<th>Employee Name</th>
<th>Employee Contact</th>
<th>Employee Salary</th>
<th>Employee Phone</th>
<th>Employee City</th>
<th>Join Date</th>
<th>Action</th>
</tr>
<?php
require 'config.php';
$query = mysql_query("SELECT * FROM emp");
while ($row = mysql_fetch_array($query)) {
?>
<tr>
<td><?php echo $row['emp_id']; ?></td>
<td><?php echo $row['emp_name']; ?></td>
<td><?php echo $row['emp_contact']; ?></td>
<td><?php echo $row['emp_salary']; ?></td>
<td><?php echo $row['emp_phone']; ?></td>
<td><?php echo $row['emp_city']; ?></td>
<td><?php echo $row['join_date']; ?></td>
<td>Update | Delete</td>
</tr>
<?php
}
?>
</table>
</div>
</body>
</html>
i checked my config.php file and it is working fine and in database i have 6 records but it is not displaying any. i try also run query to database and it is working fine in database but not here. please help me.
**Use this**
$query = mysql_query("SELECT * FROM emp") or die(mysql_error());
to display mysql error
The mysql_ extension is deprecated. There is no point in using it.
Switch to mysqli or PDO
The issue you are currently facing is not caused because of mysql_ being deprecated but there's no worth in investigating it. It's not used anymore

How do I make a table that prints out in a row all the same columns in a database? [duplicate]

This question already has answers here:
Displaying mysql data in html table PHP
(2 answers)
Closed 8 years ago.
What I am trying to do here is echo out every columns "unit" within my database. In my database I have columns: evaluation, unit, percent and due date. I want all the units to appear on the table in a row as I have tried to do it but can't seem to find out how to do this. this is the code that I have tried <?php echo $unit ?> but does not seem to work.
Example
My database:
project0 unit1 15% 22-07-2014
project1 unit1 10% 24-07-2014
project2 unit2 20% 27-07-2014
project3 unit3 30% 29-07-2014
Code
<?php
mysql_connect('localhost','root','root');
mysql_select_db('Eviden');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<table width="200" border="1">
<?php
$result = mysql_query("SELECT * FROM peviden");
while($row=mysql_fetch_array($result)){
$unit=$row['unit'];
$name=$row['name'];
?>
<tr>
<td> </td>
<!--I want all the units columns in the database to go on this row-->
<td><?php echo $unit ?></td>
<td><?php echo $unit ?></td>
<td><?php echo $unit ?></td>
<td><?php echo $unit ?></td>
</tr>
<tr>
<td>Name</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Sebastian</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Zack</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Daniel</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<?php
}
?>
</table>
</form>
</body>
</html>
I believe this is happening because mysql_fetch_array returns an array, which would store the results of each row as
row[0] // evaluation
row[1] // unit
row[2] // percent
row[3] // due date
Try using the array format, and optionally specify the order for the array as you go:
<?php
$result = mysql_query("SELECT evaluation, unit, percent, due_date FROM peviden");
while($row=mysql_fetch_array($result)){
$evaluation=$row[0];
$unit=$row[1];
$percent=$row[2];
$duedate=$row[3];
?>
The first thing you have to do is fix your database call. Right now you are looping over the results and assigning $unit a new value at each iteration over the loop. So, we're going to fix that here:
$result = mysql_query("SELECT * FROM peviden");
// New Array to avoid PHP notifications
$unitsArray = array();
// Start our loop over our results
while($row=mysql_fetch_array($result)){
// Add an entry to our array with two values for unit and name
$unitsArray[] = array( 'unit' => $row['unit'],
'name' => $row['name']
);
}
Now that we've assigned all our units to a useable value, in your HTML code you need to loop over them again to get them displayed correctly:
<td> </td>
<!--I want all the units columns in the database to go on this row-->
<?php
foreach($unitsArray as $entry) {
?>
<td><?php echo $entry['unit']; ?></td>
<?php
}
?>
This will create one TD for each unit across the table.

trying to print database in a web page but can't get a counter for table

I am trying to create a page that displays rpg ranks from a mysql database on a webpage
i went into the database and organized the data by level, so the person with the highest level is shown first and so on, however the database does not contain a table for ranks
I am trying to do that manually in dreamweaver but I don't know how, can I create a counter and have it display in the table?
I managed to get the following:
http://slayersgaming.com/rpgranks2.php
<?php
$dbh=mysql_connect("********", "**********", "*********") or die('Cannot connect to the database because: '. mysql_error());
mysql_select_db("C368969_thcrpgCSGO");
$rpgranks_sql = "SELECT * FROM `thc_rpg` ORDER BY `thc_rpg`.`level` DESC LIMIT 0, 30 ";
$rpgranks_query = mysql_query($rpgranks_sql) or die(mysql_error());
$rsrpgranks = mysql_fetch_assoc($rpgranks_query);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<p>
<table width="501" height="58" border="0">
<tr>
<td width="240"><h2><strong>Name</strong></h2></td>
<td width="70"><strong>Level</strong></td>
<td width="70"><strong>XP</strong></td>
<td width="70"><strong>Credits</strong></td>
<td width="70"><strong>Rank</strong></td>
</tr>
</table>
<?php do{ ?>
<table width="501" height="58" border="0">
<tr>
<td width="240"><?php echo $rsrpgranks['name'];?></td>
<td width="70"><?php echo $rsrpgranks['level'];?></td>
<td width="70"><?php echo $rsrpgranks['xp'];?></td>
<td width="70"><?php echo $rsrpgranks['credits'];?></td>
<td width="70"> </td>
</tr>
</table>
<?php } while ($rsrpgranks = mysql_fetch_assoc($rpgranks_query)) ?>
</p>
<p> </p>
</body>
</html>
screen cap here: http://oi47.tinypic.com/21exdfs.jpg
This is actually really easy to do. You just need a counter in your do-while loop like this:
<?php
$counter = 1;
do{
?>
<table width="501" height="58" border="0">
<tr>
<td><?php echo $counter; ?></td>
<td width="240"><?php echo $rsrpgranks['name'];?></td>
<td width="70"><?php echo $rsrpgranks['level'];?></td>
<td width="70"><?php echo $rsrpgranks['xp'];?></td>
<td width="70"><?php echo $rsrpgranks['credits'];?></td>
<td width="70"> </td>
</tr>
</table>
<?php
$counter++;
} while ($rsrpgranks = mysql_fetch_assoc($rpgranks_query))
?>

Categories