Jump to content

Data will not display for Staff listings .. ??


spacepoet

Recommended Posts

Hello:

 

I am building a Staff list, that I want to use to allow the owner of a company to upload a photo, name, phone, and email of each person on his staff.

 

I am using this approach from a tutorial I found online:

Database:

CREATE TABLE employees (id int(5), name VARCHAR(30), email VARCHAR(30), phone VARCHAR(30), photo VARCHAR(30))

 

Form:

<form enctype="multipart/form-data" action="Add.php" method="POST"> 
Name: <input type="text" name="name"><br> 
E-mail: <input type="text" name = "email"><br> 
Phone: <input type="text" name = "phone"><br> 
Photo: <input type="file" name="photo"><br> 
<input type="submit" value="Add"> 
</form>

 

Add.php

<?php
include('include/myConn.php');
?>

...

<?php 

$target = "images/"; 
$target = $target . basename( $_FILES['photo']['name']); 

$name=$_POST['name']; 
$email=$_POST['email']; 
$phone=$_POST['phone']; 
$pic=($_FILES['photo']['name']); 

mysql_query("INSERT INTO `employees` VALUES ('$name', '$email', '$phone', '$pic')") ; 

if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) 
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; 
} 
else 
{ 

echo "Sorry, there was a problem uploading your file."; 
} 
?> 

 

Display.php

<?php
include('include/myConn.php');
?>

...

<?php

$data = mysql_query("SELECT * FROM employees") or die(mysql_error()); 

while($info = mysql_fetch_array($data));

{
echo "<img src=images/".$info['photo'] ."> <br>"; 
echo "<b>Name:</b> ".$info['name'] . "<br> "; 
echo "<b>Email:</b> ".$info['email'] . " <br>"; 
echo "<b>Phone:</b> ".$info['phone'] . " <hr>";
} 

?> 

 

I am not getting any errors and the photo is uploaded to the "images" folder, but none of the data displays ...

 

I do not see why ..

 

Any ideas?

 

Also, if any one has done something like this before and has a better approach to doing this, I am all ears.

 

I do want to allow the owner to edit and delete the profiles as well.

 

Thanks.

Loose the semi-colon on the fetch array line.

<?php
$data = mysql_query("SELECT * FROM employees") or die(mysql_error()); 
WHILE ($info = mysql_fetch_array($data)) {
echo "<img src=images/".$info['photo'] ."> <br>"; 
echo "<b>Name:</b> ".$info['name'] . "<br> "; 
echo "<b>Email:</b> ".$info['email'] . " <br>"; 
echo "<b>Phone:</b> ".$info['phone'] . " <hr>";
} 
?>

Have you even checked in your database table if there is any data being inserted into it?

 

Your insert query is failing because the syntax of the insert query you are using requires that you supply a value for every column. You should (always) use the form of an insert query where you specifically list the columns and the values.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.