spacepoet Posted February 2, 2012 Share Posted February 2, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/256287-data-will-not-display-for-staff-listings/ Share on other sites More sharing options...
Drummin Posted February 3, 2012 Share Posted February 3, 2012 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>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/256287-data-will-not-display-for-staff-listings/#findComment-1313850 Share on other sites More sharing options...
spacepoet Posted February 3, 2012 Author Share Posted February 3, 2012 Hi: Thanks, but I had tried that earlier - no luck .. Any other suggestions? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/256287-data-will-not-display-for-staff-listings/#findComment-1313891 Share on other sites More sharing options...
Drummin Posted February 3, 2012 Share Posted February 3, 2012 Are you sure fields match and the query is pulling results? Looks fine to me. Quote Link to comment https://forums.phpfreaks.com/topic/256287-data-will-not-display-for-staff-listings/#findComment-1313906 Share on other sites More sharing options...
PFMaBiSmAd Posted February 3, 2012 Share Posted February 3, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/256287-data-will-not-display-for-staff-listings/#findComment-1314099 Share on other sites More sharing options...
spacepoet Posted February 3, 2012 Author Share Posted February 3, 2012 Hi: I have found another solution. I abandoned the above and have turned my photo gallery into a staff list! Working so far, but I am sure I will have some questions. Thanks for the help! Quote Link to comment https://forums.phpfreaks.com/topic/256287-data-will-not-display-for-staff-listings/#findComment-1314212 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.