Add additional Rows in PHP - php

I need to add a button to add more rows, maybe 10 at a time? I also need each added row to have it's own variable name right? So it will echo out in the email template below? Or can it just be a bunch of fields to echo out? I have a team of non-programmers that will be using this form to print out the email template below it, so they can copy and paste. Would really be nice if it could have a button to copy to clipboard, but thats not the main issue.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Remove Bad Links Template</title>
<style>
body {font-family: 'Hammersmith One', sans-serif; color:#333; }
#wrapper { width:75%; margin:0 auto; background:#f2f2f2; border:#ccc; border-radius: 10px; box-shadow:3px 3px 3px #ccc; padding:20px; }
#emailback { background: #fff; padding:20px; }
h1, h2 { color:#0074b9; }
</style>
<link href='http://fonts.googleapis.com/css?family=Hammersmith+One' rel='stylesheet' type='text/css'>
</head>
<body>
<?php
$name = $_GET['name'];
$link1 = $_GET['link1'];
$link2 = $_GET['link2'];
$link3 = $_GET['link3'];
$link4 = $_GET['link4'];
$link5 = $_GET['link5'];
$link6 = $_GET['link6'];
$link7 = $_GET['link7'];
$link5 = $_GET['link8'];
$link6 = $_GET['link9'];
$link7 = $_GET['link10'];
?>
<div id="wrapper">
<h1>Use the following template to request bad link removal</h1>
<form action="" method="GET">
<h3>WEBMASTERS NAME: <input type="text" name="name"></h3>
<h3>BAD LINK 1 <input type="text" name="link1"></h3>
<h3>BAD LINK 2 <input type="text" name="link2"></h3>
<h3>BAD LINK 3 <input type="text" name="link3"></h3>
<h3>BAD LINK 4 <input type="text" name="link4"></h3>
<h3>BAD LINK 5 <input type="text" name="link5"></h3>
<h3>BAD LINK 6 <input type="text" name="link6"></h3>
<h3>BAD LINK 7 <input type="text" name="link7"></h3>
<h3>BAD LINK 8 <input type="text" name="link8"></h3>
<h3>BAD LINK 9 <input type="text" name="link9"></h3>
<h3>BAD LINK 10 <input type="text" name="link10"></h3>
<input type="submit">
</form>
<p>
<h2>THEN COPY AND PASTE THE FOLLOWING AFTER SUBMITTING THE ABOVE FORM: </h2>
<div id="emailback">
Hi <?php echo $name; ?>, </p>
<p>
We have recently received a notification from Google stating that our website has unnatural links pointing towards it. This has really damaged our rankings on Google and as a result, we're trying to clear things up. Our website url is http://********.com.
</p><p>
We noticed the following links are pointing to our website from your site:
</p><p>
<h3><?php echo $link1; ?></h3>
<h3><?php echo $link2; ?></h3>
<h3><?php echo $link3; ?></h3>
<h3><?php echo $link4; ?></h3>
<h3><?php echo $link5; ?></h3>
<h3><?php echo $link6; ?></h3>
<h3><?php echo $link7; ?></h3>
<h3><?php echo $link8; ?></h3>
<h3><?php echo $link9; ?></h3>
<h3><?php echo $link10; ?></h3>
</p><p>
I appreciate this is inconvenient and isn't a reflection on your website at all, but if you're able to remove the links, we would really appreciate it and would be very grateful.
</p><p>
I look forward to hearing from you.
</p><p>
Jerry *****
</p><p>
*********
</p>
</p>
</div>
</div>
</body>
</html>

Alright, let's start with some DRY work.
<?php
$name = isset($_GET['name']) ? $_GET['name'] : 'Webmaster';
$links = $_GET['links'] ? $_GET['links'] : array_fill(0, 10, '');
if (isset($_GET['add-rows'])) {
for ($i = 0; $i < 10; $i++) {
$links[] = '';
}
}
?>
And then modify your form:
<form method="GET">
<h3>WEBMASTERS NAME: <input type="text" name="name"></h3>
<?php
for ($i = 0; $i < count($links); $i++) {
echo '<h3>BAD LINK ' . ($i + 1) . ' <input type="text" name="links[]"></h3>';
}
?>
<input name="add-rows" type="submit" value="Add Rows">
<input type="submit" value="Submit">
</form>
And finally, change how your links output:
<p>
<?php
for ($i = 0; $i < count($links); $i++) {
echo '<h3>' . $links[$i] . '</h3>';
}
?>
</p>

Related

How to keep session variables between pages with forms?

I'm writing a program that has 3 pages.
On page 1 there is an option for the user to select a quantity of a breakfast product he wants to purchase. After selecting a quantity the user hits the submit button, if the user is not registered, it will take him to Page 2 for him to register. If the user is registered, it will direct them to Page 3.
However, if the user goes to Page 2 first and does not have a quantity selected from Page 1 it will redirect him to Page 1 after he registers and press submit, and then once they select a quantity and hit submit on Page 1 it will go to Page 3.
I'm struggling to maintain my session variables between the pages because two of them have forms that get overwritten if the user ever goes back to that page.
Page 1:
<?php
session_start();
$_SESSION['name']= $_POST['name'];
$_SESSION['email']= $_POST['email'];
$platter_quantity = $_SESSION['platter_quantity'];
$yogurt_quantity = $_SESSION['yogurt_quantity'];
$waffles_quantity = $_SESSION['waffles_quantity'];
?>
<!DOCTYPE html>
<head>
<title>Product Page</title>
<link rel="stylesheet" type"text/css" href="settings.css">
</head>
<html>
<body>
<ul>
<li><a class="active" href="product.php">Product</a></li>
<li>Registration</li>
<li>Invoice</li>
<li style="float:right">Login</li>
</ul>
<?php
$action = '';
if (!empty($_SESSION['name']) or !empty($_SESSION['email'])) {
$action = "invoice.php";
}
else {
$action = "registration.php";
}
?>
<form action="<?php echo $action; ?>" method="post">
<div class="container">
<img src="images/platter.jpg" alt="Breakfast Platter" style="float: left; width: 400px; height: 300px;";>
<h1>Breakfast Platter</p>
<p>The breakfast platter option comes with two fried eggs, four pancakes, and a bunch of bacon.</p>
Quantity: <input type="number" name="platter_quantity" min="0">
<p value="10.99" name="platter_price">Price: $10.99</p>
</div>
<div class="container">
<img src="images/yogurt.jpg" alt="Yogurt Parfait" style="float: left; width: 400px; height: 300px;">
<h1>Yogurt Parfait</p>
<p>The yogurt parfait option comes with two cups of yogurt, oats, and a mixture of berries.</p>
Quantity: <input type="number" name="yogurt_quantity" min="0">
<p value="6.99" name="yogurt_price">Price: $6.99</p>
</div>
<div class="container">
<img src="images/waffles.jpg" alt="Waffles" style="float: left; width: 400px; height: 300px;";>
<h1>Waffles</p>
<p>The waffles option comes with two buttermilk waffles with butter and syrup.</p>
Quantity: <input type="number" name="waffles_quantity" min="0">
<p value="$4.99" name="waffles_price">Price: $4.99</p>
</div>
<br>
<button class="button" type="submit" name="submit">Submit</button>
</form>
</body>
</html>
Page 2:
<?php
session_start();
$name = $_SESSION['name'];
$email = $_SESSION['email'];
$_SESSION['platter_quantity'] = $_POST['platter_quantity'];
$_SESSION['yogurt_quantity'] = $_POST['yogurt_quantity'];
$_SESSION['waffles_quantity'] = $_POST['waffles_quantity'];
?>
<!DOCTYPE html>
<head>
<title>Registration Page</title>
<link rel="stylesheet" type"text/css" href="settings.css">
</head>
<html>
<body>
<ul>
<li>Product</li>
<li><a class="active" href="registration.php">Registration</a></li>
<li>Invoice</li>
<li style="float:right">Login</li>
</ul>
<br>
<?php
$action = '';
if (!empty($_SESSION['platter_quantity']) or !empty($_SESSION['yogurt_quantity']) or !empty($_SESSION['waffles_quantity'])) {
$action = "invoice.php";
}
else {
$action = "product.php";
}
?>
<form action="<?php echo $action; ?>" method="post">
Name: <input type="text" name="name" pattern="[A-Za-z]" required><br><br>
E-mail: <input type="text" name="email" pattern="/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+#[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/" required><br><br>
<input type="submit">
</form>
<br>
<?php
print_r($_SESSION);
echo "<br>Platter: " . $_SESSION["platter_quantity"] . "<br>";
echo "Yogurt: " . $_SESSION["yogurt_quantity"] . "<br>";
echo "Waffles: " . $_SESSION["waffles_quantity"];
?>
</body>
</html>
Page 3:
<?php
session_start();
$name = $_SESSION['name'];
$email = $_SESSION['email'];
$platter_quantity = $_SESSION['platter_quantity'];
$yogurt_quantity = $_SESSION['yogurt_quantity'];
$waffles_quantity = $_SESSION['waffles_quantity'];
?>
<!DOCTYPE html>
<head>
<title>Invoice Page</title>
<link rel="stylesheet" type"text/css" href="settings.css">
</head>
<html>
<body>
<ul>
<li>Product</li>
<li>Registration</li>
<li><a class="active" href="invoice.php">Invoice</a></li>
<li style="float:right">Login</li>
</ul>
<h1>Hi! Welcome <?php echo $_SESSION['name']; ?>! </h1>
<?php
print_r($_SESSION);
echo "<br>Platter: " . $platter_quantity . "<br>";
echo "Yogurt: " . $yogurt_quantity . "<br>";
echo "Waffles: " . $waffles_quantity;
?>
</body>
</html>
What's the best way for me to implement this using session variables without using a database?
I tried doing this as well, but it did not seem to work:
<?php
session_start();
if (empty($_SESSION['name']) or empty($_SESSION['email'])) {
$_SESSION['name'] = $POST_['name'];
$_SESSION['email'] = $POST_['email'];
}
else {
$name = $_SESSION['name'];
$name = $_SESSION['email'];
}
if (empty($_SESSION['platter_quantity']) or empty($_SESSION['yogurt_quantity']) or ($_SESSION['waffles_quantity'])) {
$_SESSION['platter_quantity'] = $POST_['platter_quantity'];
$_SESSION['yogurt_quantity'] = $POST_['yogurt_quantity'];
$_SESSION['waffles_quantity'] = $POST_['waffles_quantity'];
}
else {
$platter_quantity = $_SESSION['platter_quantity'];
$yogurt_quantity = $_SESSION['yogurt_quantity'];
$waffles_quantity = $_SESSION['waffles_quantity'];
}
?>
You never insert $_POST or $_GET without first checking if they're set isset($_POST['variable']), and you can use checks here as well - do a check for the existence of $_POST-variables, and if they exist, use them, and if not, assign the $_SESSION-variables. So on page 3, you will have something like:
$name = $_SESSION['name'] = (isset($_POST['name']) ? $_POST['name'] : ((isset($_SESSION['name']) ? $_SESSION['name'] : '')));
And so on for the other variables. What this does is checks for $_POST, and if it's set, it updates the $_SESSION-variable, and if it's not set, it just updates the $_SESSION-variable with the already existing $_SESSION-variable, and if that doesn't exist either, it sets both variables $name and $_SESSION['name'] to empty, which you then can check for later in the script (and redirect etc.)

wrap post in div, and the comment in same div. reproduce reddit nested comment css

I have been trying to mimick the nested comment system that reddit use. Now i have a app that does in a way look like what it was intended to look. But, if you have a look at the reddit style:
I haven't been able to reproduce the lines that attach the previous answer.
My thought is that is nested divs somehow.
currenlty I'm outputting the db data lik this:
<?php if(!empty(getMessage())): ?>
<div class="container">
<h1>The nested comment exampel!</h1>
<?php foreach (getMessage() as $value){ ?>
<div class="level_<?= $value->level; ?> comment" id="<?= $value->id; ?>">
<?php if($value->visible == 0) : ?>
<?= $value->date ?><br>
Deleted
<?php elseif($value->visible == 1): ?>
<?= $value->date ?> X <?= 'id: '. $value->id . ', sort order: ' .$value->sort_order . ', level: '.$value->level ;?><br>
<?= $value->comment_text ?>
<form action="index.php" method="post">
<input type="hidden" name="id" value="<?= $value->id ?>" />
<input type="hidden" name="parent" value="<?= $value->reply_to ?>" />
Add comment: <input type="text" name="svar">
<input type="submit">
</form>
<?php endif; ?>
</div>
<?php } endif; ?>
</div>
And i have solved the left margin with a simpel (not so clean) solution with
<style>
div.level_ {
margin-left: 00px;
}
div.level_1 {
margin-left: 20px;
}
div.level_2 {
margin-left: 40px;
}
div.level_3 {
margin-left: 60px;
}
div.level_4 {
margin-left: 80px;
}
div.level_5 {
margin-left: 100px;
}
div.level_6 {
margin-left: 120px;
}
div.level_7 {
margin-left: 140px;
}
div.level_8 {
margin-left: 160px;
}
div.level_9 {
margin-left: 180px;
}
div.level_10 {
margin-left: 200px;
}
</style>
I have these columns in the database
id,comment_text, reply_to, sort_order, level, date, ip, visible
And my "clone" or what you can call it simply reads the parent id (reply to) and updates all rows if a comment is addad before. if a comment is addad to the first comment/post, the sort_order is simply +1.
But, how can i output a "comment" inside the post. and a answer
comment inside its parent comment.
Currently it looks like this
EDIT
To make it clear i have prepared some mock up data.
Here is the result I'm looking for: http://jsfiddle.net/wv9j9ueo/
With dis data http://pastie.org/10400764 notice the level column. Shouldn't it be possible to foreach the column levelfrom 0 and then keep going until there is nothing left (notice that the can be two or more of the same value).
If you put divs into the parents your code looks prettiest:
<div class="comment">
<p>The comment</p>
<div class="comment">
<p>The comment</p>
<div class="comment"> <p>The comment</p></div>
</div>
</div>
Css
.comment {
margin-left: 15px;
border-left : 2px dotted blue;
padding : 0 10px;
}
PHP
<?php if(!empty(getMessage())): ?>
<div class="container">
<h1>The nested comment exampel!</h1>
<?php
$i=0; //initialize flag
foreach (getMessage() as $value){ ?>
<div class="comment" id="<?= $value->id; ?>">
//you don't need level class
<?php if($value->visible == 0) : ?>
<?= $value->date ?><br>
Deleted
<?php elseif($value->visible == 1): ?>
<?= $value->date ?> X <?= 'id: '. $value->id . ', sort order: ' .$value->sort_order . ', level: '.$value->level ;?><br>
<?= $value->comment_text ?>
<form action="index.php" method="post">
<input type="hidden" name="id" value="<?= $value->id ?>" />
<input type="hidden" name="parent" value="<?= $value->reply_to ?>" />
Add comment: <input type="text" name="svar">
<input type="submit">
</form>
<?php endif; ?>
<?php
$i++; //sum flag
}
for($x=0; $x<=$i; $x++) { //paint div closers
echo '</div>' ;
}
?>
<? endif; ?>
</div>
See it working
http://jsfiddle.net/jc5104st/1/

Redirect if page is blank

I'm working on some sort of search engine that adds on to a URL to complete the request. using header(Location:http://www.WEBSITENAME.com/'. $search); Although sometimes this will send me to a blank page. Was wondering if there's any sort of code that will redirect me to another page if that error happens. I want the else to be what it redirects to if the page is blank. Thanks.
My code:
search.php
<?php
$search = $_POST["search"];
if(isset($_POST['search'])){
header('Location:http://cydia.saurik.com/package/'.$search);
}else{
?>
<?php
echo "
<head>
<style>
#header{
color:black;
}
.header{
color:black;
font-size:25px;
}
#header_minor{
margin-top:20px;
}
.header_minor{
font-size:18px;
}
a[class='header_minor']{
color:black;
}
body{
text-align:center;
margin-top:14%;
}
#idea{
margin-top:20px;
}
.hidden{
display:none;
visibility:hidden;
}
</style>
</head>
";
?>
<div id="header">
<span class="header">
Sorry, this tweak was not found...
</span>
</div>
<div id="header_minor">
<span class="header_minor">
Would you like to suggest it? or Return home
</span>
</div>
<div id="idea">
<form method="POST" action="idea.php" name="idea">
<input type="text" name="idea" value="<?php echo $_POST['search']; ?>"/>
<input type="text" name="hidden" class="hidden"/>
<input type="submit" value="Submit"/>
</form>
</div>
<?php
exit();
}
?>
It could have been better if you can call an api on that site so that you can interact easier with the external site.
I would do something like this:
PHP:
<?php
if(isset($_POST['search'])) {
$search_text = $_POST['search_field'];
$location_url = "http://cydia.saurik.com/package/{$search_text}/";
$content = #file_get_contents($location_url); // use this function to query on site
if($content) {
// redirect if it has a result
header("Location: {$location_url}");
} else {
// will go here if query on external site is empty (blank)
// create your own empty result page that says your search yielded no results (your own page, redirect the user)
// sample
header("Location: http://www.yoursite.com/index.php?noresults=1");
}
}
?>
HTML:
<form method="POST" action="index.php">
<input type="text" name="search_field" class="" id="" /><br/>
<input type="submit" name="search" class="" id="" value="Search" />
</form>
<?php if(isset($_GET['noresults'])): ?>
<div class="yourdesign" style="display: block; width: 300px; border: 1px solid black;";>
<h1>No results found</h1>
</div>
<?php endif; ?>

