How to put an array to the mysql database? [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 3 years ago.
Improve this question
I'm new for the PHP & I begin the project which was involving the PHP. my firm has a dynamic drop down. I can't insert the dynamic drop down data to the database.
Here's my index.php form.
<?php
//index.php
include('database_connection.php');
$query = " SELECT * FROM first_level_category ORDER BY first_level_category_name ASC ";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
?> <!DOCTYPE html> <style>
* { box-sizing: border-box; }
input[type=text], select, textarea { width: 100%; padding: 12px; border: 1px solid #ccc; border-radius: 4px; resize: vertical; }
label { padding: 12px 12px 12px 0; display: inline-block; }
/* Set a style for the submit button */ .registerbtn { background-color: #4CAF50; color: white; padding: 10px 10px; margin: 2px 0; border: none; cursor: pointer; width: 50%; opacity: 0.9; }
.registerbtn:hover { opacity: 1; }
.container { border-radius: 5px; background-color: #f2f2f2; padding: 20px; }
.col-25 { float: left; width: 30%; margin-top: 6px; }
.col-35 { float: left; width: 25%; margin-top: 6px; }
.col-75 { float: left; width: 30%; margin-top: 6px; }
div.ui-datepicker{ font-size:20px; float: left; width: 30%; margin-top: 6px; } /* Clear floats after the columns */ .row:after { content: ""; display: table; clear: both; } /* Clear floats after the columns */ .row:after { content: ""; display: table; clear: both; }
/* Responsive layout - when the screen is less than 600px wide, make the two columns stack on top of each other instead of next to each other */ #media screen and (max-width: 600px) { .col-25, .col-75, input[type=submit] {
width: 100%;
margin-top: 0; } </style>
<html> <head> <title>Bootstrap Multi Select Dynamic Dependent
Select box using PHP Ajax </title> <script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" /> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.13/js/bootstrap-multiselect.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.13/css/bootstrap-multiselect.css" /> </head> <body> <br /> <div class="container"> <form action="action.php" method="post"> <h2 align="center">Multi Select Dynamic Dependent Select box using PHP Ajax</h2> <br /><br /> <div style="width: 500px; margin:0 auto">
<div class="form-group"> <div class="container"> <form action="/action_page.php">
<div class="row">
<div class="col-25">
<label for="policynumber">Policy Number</label>
</div>
<div class="col-75">
<input type="text" id="policynumber" name="pid" placeholder="Policy number...">
</div>
</div>
<div class="row">
<div class="col-25">
<label for="date">Date</label>
</div>
<div class="ui-datepicker">
<input type="date" id="date" name="date" placeholder="date">
</div>
</div>
<div class="row">
<div class="col-25">
<label>Department</label> </div> <div class="col-75">
<select id="first_level" name="first_level" multiple class="form-control">
<?php
foreach($result as $row)
{
echo '<option value="'.$row["first_level_category_id"].'">'.$row["first_level_category_name"].'</option>';
}
?>
</select>
</div> </div>
<div class="row">
<div class="col-25">
<label>Supporting Documents</label> </div> <div class="col-75">
<select id="second_level" name="second_level" multiple class="form-control">
</select>
</div> </div>
<!--<div class="row">
<div class="col-25">
<label>First Level Category</label> </div> <div class="col-75">
<select id="third_level" name="third_level[]" multiple class="form-control">
</select> </div> </div>-->
<button type="submit" class="registerbtn">Submit</button> </div>
</form> </body> </html> <script> $(document).ready(function(){
$('#first_level').multiselect({ nonSelectedText:'Select First Level Category', buttonWidth:'400px', onChange:function(option, checked){ $('#second_level').html(''); $('#second_level').multiselect('rebuild'); $('#third_level').html(''); $('#third_level').multiselect('rebuild'); var selected = this.$select.val(); if(selected.length > 0) {
$.ajax({
url:"fetch_second_level_category.php",
method:"POST",
data:{selected:selected},
success:function(data)
{
$('#second_level').html(data);
$('#second_level').multiselect('rebuild');
}
}) } } });
$('#second_level').multiselect({ nonSelectedText: 'Select Second Level Category', buttonWidth:'400px', onChange:function(option, checked) { $('#third_level').html(''); $('#third_level').multiselect('rebuild'); var selected = this.$select.val(); if(selected.length > 0) {
$.ajax({
url:"fetch_third_level_category.php",
method:"POST",
data:{selected:selected},
success:function(data)
{
$('#third_level').html(data);
$('#third_level').multiselect('rebuild');
}
}); } } });
$('#third_level').multiselect({ nonSelectedText: 'Select Third Level Category', buttonWidth:'400px' });
}); </script>
Here's my Action.php code
//here's my action.php form
// Check connection if($connect === false){
die("ERROR: Could not connect. " . mysqli_connect_error()); }
if(isset($_POST["submit"]));
// Escape user inputs for security
$pid = $_POST['pid']; $date = $_POST['date']; $record1 = is_array('first_level'); $record2 = is_array('second_level');
// Attempt insert query execution $sql = "INSERT INTO saveditem (pid, date, department,supdoc) VALUES ('$pid', '$date','$record1','$record2')";
if(mysqli_query($connect, $sql)){
echo "Records inserted successfully."; } else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($connect); } // Close connection mysqli_close($connect); ?>
Can someone help me out?

try to var_dump($result) before you looping them to make sure your data is ready to use
<?php
var_dump($result);
foreach($result as $row)
{?>
<option value="<?php echo $row['first_level_category_id']; ?>"><?php echo $row['first_level_category_name']; ?></option>
<?php
}
?>

You can json_encode and json_decode. Encode the array and then insert into the database. if you need to fetch the array from the database, json_decode it.
More info:
https://www.php.net/manual/en/function.json-encode.php
https://www.php.net/manual/en/function.json-decode.php

Related

When I try to upload an image to my chat website it doesn't save the variable

I have a simple chat website, and I'm trying to add a profile-picture feature. This is my code:
<?php
function loginForm(){
echo
'<div id="loginform">
<p>Please enter your name to continue!</p>
<form action="index.php" method="post">
<label for="name">Display Name: </label>
<input style="font-family: Sans-serif;" type="text" name="name" id="name" />
<label for="name">Profile picture: </label>
<input style="font-family: Sans-serif;" type="text" name="pfp" id="name" />
<input style="font-family: Sans-serif;" type="submit" name="enter" id="enter" value="Enter" />
</form>
</div>
<center><h2>Upload profile picture: </h2><br><?php error_reporting(0); ?> <?php $msg = ""; if (isset($_POST[\'uploadfile\'])) { $filename = $_FILES["choosefile"]["name"]; $tempname = $_FILES["choosefile"]["tmp_name"]; $folder = "image/".$filename; $_SESSION[\'pfp\'] = $folder; $db = mysqli_connect("localhost", "root", "", "Image_upload"); $sql = "INSERT INTO image (filename) VALUES (\'$filename\')"; ($db, $sql); if (move_uploaded_file($tempname, $folder)) { $msg = "Image uploaded successfully"; }else{ $msg = "Failed to upload image"; } } $result = mysqli_query($db, "SELECT * FROM image"); ?> <!DOCTYPE html> <html> <!DOCTYPE html> <html> <head> <title>Image Upload in PHP</title> <! link the css file to style the form > <style type="text/css"> #wrapper{ width: 50%; margin: 20px auto; } form{ width: 50%; margin: 20px auto; } form div{ margin-top: 5px; } img{ float: left; margin: 5px; width: 280px; height: 120px; } #img_div{ width: 70%; padding: 5px; margin: 15px auto; border: 1px solid #dad7d7; } #img_div:after{ content: ""; display: block; clear: both; } button, input, span { background: #41d18e; border: none; color: white; padding: 4px 10px; font-weight: bold; border-radius: 20px; } </style> </head> <body> <div id="wrapper"> <! specify the encoding type of the form using the enctype attribute > <form method="POST" action="" enctype="multipart/form-data"> <input type="file" name="choosefile" value="" /> <div> <button type="submit" name="uploadfile">Use as new profile pic</button> </div> </form> </div></center>';
}
?>
<div id="menu">
<?php echo "<img style=\"width: 20px; border-radius: 9999px;\" src=".$_SESSION['pfp'].">"; ?>
<p class="welcome"> Welcome, <b><?php echo $_SESSION['name']; ?></b></p>
<p class="logout"><a id="exit" href="#">Rename</a></p>
</div>
For some reason <p class="welcome"></p> works perfectly fine, but the image just doesn't show. I looked in my image folder but could not find the image that I uploaded earlier.
Thanks for all the support.
replace the line and see
"<img style="width:20px;",src=<?php echo $_SESSION['pfp'];?>"
his maybe the issue: Change so the image link/location is properly surrounded in quotes in the outputted html.

How to input a slider in this form?

I want to add a slider in the form tag. Right now all the pictures are together. i want to make it more user friendly. As you can see in my code i'm fetching all images from database. And i've override the input radio button on each image so that the user can select its image.
I've already tried to use the Slick library but its not good.
<style type="text/css">
/*
html, body {
margin: 0;
padding: 0;
}
*/
* {
box-sizing: border-box;
}
.slider {
width: 50%;
margin: 100px auto;
}
.slick-slide {
margin: 0px 20px;
}
.slick-slide img {
width: 100%;
}
.slick-prev:before,
.slick-next:before {
color: black;
}
.slick-slide {
transition: all ease-in-out .3s;
opacity: .2;
}
.slick-active {
opacity: .5;
}
.slick-current {
opacity: 1;
}
.img{
width: 10%;
}
</style>
<style media="screen">
.input-hidden {
position: absolute;
left: -9999px;
}
input[type=radio]:checked + label>img {
border: 1px solid #fff;
box-shadow: 0 0 3px 3px #090;
}
input[type=radio]:checked + label>img {
transform:
rotateZ(-10deg)
rotateX(10deg);
}
/* Stuff after this is only to make things more pretty */
input[type=radio] + label>img {
width: 115px;
height: 115px;
transition: 500ms all;
}
* {
margin: 0px;
padding: 0px;
}
</style>
</head>
<body>
<form action="preview.php" method="post" >
<?php
$result_model = mysqli_query($conn, "SELECT * FROM model ORDER BY id DESC ");
$result_metal = mysqli_query($conn, "SELECT * FROM metal ORDER BY id DESC ");
$result_stone = mysqli_query($conn, "SELECT * FROM stone ORDER BY id DESC "); ?>
<div >
<div class="input-group">
<p>Choose your Model:</p>
</div>
<div class="regular slider">
<?php
while($model = mysqli_fetch_assoc($result_model)){
?>
<!-- <input type="radio" name="model" id="model<?= $model['id'] ?>" class="input-hidden" value="<?= $model['id'] ?>" />-->
<!--
<label for="model<?= $model['id'] ?>">
-->
<img
src="images/<?= $model['image'] ?>"
alt="<?= $model['name'] ?>" style="width:50%;" />
<!-- </label>-->
<?php
}
?>
<!-- </div>-->
<!-- <br>-->
<div>
<!--
<div class="input-group">
<p>Choose your Metal:</p>
</div>
-->
<!--
-->
</div>
<br>
</div>
<div class="input-group">
<p>Choose your Metal:</p>
</div>
<div class="regular slider">
<?php
while($metal = mysqli_fetch_assoc($result_metal)){
?>
<!--
<input type="radio" name="metal" id="metal<?= $metal['id'] ?>" class="input-hidden" value="<?= $metal['id'] ?>" />
-->
<!-- <label for="metal<?= $metal['id'] ?>">-->
<img
src="images/<?= $metal['image'] ?>"
alt="<?= $metal['name'] ?>" />
<!-- </label>-->
<?php
}
?>
?>
<!-- </div>-->
<!-- <br>-->
<div>
<!--
<div class="input-group">
<p>Choose your Metal:</p>
</div>
-->
<!--
-->
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="./slick/slick.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(document).on('ready', function() {
$(".regular").slick({
infinite: true,
slidesToShow: 3,
slidesToScroll: 1
});
});
</script>
</div>
</form>

push item to div from list of item div [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a question. I have for example list of div, i just want all these dives should be clickable. And after click on div, value from div should be pushed to on an other div. How I can do it in a best way?
<?php
define('HOST','xxxx');
define('USER','xxx');
define('PASS','xxxx');
define('DB','xxxxx');
$con = mysqli_connect(HOST,USER,PASS,DB);
$sql = "select * from users";
$res = mysqli_query($con,$sql);
$result = array();
while($row = mysqli_fetch_array($res)){
array_push($result,
array(
'email'=>$row[3],
));
}
echo json_encode(array("result"=>$result));
mysqli_close($con);
?>
<html>
<head>
<style>
#usersOnLine {
font-family:tahoma;
font-size:12px;
color:black;
border: 3px teal solid;
height: 525px;
width: 250px;
float: right;
overflow-y:scroll;
}
.container{
width:970px;
height:auto;
margin:0 auto;
}
</style>
</head>
<body>
<div class="container">
<div id="reciver"><h3>reciver</h3></div>
<div id="sender"><h3>sender</h3></div>
<h2 align="right"> all contacts </h2>
<div id="usersOnLine">
<?php
foreach($result as $key => $val)
{
echo $val['email'];
echo "<br>";
}
?>
</div>
</div>
</body>
</html>
here is useronline div in which many name are i want when i click on any name name push to reciver div how to made it i am new in php
You may do it with a Combination of Javascript and HTML. Below is how:
HTML, CSS & JAVASCRIPT - JQUERY
<!-- HTML-->
<html>
<head>
<!-- CSS-->
<style>
#usersOnLine {
font-family:tahoma;
font-size:12px;
color:black;
border: 3px teal solid;
height: 525px;
width: 250px;
float: right;
overflow-y:scroll;
padding: 10px;
}
.container{
width:970px;
height:auto;
margin:0 auto;
}
.clickAble{
display: inline-block;;
cursor:pointer; /* <== TO INDICATE TO USER THAT THIS IS CLICKABLE... */
}
</style>
</head>
<!-- HTML CONTENT -->
<body>
<div class="container">
<div id="receiver">
<h3>receiver</h3>
<!-- NOTICE THAT THIS IS NEW NOW... -->
<!-- IT'S IMPORTANT THAT YOU HAVE THIS PARAGRAPH EXACTLY AS IT IS HERE -->
<p class='bubbled-data'></p>
</div>
<div id="sender"><h3>sender</h3></div>
<h2 align="right"> all contacts </h2>
<div id="usersOnLine">
<?php
foreach($result as $key => $val){
echo "<span class='clickAble'>" . $val['email'] . "</span><br />";
}
?>
</div>
<!-- THE FORM -->
<form id="messageForm" action="<?php echo $_PHP_SELF; ?>" method="POST" >
<input type="text" name="data" id="message" placeholder="message" onFocus="fun1(this)" onBlur="fun2(this)" required="" /><br /><br />
<!-- NOTICE THAT WE ADDED A HIDDEN FIELD TO HOLD THE DATA -->
<input type="hidden" name="user_data" id="user_data" value="">
<input id="send" type="submit" value="Send">
</form>
</div>
<!-- JAVASCRIPT - JQUERY -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script type="text/javascript">
(function ($) {
$(document).ready(function (e) {
var receiver = $("#receiver");
var clickAbles = $(".clickAble");
// BIND THE clickAble SPAN TO AN ON-CLICK EVENT...
// SO THAT WITH EACH CLICK, YOU CAN SIMPLE APPEND THE CONTENT OF THAT SPAN TO THE RECEIVER DIV
clickAbles.on("click", function(evt){
var nameValue = $(this).text();
receiver.find(".bubbled-data").text(nameValue);
// ADD THE SAME VALUE TO THE HIDDEN INPUT ELEMENT: #user_data
$("#user_data").val(nameValue);
});
});
})(jQuery);
</script>
</body>
</html>
TEST & FIDDLE WITH IT HERE
https://jsfiddle.net/7eres0L0/

Why is my input submit of my form not clickable?

I have no idea what's causing the problem. I have a sign up form, and whenever I try to click the "Complete Registration" button, nothing happens! The form isn't even submitted! This is the HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" name="viewport" content="width=device-width, height=device-height, initial-scale = 1">
<title>Signup</title>
<link rel="icon" href="/images/favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="/styling/signupstyle.css">
</head>
<body>
<div id="formdiv" method="post">
<h1 id="title">Sign Up Here!</h1>
<form id="form" name="signupform" onsubmit="return false;">
<div class="inputdiv">
<label for="username">Username: </label>
<input name="username" type="text" maxlength="20">
<span id="unamestatus"></span>
</div>
<div class="inputdiv">
<label for="password">Password: </label>
<input type="password" name="pass1" maxlength="20">
</div>
<div class="inputdiv">
<label for="pass2">Confirm Password: </label>
<input type="password" name="pass2" maxlength="20">
</div>
<div class="inputdiv">
<label for="email">Email: </label>
<input name="email" type="text" maxlength="100">
</div>
<div class="inputdiv">
<label for="gender">Gender: </label>
<select name="gender"">
<option value=""></option>
<option value="m">Male</option>
<option value"f">Female</option>
</select>
</div>
<div class="inputdiv">
<label for="country">Country: </label>
<select name="country">
<?php include_once("countries.html"); ?>
</select>
</div>
<div>
<input id="submit" type="submit" name="submit" value="Complete Registration!" style="width: 40%; font-size: 25px; padding: 1% 0;">
</div>
<div style="margin-top: 5%;">
<img src="/images/ConnectionLogo.PNG" alt="Connection" style="width: 25%; height: 25%;">
</div>
</form>
</div>
</body>
</html>
And this is the styling of the form:
body {
width: 100vw;
height: 100vh;
font-size: 25px;
background: linear-gradient(to right, #3DCBF2 , #3DF2D4);
overflow-x: hidden;
overflow-y: hidden;
}
#formdiv {
margin: auto;
width: 50%;
height: 85%;
border: 5px solid #2A67EB;
background-color: #37A3F0;
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
}
#form {
width: 70%;
margin: 0 auto;
text-align: center;
height: 90%;
}
#title {
text-align: center;
color: #57E7F7;
margin-top: 1%;
}
#form input {
width: 35%;
font-size: 20px;
background-color: #70D1FA;
border: 3px solid #4187E8;
color: #376BE6;
}
#form select {
width: 25%;
font-size: 20px;
background-color: #70D1FA;
border: 3px solid #4187E8;
color: #376BE6;
}
.inputdiv {
padding-bottom: 5%;
}
#form label {
margin-right: 3%;
color: #3544F0;
font-weight: bold;
}
This is the PHP that isn't finished yet, but is certainly not causing the problem:
if ($_POST['submit']) {
// Receiving data from the form //
$username = preg_replace('#[^a-z0-9]#i', '', $_POST['username']);
$usercheck = mysqli_query($connection, "SELECT * FROM users WHERE username='$username'");
$password = mysqli_real_escape_string($connection, $_POST['pass1']);
$passconfirm = mysqli_real_escape_string($connection, $_POST['pass2']);
$email = mysqli_real_escape_string($connection, $_POST['email']);
$emailcheck = filter_var($email, FILTER_VALIDATE_EMAIL);
$emailcheck2 = mysqli_query($connnection, "SELECT * FROM users WHERE email='$email'");
$gender = mysqli_real_escape_string($connection, $_POST['gender']);
$country = mysqli_real_escape_string($connection, $_POST['country']);
// Now for the check functions //
if ($usercheck != 0) {
die("Sorry, your username is already in use! Redirecting...");
};
if ($password != $passwordconfirm) {
die("The passwords do not match! Redirecting...");
};
if ($emailcheck != 0) {
die("That email is already in use! Redirecting...");
};
};
Because you explicitly cancel the submit action. You say onsubmit="return false;". What are you expecting it to do when you explicitly tell it to do nothing?
Also, sidenote, you have a few HTML issues:
<select name="gender"">
<option value=""></option>
<option value="m">Male</option>
<option value"f">Female</option>
should be:
<select name="gender">
<option value=""></option>
<option value="m">Male</option>
<option value="f">Female</option>

Need a small help in Viewing database content in a webpage

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.

Categories