Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialKonrad Pilch
2,435 PointsConnecting PHP input to the array and put it on website
Hi,
Im going throw mike shirts store, im bulidng it and i want to do something. Since i believe i do understand how it works. I want to make it like this. User put input in the input fields, what he puts, his input will go to the array where the array holds e.g "name" => ,"img" => , "prize", and it creates new item in html and adds it . I know how to make it but i dont know how to make the input work so its works like that .
Can somebody tell me how to do it ro give and idea how to connect ti tplease?
Kayden Enright
3,494 Pointsi dont know who would that be
Emmanuel Salom
Courses Plus Student 8,320 PointsYou should show some code that way we can help you better.
Konrad Pilch
2,435 PointsWait im making things confusing
Heres a post
https://teamtreehouse.com/forum/php-news-feed-adding-dynamicly
Sorry : p but i believe the code can be different maybe ? : p
1 Answer
thomascawthorn
22,986 PointsHmmm, not quite sure what you're asking. Can you post an example?
Konrad Pilch
2,435 PointsHi,
I did code it quite a bit , now i have to connect the input. Look at the placeholder and youll notice what i mean.
<?php
$posts = array();
$posts[100] = array(
"heading" => "Car for sell",
"paragraph" => "This car is brand new",
"price" => £900 ,
"img" => "img/fb.png"
);
$posts[101] = array(
"heading" => "House",
"paragraph" => "Fashon",
"price" => £900000 ,
"img" => "img/fb.png"
);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Trying PHP News Feed</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<!-- Custom CSS -->
<link href="includes/css/styles.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-9">
<div class="row">
<h1> Shirt Details </h1>
<ul class="posts-wrapper">
<?php foreach($posts as $post){ ?>
<div class="posts">
<?php
echo "<li>";
echo '<h3>'.$post["heading"].'</h3>';
echo '<h5>'.$post["price"].'</h5>';
echo '<p>'.$post["paragraph"].'</p>';
echo '<img src="">';
echo "</li>";
?>
</div><!-- /posts -->
<?php } ?>
</ul>
</div><!-- /row -->
</div><!-- /col-md-9 -->
<div class="col-md-3">
<h1> Add info </h1>
<form>
<div class="row">
<div class="col-xs-12 col-md-12">
<div class="form-group">
<input type="text" name="name" id="name" required class="form-control" placeholder="Title">
</div>
</div>
<div class="col-xs-12 col-md-12">
<div class="form-group">
<input type="email" name="email" id="email" required class="form-control" placeholder="Price">
</div>
</div>
<div class="col-xs-12 col-md-12">
<div class="form-group">
<input type="text" name="name" id="subject" class="form-control" placeholder="Image ( search your desktop)">
</div>
</div>
</div><!-- /row -->
<div class="row">
<div class="col-xs-12">
<div class="form-group" id="messageContact">
<textarea name="message" id="message" required class="form-control" placeholder="Description"></textarea>
</div>
</div>
</div>
<div class="btnContact pull-right">
<button type="submit" class="btn btn-warning custom-button buttonContact">Add post</button>
</div>
</form>
</div>
</div><!-- /row -->
</div><!-- /contaiern -->
</body>
</html>
CSS:
.posts{
border:2px solid black;
margin:5px 0;
}
.posts img{
float:left;
}
Konrad Pilch
2,435 PointsKonrad Pilch
2,435 PointsHI, i think somebody is spamming and not only.
Not sure who to tag but if that even work s: p
Faye Bridge