syntax error, unexpected T_ECHO, expecting ',' or ';' in /Secured_Page_Edit.php on line 110

<?php
session_start();
if (!isset($_SESSION['username'])) {
header('Location: LoginForm.php');
}
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Secured Page</title>
<style>
.db-table {position:absolute;top:95px;left:300px;}
</style>
</head>
<body>
<p align="left" style="margin-left:0px; margin-top:135px;">
<form action="Secured_Page_Search.php" method="post">
Select_Table_To_Display:<br><select name="Table">
<option value="members">Members</option>
<option value="online">Online</option>
<input type="submit" name="submit_name" />
</form>
<title>Secured Page</title>
<style type="text/css">
body{font-family:Impact;}
#container{width:10000px;margin:auto;font-size:15pt;}
#menu{position:absolute;margin-top:10px;}
#menu ul .item{display:none;}
#menu ul:hover .item{display:block;background:#white;padding:1px;margin:1px;}
#menu ul:hover .item a{color:#abc;text-decoration:none;}
#menu ul:hover .item a:hover{color:grey;}
#menu ul{width:110px;float:left;margin:0px;padding:2px;background:white;list-
Style:none;}
.clear{clear:both;height:10px;}
</style>
<div id="container">
<h1></h1>
<div id="menu">
<p align="left" style="margin-left:0px; margin-top: 0px;">
<br><FONT FACE="arial">Logged In #: (<?php echo $_SESSION['username']; ?>)</FONT></p>
</p>
<ul id="item1">
<li class="top">Profile</li>
<li class="item">Profile User</li>
<li class="item"><a href="#">Profile I.M.</li>
<li class="item">Profile O.P.</li>
</ul>
<ul id="item1">
<li class="top">Edit</li>
<li class="item">Edit User</li>
<li class="item"><a href="#">Edit I.M.</li>
<li class="item">Edit O.P.</li>
</ul>
</div>
<div class="clear"></div>
</body>
<br><FONT FACE="arial">
<?php
$Table = 'members';
$mysqli = new mysqli("XXXXXXXX", "XXXXXXXX", "XXXXXXXX", "XXXXXXXXXX");
$result = $mysqli->query("SHOW TABLES");
while ( $row = $result->fetch_row() ){
$table = $row[0];
$result1 = $mysqli->query("SELECT * FROM $Table ORDER BY dt DESC LIMIT 0,12");
if($result1) {
echo '<table cellpadding="15" cellspacing="20" class="db-table">';
$column = $mysqli->query("SHOW COLUMNS FROM $Table");echo '<tr>';
while($row3 = $column->fetch_row() ) {
echo '<th>'.$row3[0].'</th>';
}
echo '</tr>';
while($row2 = $result1->fetch_row() ) {
echo '<tr>';
foreach($row2 as $key=>$value) {
LINE 110 ----> echo '<td style="padding-top:0px;padding-bottom:0px;">',$value,'
'Edit'</td>;'<------Line 110
}
echo '</tr>';
}
echo '</table><br />';
}
}
$mysqli->close();
?>
<FONT FACE="impact">
<p align="left" style="margin-left:100px; margin-top:100PX;">
<form action="Secured_Page_Search_Email.php" method="post">
Search, Email:<br> <input type="text" name="email"><br>
<input type="submit" name="submit_name" />
</form>
<p align="left" style="margin-left:100px; margin-top:10px;">
<form action="Secured_Page_Search_User.php" method="post">
Search, User:<br> <input type="text" name="usr"><br>
<input type="submit" name="submit_name" />
</form>
</FONT></p>
</body>
</html>
Basically i need the mysql table to print with a edit link... Seems so easy, but have been battling with this issue the last few hours. Line that has an issue:
Basically i need the mysql table to print with a edit link... Seems so easy, but have been battling with this issue the last few hours. Line that has an issue:
LINE 110 ----> echo '<td style="padding-top:0px;padding-bottom:0px;">',$value,'
'Edit'</td>;'<------Line 110
UPDATED CODE UPDATED CODE
echo '<td>'Edit'</td>;'
Parse error: syntax error, unexpected T_ECHO, expecting ',' or ';' in Secured_Page_Edit.php on line 113
echo '<td style="padding-top:0px;padding-bottom:0px;">'.$value.'
Edit</td>';
The way you concatenate text and variables is wrong. See http://php.net/manual/en/language.operators.string.php
You should write something like this:
LINE 110 ----> echo '<td style="padding-top:0px;padding-bottom:0px;">' . $value . '
Edit</td>;'<------Line 110
More precisely, mixing dots and comma is fine, but if you use single quotes with echo, you should make sure to put either a dot or a comma right after them (if you want to continue your string [1]) or a semicolon if you're done [2].
echo 'Text and '.$variable; // [1]
echo $variable.' and text'; // [2]
See also http://us.php.net/manual/en/function.echo.php.
Your php open/close tags are part of what is being echoed. As well as using commas rather then dots (.) to append the $value. However there is no reason to echo into the html string when already building the string in php.
echo '<td style="padding-top:0px;padding-bottom:0px;">',$value,''Edit'</td>;'
I think you want:
echo '<td style="padding-top:0px;padding-bottom:0px;">'.$value.'Edit</td>;'
// Changes are: ^ ^ ^ ^
UPDATE (Thanks Fred) You can in fact use commas to append a string in an echo call. So this would also be valid:
echo '<td style="padding-top:0px;padding-bottom:0px;">', $value, 'Edit</td>;'

posts overlapping

Now i dont know if this is simple or hard. If its just css or php code i need
But basically i have posting system and users can comment on posts. In the comments page it shows orginal post and one users have left (the comments)
I had one in there and this was fine but i added another and it looked like this...
[1]: http://i.stack.imgur.com/2fIXd.jpg
As you can see its completly different! Heres my code for it...
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("test");
echo "<a href='Untitled9.php'>Go Back...</a>";
?>
<br/><br/>
<div class="message">
<?php
$sql = mysql_query("SELECT * FROM threads WHERE id = '".
mysql_real_escape_string($_GET['id']) . "'") or die(mysql_error());
while($r = mysql_fetch_array($sql)) {
$posted = date("jS M Y h:i",$r['posted']); echo "".$r['author']." $posted"; ?>
<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-text="<?php echo "".$r['message'].""; ?>">
Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
<div class="message2"><?php echo " ".$r['message'].""; ?></div>
<?php echo "Likes: ".$r['votes_up']." "; echo "Dislike: ".$r['votes_down']."";>
</div>
<br/>
<hr width="725px">
<?php
echo "<h3>Replies...</h3>"; ?>
<div class="message"><?php
$sql = mysql_query("SELECT * FROM replies WHERE thread = '".
mysql_real_escape_string($_GET['id']) . "'") or die(mysql_error());
while($r = mysql_fetch_array($sql)) {
$posted = date("jS M Y h:i",$r['posted']); echo "".$r['author']." $posted"; ?>
<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-text="<?php echo "".$r['message'].""; ?>">
Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
<div class="message2">
<?php echo " ".$r['message']."" ; } ?> </div>
</div>
<hr width="725px">
<form action="newreply.php" method="POST">
Your Name: <input type="text" name="author">
<input type="hidden" value="<?php echo $_GET['id']; ?>" name="thread"><br>
Message:<br><textarea cols="60" rows="5" name="message"></textarea><br>
<input type="submit" value="Post Reply">
</form>
The code looks really messy on here. I tried editing but couldnt get much better.
So bascially what i want to know is how do i prevent this (the overlapping) from happening?
Edit * CSS
.message {
width: 500px;
color: black;
background: white;
padding:8px;
border:1px solid white;
margin:5px auto;
-moz-border-radius:8px;
}
.message2 {
background-color: grey;
}
It looks to me as though everything is posting inside the second php function but i have some code pretty much the same for just the individual post and this displays normally i.e. as many as i want. Im just wondering is there something i need to add/change
Wrong (Your code):
<?php echo " ".$r['message']."" ; } ?> </div>
</div>
Correct:
<?php echo " ".$r['message']."" ; ?> </div>
</div>
<?php } ?>
You were opening multiple DIVs in your while loop but only closing two.
Similarly to Cobra_Fast's reply, it seems that the positioning of your divs seemed to be causing the problem, and also the position of your while loop.
Try replacing the replies section with the following and let me know if it is any better.
<?php
echo "<h3>Replies...</h3>";
$sql = mysql_query("SELECT * FROM replies WHERE thread = '".mysql_real_escape_string($_GET['id']) . "'") or die(mysql_error());
while($r = mysql_fetch_array($sql)) {
?>
<div class="message">
$posted = date("jS M Y h:i",$r['posted']);
echo $r['author']." ".$posted;
?>
<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-text="<?php echo $r['message']; ?>">
Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
</div>
<div class="message2">
<?php
echo " ".$r['message'];
?>
</div>
<?php
}
?>

Categories