PHP not sending using Website X5 evelution 9 on Godaddy - php

I've been trying to figure out why everything seems to work perfectly, but no emails are ever sent.
I contacted Godaddy, they checked everything on there end, and even sent an email from my site that i was able to receive. Right now I'm just working on a basic contact form, but have a much larger project in the making, and would like my web builder to handle the small form first.
Here is the Code from the html/Form side:
<form id="imObjectForm_8" action="mail/imEmailForm.php" method="post" enctype="multipart/form-data" style="width: 505px; margin: 0; padding: 0; text-align: left;">
<fieldset class="first">
<div>
<div style="float: left; margin: 0; padding: 0 0 2px;"><label for="imObjectForm_8_1" style="vertical-align: top; display: inline-block; margin: 3px 0 2px; width: 246px;">Name*</label><br /><input type="text" class="mandatory" style="float: left; width: 220px; margin-right: 2px; vertical-align: top; padding-top: 2px; padding-bottom: 2px;" id="imObjectForm_8_1" name="imObjectForm_8_1" /><img id="imObjectForm_8_1_tip" src="res/info.gif" title="" onmouseover="x5engine.imTip.Show(this, { text: 'Enter your name here.', position: 'top' })" alt="Tip" style="vertical-align: top; margin-top: 5px;" /></div>
<div style="float: left; margin: 0; padding: 0 0 2px;"><label for="imObjectForm_8_2" style="vertical-align: top; display: inline-block; margin: 3px 0 2px; width: 246px;">Email*</label><br /><input type="text" class="mandatory valEmail" style="float: left; width: 220px; margin-right: 2px; vertical-align: top; padding-top: 2px; padding-bottom: 2px;" id="imObjectForm_8_2" name="imObjectForm_8_2" /><img id="imObjectForm_8_2_tip" src="res/info.gif" title="" onmouseover="x5engine.imTip.Show(this, { text: 'Enter your email address here.', position: 'top' })" alt="Tip" style="vertical-align: top; margin-top: 5px;" /></div>
<div class="imClear" style="height: 1px; line-height: 1px; width: 505px;"></div>
<div style="float: left; margin: 0; padding: 0 0 2px;"><label for="imObjectForm_8_3" style="vertical-align: top; display: inline-block; margin: 3px 0 2px; width: 246px;">Reason for contact*</label><br /><select class="mandatory" style="float: left; width: 220px; margin-right: 2px; vertical-align: top; padding-top: 2px; padding-bottom: 2px;" id="imObjectForm_8_3" name="imObjectForm_8_3"><option value="">-</option><option value="Questions">Questions</option><option value="Comments">Comments</option><option value="Suggestions">Suggestions</option><option value="Requests">Requests</option><option value="Other">Other</option></select><img id="imObjectForm_8_3_tip" src="res/info.gif" title="" onmouseover="x5engine.imTip.Show(this, { text: 'Select the reason you are contacting us.', position: 'top' })" alt="Tip" style="vertical-align: top; margin-top: 5px;" /></div>
<div style="float: left; margin: 0; padding: 0 0 2px;"><label for="imObjectForm_8_4" style="vertical-align: top; display: inline-block; margin: 3px 0 2px; width: 246px;">Phone #</label><br /><input type="text" class="" style="float: left; width: 220px; margin-right: 2px; vertical-align: top; padding-top: 2px; padding-bottom: 2px;" id="imObjectForm_8_4" name="imObjectForm_8_4" /><img id="imObjectForm_8_4_tip" src="res/info.gif" title="" onmouseover="x5engine.imTip.Show(this, { text: 'Phone # is optinal, but suggested if requesting we contact your back.', position: 'top' })" alt="Tip" style="vertical-align: top; margin-top: 5px;" /></div>
<div class="imClear" style="height: 1px; line-height: 1px; width: 505px;"></div>
<div style="float: left; margin: 0; padding: 0 0 2px;"><label for="imObjectForm_8_5" style="vertical-align: top; display: inline-block; margin: 3px 0 2px; width: 499px;">Message*</label><br /><textarea class="mandatory" style="float: left; width: 473px; margin-right: 2px; vertical-align: top; padding-top: 2px; padding-bottom: 2px; padding-left: 0; padding-right: 0; height: 130px;" id="imObjectForm_8_5" name="imObjectForm_8_5"></textarea><img id="imObjectForm_8_5_tip" src="res/info.gif" title="" onmouseover="x5engine.imTip.Show(this, { text: 'Enter your message here.', position: 'top' })" alt="Tip" style="vertical-align: top; margin-top: 5px;" /></div>
</div>
</fieldset>
<fieldset>
<input type="hidden" id="imObjectForm_8_prot" name="imSpProt" />
</fieldset>
<div style="width: 505px; text-align: center;">
<input type="submit" value="Send" />
<input type="reset" value="Reset" />
</div>
</form>
Here is the PHP file:
<?php
$settings['imEmailForm_19_8'] = array(
"owner_email_from" => "Email",
"owner_email_to" => "noah_swett#yahoo.com",
"customer_email_from" => "noah_swett#yahoo.com",
"customer_email_to" => "",
"owner_message" => "New email from the website. message:",
"customer_message" => "",
"owner_subject" => "New Message",
"customer_subject" => "",
"owner_csv" => False,
"customer_csv" => False,
"confirmation_page" => "../confirmation.html"
);
if(substr(basename($_SERVER['PHP_SELF']), 0, 11) == "imEmailForm") {
include "../res/x5engine.php";
$answers = array(
);
$form_data = array(
array('label' => 'Name', 'value' => $_POST['imObjectForm_8_1']),
array('label' => 'Email', 'value' => $_POST['imObjectForm_8_2']),
array('label' => 'Select', 'value' => $_POST['imObjectForm_8_3']),
array('label' => 'Your Message', 'value' => $_POST['imObjectForm_8_4'])
);
$files_data = array(
);
if(#$_POST['action'] != "check_answer") {
if(!isset($_POST['imJsCheck']) || $_POST['imJsCheck'] != "jsactive")
die(imPrintJsError());
if (isset($_POST['imCpt']) && !isset($_POST['imCptHdn']))
die(imPrintJsError());
if(isset($_POST['imSpProt']) && $_POST['imSpProt'] != "")
die(imPrintJsError());
$email = new imSendEmail();
$email->sendFormEmail($settings['imEmailForm_19_8'], $form_data, $files_data);
#header('Location: ' . $settings['imEmailForm_19_8']['confirmation_page']);
} else {
if(#$_POST['id'] == "" || #$_POST['answer'] == "" || strtolower(trim($answers[#$_POST['id']])) != strtolower(trim(#$_POST['answer'])))
echo "0";
else
echo "1";
}
}
Code from imengine.php
function sendFormEmail($form, $form_data, $files_data, $user_only = FALSE) {
global $imSettings;
if (!is_array($form))
$settings = $imSettings['email_form'][$form_id];
else
$settings = $form;
//Form Data
$txtData = "";
$htmData = "";
$csvHeader = "";
$csvData = "";
$customer_email_to = "";
$owner_email_from = "";
foreach ($form_data as $field) {
if (is_array($field['value'])) {
$txtData .= $field['label'] . ": " . implode(", ", $field['value']) . "\r\n";
$htmData .= "<tr valign=\"top\"><td width=\"25%\"><b>" . $field['label'] . ":</b></td><td>" . implode(", ", $field['value']) . "</td></tr>";
if ($settings['customer_csv'] || $settings['owner_csv']) {
$csvHeader .= $field['label'] . ";";
$csvData .= implode(", ", $field['value']) . ";";
}
} else {
if (isset($settings['customer_email_to']) && $field['label'] == $settings['customer_email_to'])
$customer_email_to = $field['value'];
if (isset($settings['owner_email_from']) && $field['label'] == $settings['owner_email_from'])
$owner_email_from = $field['value'];
$txtData .= $field['label'] . ": " . $field['value'] . "\r\n";
// Is it an email?
if (preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\#([a-z0-9])' . '(([a-z0-9-])*([a-z0-9]))+' . '(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i',$field['value'])) {
$htmData .= "<tr valign=\"top\"><td width=\"25%\"><b>" . str_replace(array("\\'", '\\"'), array("'", '"'), $field['label']) . ":</b></td><td>". $field['value'] . "</td></tr>";
} else if (preg_match('/^http[s]?:\/\/[a-zA-Z0-9\.\-]{2,}\.[a-zA-Z]{2,}/', $field['value'])) {
// Is it an URL?
$htmData .= "<tr valign=\"top\"><td width=\"25%\"><b>" . str_replace(array("\\'", '\\"'), array("'", '"'), $field['label']) . ":</b></td><td>". $field['value'] . "</td></tr>";
} else {
$htmData .= "<tr valign=\"top\"><td width=\"25%\"><b>" . str_replace(array("\\'", '\\"'), array("'", '"'), $field['label']) . ":</b></td><td>" . str_replace(array("\\'", '\\"'), array("'", '"'), $field['value']) . "</td></tr>";
}
if ($settings['customer_csv'] || $settings['owner_csv']) {
$csvHeader .= str_replace(array("\\'", '\\"'), array("'", '"'), $field['label']) . ";";
$csvData .= str_replace(array("\\'", '\\"'), array("'", '"'), $field['value']) . ";";
}
}
}
// Template
$htmHead = $imSettings['email']['header'];
$htmFoot = $imSettings['email']['footer'];
//Send email to owner
if (!$user_only && isset($settings['owner_email_to']) && $settings['owner_email_to'] != "") {
$txtMsg = $settings['owner_message'];
$htmMsg = nl2br($settings['owner_message']);
if (strpos($owner_email_from, "#") === FALSE || strlen($owner_email_from) == 0)
$owner_email_from = $settings['owner_email_to'];
$oEmail = new imEMail($owner_email_from, $settings['owner_email_to'], $settings['owner_subject'], "utf-8");
$oEmail->setText($txtMsg . "\n\n" . $txtData);
$oEmail->setHTML($htmHead . $htmMsg . "<br><br><table border=0 width=\"100%\" style=\"" . $imSettings['email']['email_content_style'] . "\">" . $htmData . "</table>" . $htmFoot);
if ($settings['owner_csv'])
$oEmail->attachFile("form_data.csv", $csvHeader . "\n" . $csvData, "text/csv");
if (count($files_data) > 0) {
foreach ($files_data as $file) {
if (file_exists($file['value']['tmp_name']))
$oEmail->attachFile($file['value']['name'], file_get_contents($file['value']['tmp_name']), $file['value']['type']);
}
}
$oEmail->send();
}
//Send email to user
if ($customer_email_to != "") {
$txtMsg = $settings['customer_message'];
$htmMsg = nl2br($settings['customer_message']);
if ($settings['customer_email_from'] == "")
$settings['customer_email_from'] = $settings['owner_email_to'];
$oEmail = new imEMail($settings['customer_email_from'], $customer_email_to, $settings['customer_subject'], "utf-8");
if ($settings['customer_csv']) {
$oEmail->setHTML($htmHead . $htmMsg . "<br><br><table border=0 width=\"100%\" style=\"" . $imSettings['email']['email_content_style'] . "\">" . $htmData . "</table>" . $htmFoot);
$oEmail->setText($txtMsg . "\n\n" . $txtData);
} else {
$oEmail->setText($txtMsg);
$oEmail->setHTML($htmHead . $htmMsg . $htmFoot);
}
$oEmail->send();
}
}
Please help!

Related

How to change the padding with HTML/PHP?

This is my php code I use. But for on or other reason it doesn't change with my CSS. I keeps on giving it weight of the picture lenght & height. You can see in the screenshot what goes wrong. The HtmlTable of my does change but my doesn't. WORKS -> PHP ERROR CSS -> ERROR
$htmlTabel = '';
$htmlTabel .= '<table border="1px">';
$htmlTabel .= '<tr>';
$htmlTabel .= '<th style="padding: 10px; padding-right: 35px; padding-left: 35px;">Foto</th>';
$htmlTabel .= '<th style="padding: 10px; padding-right: 35px; padding-left: 35px;">Type</th>';
$htmlTabel .= '<th style="padding: 10px; padding-right: 35px; padding-left: 35px;">Prijs</th>';
$htmlTabel .= '<th style="padding: 10px; padding-right: 35px; padding-left: 35px;">Adres</th>';
$htmlTabel .= '<th style="padding: 10px; padding-right: 35px; padding-left: 35px;">Woonopp</th>';
$htmlTabel .= '<th style="padding: 10px; padding-right: 35px; padding-left: 35px;">Grondopp</th>';
$htmlTabel .= '<th style="padding: 10px; padding-right: 35px; padding-left: 35px;">Slaapkamers</th>';
$htmlTabel .= '<th style="padding: 10px; padding-right: 35px; padding-left: 35px;">Badkamers</th>';
$htmlTabel .= '<th style="padding: 10px; padding-right: 35px; padding-left: 35px;">Bebouwing</th>';
$htmlTabel .= '<th style="padding: 10px; padding-right: 35px; padding-left: 35px;">Bouwjaar</th>';
$htmlTabel .= '<th style="padding: 10px; padding-right: 35px; padding-left: 35px;">Beschrijving</th>';
$htmlTabel .= '</tr>';
for ($i = 1; $i <= $adsId; $i++) {
$url = "http://localhost:55342/api/tekoop/" . $i; // path to your JSON file
$data = file_get_contents($url); // put the contents of the file into a variable
$apidata = json_decode($data); // decode the JSON feed
$img = "<img src='img/$apidata->images' width='500px' height='500px'></img>";
$htmlTabel .= '<tr>' .
'<td style="padding: 10px; padding-right: 35px; padding-left: 35px;">' . $img . '</td>' .
'<td style="padding: 10px; padding-right: 35px; padding-left: 35px;">' . $apidata->type . '</td>' .
'<td style="padding: 10px; padding-right: 35px; padding-left: 35px;">' . $apidata->prijs . '</td>' .
'<td style="padding: 10px; padding-right: 35px; padding-left: 35px;">' . $apidata->adres . '</td>' .
'<td style="padding: 10px; padding-right: 35px; padding-left: 35px;">' . $apidata->woonopp . '</td>' .
'<td style="padding: 10px; padding-right: 35px; padding-left: 35px;">' . $apidata->grondopp . '</td>' .
'<td style="padding: 10px; padding-right: 35px; padding-left: 35px;">' . $apidata->slaapkamers . '</td>' .
'<td style="padding: 10px; padding-right: 35px; padding-left: 35px;">' . $apidata->badkamers . '</td>' .
'<td style="padding: 10px; padding-right: 35px; padding-left: 35px;">' . $apidata->bebouwing . '</td>' .
'<td style="padding: 10px; padding-right: 35px; padding-left: 35px;">' . $apidata->bouwjaar . '</td>' .
'<td style="padding: 10px; padding-right: 35px; padding-left: 35px;">' . $apidata->text . '</td>' .
'</tr>';
}
$htmlTabel .= '</table>';
$conn->close();
?>
HTML CODE
<div class="container" style="margin-left:150px; margin-right:150px; font-family:Georgia; margin-top: 75px; text-align: center; ">
<?php echo $htmlTabel ?>
</div>

How to align form and text generated by function?

I'm developing a webpage that has many forms with some text close to form. This form and text are generated by a function, but I get this
As you can see the forms and the text are not aligned with forms and text below. I would like to have this:
(this work because I put spaces manually). This is how I create forms.
function add_form($product,$name,$productp)
{
$productpt = "X";
echo $name;
echo '<input type="text" name="'. $product. '" id="'. $product. '" style="font-size:12pt;height:30px"/> x'.$productp. '€
price:'.$productpt.'€<br>';
}
echo '<form method="post" name="form1" id="form1" autocomplete="off">'; //start form
echo '<div class="leftpane">'; //start leftpane
echo '<h1>';
echo '<font size="6" color="red"> ALIMENTS </font><br>';
//ADD ELEMENTS IN MY MENU
//The first argument is the form name and id, the second is the name that will be printed(to the left of the form), the third argument is the price.
$menu[] = new Menu("pasta", "Pasta", 2);
$menu[] = new Menu("spaghetti", "Spaghetti", 1.50);
$menu[] = new Menu("pizza", "Pizza", 5);
$menu[] = new Menu("chicken_wings_x4", "Chicken Wings X4", 4.50);
$menu[] = new Menu("cheeseburger", "Cheeseburger", 6);
$menu[] = new Menu("Sandwich", "Sandwich", 2);
$menu[] = new Menu("hamburger", "Hamburger", 4.50);
$menu[] = new Menu("stuff", "stuff", 15.50);
//FOR EACH ELEMENT CREATE A FORM
for($i=0; $i<count($menu); $i++){
add_form($menu[$i]->form_name, $menu[$i]->name, $menu[$i]->price);
}
echo '</h1>';
echo '</div>'; //Close leftpane
...Do Others stuff in middlepane and in rightpane
To be clearer in html, for example the first form will be:
<input type="text" name="pasta" id="pasta" style="font-size:12pt;height:30px"/> x2€ price:X€<br>
I thought to divide in 3 parts my leftpane and to place $name to the left, the form to the middle and the price to the right. But the problem is that i create form in function, so I do not know how to do it.
This is my css:
<style>
input[type=text] {
width: 10%;
margin: 7.5px 0;
box-sizing: border-box;
}
input[type=submit].class1 {
width: 50%;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
}
input[type=submit].class2 {
width: 50%;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
}
body, html {
width: 100%;
height: 100%;
margin: 0;
}
.container {
width: 100%;
height: 100%;
}
.leftpane {
width: 33%;
height: 100%;
float: left;
border-collapse: collapse;
}
.middlepane {
width: 33%;
height: 100%;
float: left;
border-collapse: collapse;
}
.rightpane {
width: 33%;
height: 100%;
position: relative;
float: right;
border-collapse: collapse;
}
form {
display: inline-block;
}
h1 {
font-size: 19.5px;
}
</style>
I would suggest you to use a table. https://www.w3schools.com/html/html_tables.asp
Or you could wrap every section into a div-container and define its width.
I think your output code would really benefit from some additional HTML structure with classes that allow you to control their layout in a consistent way with CSS. I would update the add_form() function:
function add_form($product,$name,$productp) {
$productpt = "X";
echo '<div class="form-wrap">';
echo '<span class="form-name">' . $name . '</span>';
echo '<input type="text" name="'. $product. '" id="'. $product. '"/> <span class="form-label">x'.$productp. '€</span> <span class="form-price">price:'.$productpt.'€</span>';
echo '</div>';
}
Then with the output having more targetable HTML structure you can do this with CSS:
.form-wrap input {
font-size: 12pt;
height: 30px
}
.form-name {
display: inline-block;
width: 100px;
margin-right: 20px;
}
.form-label {
display: inline-block;
margin-left: 5px;
margin-right: 20px;
}
<div class="form-wrap">
<span class="form-name">Something</span>
<input type="text" name="something" id="somethingId" />
<span class="form-label">x1€</span>
<span class="form-price">price:1€</span>
</div>
<div class="form-wrap">
<span class="form-name">Another one</span>
<input type="text" name="anotherone" id="somethingId2" />
<span class="form-label">x2€</span>
<span class="form-price">price:2€</span>
</div>
<div class="form-wrap">
<span class="form-name">Number Three</span>
<input type="text" name="thirdone" id="somethingId3" />
<span class="form-label">x3€</span>
<span class="form-price">price:3€</span>
</div>
Try this.
function add_form($product,$name,$productp)
{
$productpt = "X";
echo "<table><tr>";
echo "<td width='20%'>" . $name . "</td>";
echo "<td width='20%'><input type='text' name='". $product . "' id='" . $product . "' style='font-size:12pt;height:30px;' /></td>";
echo "<td width='20%'>x" . $productp . "€</td>";
echo "<td width='20%'>price:" . $productpt . "€</td>";
echo "</tr></table>";
}

Save the generated HTML code to a file

I create an application that dynamically generates certain structures in Javascript and sends them to PHP in the resulting form. Generator is practically finished, although I have trouble writing the generated HTML code to a file. I have this PHP code and i want save generated HTML code to file. If i use this code:
$fp = fopen('plik.html', 'w');
fwrite($fp, file_get_contents('./generate.php'));
fclose($fp);
I get this file content:
error_reporting(E_ALL);
ini_set('display_errors',0);
#$tytul = $_POST['k-title'];
#$opis = $_POST['k-desc'];
$fp = fopen('plik.html', 'w');
fwrite($fp, file_get_contents('./generate.php'));
fclose($fp);
// albo dla PHP 5:
file_put_contents('plik.html', file_get_contents('./generate.php'));
/* echo "<pre>";
print_r($_POST);
echo "</pre>"; */
if ($tytul == '' || $opis == '') {
echo '<div><p>Błąd</p><p>Uzupełnij wszystkie pola generatora!</p>';
} else {
echo '<div style="max-width: 1050px; margin-left: auto; margin-right: auto;">';
echo '<div style="padding-top: 50px; padding-bottom: 50px;">';
echo '<p style="font-size: 30px; text-align: center;">'.$tytul.'</p>';
echo '<p style="font-size: 15px; text-align: justify;">'.$opis.'</p>';
echo '</div>';
echo '<div style="width: 100%; text-align: center; background-color: #eee; font-weight: 200; line-height: 0.92em; padding: 23px 0; font-size: 30px;">Specyfikacja techniczna</div>';
echo '<table style="font-size: 14px; border: none; border-top: 1px solid #dbdbdb; border-bottom: 1px solid #dbdbdb; width: 100%;" border="0" cellspacing="0" cellpadding="5px"><tbody>';
$cechy = array_combine($_POST['cecha'], $_POST['cecha-opis']);
foreach($cechy as $klucz => $wartosc) {
echo '<tr><td style="padding: 3px 10px; text-align: right; border-right: 1px solid #dbdbdb;" width="50%">';
echo $klucz;
echo '</td>';
echo '<td style="padding: 3px 10px; text-align: left;" width="50%">';
echo $wartosc;
echo '</td>';
echo '</tr>';
}
echo '</tbody></table>';
$prezentacje = array();
for($i = 0; $i < count($_POST['pwidth']); $i++) {
$prezentacja = array();
$prezentacja['pwidth'] = $_POST['pwidth'][$i];
$prezentacja['pheight'] = $_POST['pheight'][$i];
$prezentacja['psource'] = $_POST['psource'][$i];
array_push($prezentacje, $prezentacja);
}
foreach($prezentacje as $p) {
echo '<img style="width: ' . $p['pwidth'] . 'px; height: ' . $p['pheight'] . 'px;" src="' . $p['psource'] . '" />';
}
echo '<div style="clear: both;"></div>';
$section = array();
for($a = 0; $a < count($_POST['sectionwidth']); $a++) {
$sesfull = array();
$sesfull['sectionwidth'] = $_POST['sectionwidth'][$a];
$sesfull['sectionheight'] = $_POST['sectionheight'][$a];
$sesfull['bg'] = $_POST['bg'][$a];
$sesfull['sectioncolor'] = $_POST['sectioncolor'][$a];
$sesfull['inputwidth'] = $_POST['inputwidth'][$a];
array_push($section, $sesfull);
}
foreach ($_POST['section'] as $sekcja) {
echo '<div style="margin: 0; float: left; width: '.$sekcja['sectionwidth'].'px; height: '.$sekcja['sectionheight'].'px; background: #'.$sekcja['bg'].'; color: #'.$sekcja['sectioncolor'].';">';
foreach ($sekcja['input'] as $input) {
echo '<p style="margin-left: auto; margin-right: auto; width: '.$input['inputwidth'].'px;">'.$input['inputtext'].'</p>';
}
echo '</div>';
}
echo '<div style="width: 100%; text-align: center; background-color: #eee; font-weight: 200; line-height: 0.92em; padding: 23px 0; font-size: 30px; clear: both;">Galeria zdjęć</div>';
$gallery = array_combine($_POST['srcphoto'], $_POST['descphoto']);
foreach ($gallery as $source => $alt) {
echo '<img style="width: 100%; margin-bottom: 25px;" src="'.$source.'" alt="'.$alt.'" /></img>';
}
echo '</div>';
}
Is it possible to save only the generated HTML code by a PHP script while previewing the generated content?
Update #2:
<?php
error_reporting(E_ALL);
ini_set('display_errors',0);
$tytul = $_POST['k-title'];
$opis = $_POST['k-desc'];
ob_start(); ?>
<div style="max-width: 1050px; margin-left: auto; margin-right: auto;">
<div style="padding-top: 50px; padding-bottom: 50px;">
<p style="font-size: 30px; text-align: center;"><?php echo $tytul; ?></p>
<p style="font-size: 15px; text-align: justify;"><?php echo $opis; ?></p>
</div>
<div style="width: 100%; text-align: center; background-color: #eee; font-weight: 200; line-height: 0.92em; padding: 23px 0; font-size: 30px;">Specyfikacja techniczna</div>
<table style="font-size: 14px; border: none; border-top: 1px solid #dbdbdb; border-bottom: 1px solid #dbdbdb; width: 100%;" border="0" cellspacing="0" cellpadding="5px"><tbody>
<?php
$cechy = array_combine($_POST['cecha'], $_POST['cecha-opis']);
foreach($cechy as $klucz => $wartosc) {
?>
<tr><td style="padding: 3px 10px; text-align: right; border-right: 1px solid #dbdbdb;" width="50%">
<?php echo $klucz ?>
</td>
<td style="padding: 3px 10px; text-align: left;" width="50%">
<?php echo $wartosc; ?>
</td>
</tr>
<?php
}
?>
</tbody></table>
<?php
$prezentacje = array();
for($i = 0; $i < count($_POST['pwidth']); $i++) {
$prezentacja = array();
$prezentacja['pwidth'] = $_POST['pwidth'][$i];
$prezentacja['pheight'] = $_POST['pheight'][$i];
$prezentacja['psource'] = $_POST['psource'][$i];
array_push($prezentacje, $prezentacja);
}
foreach($prezentacje as $p) {
?>
<img style="float: left; max-width: 100%; width:<?php echo $p['pwidth']; ?>px; height: <?php echo $p['pheight']; ?>px;" src="<?php echo $p['psource']; ?>" />
<?php
}
?>
<div style="clear: both;"></div>
<?php
$section = array();
for($a = 0; $a < count($_POST['sectionwidth']); $a++) {
$sesfull = array();
$sesfull['sectionwidth'] = $_POST['sectionwidth'][$a];
$sesfull['sectionheight'] = $_POST['sectionheight'][$a];
$sesfull['bg'] = $_POST['bg'][$a];
$sesfull['sectioncolor'] = $_POST['sectioncolor'][$a];
$sesfull['inputwidth'] = $_POST['inputwidth'][$a];
array_push($section, $sesfull);
}
foreach ($_POST['section'] as $sekcja) {
?>
<div style="margin: 0; float: left; width: <?php echo $sekcja['sectionwidth']; ?>px; height: <?php echo $sekcja['sectionheight']; ?>px; background: #<?php echo $sekcja['bg']; ?>; color: #<?php echo $sekcja['sectioncolor']; ?>;">
<?php
foreach ($sekcja['input'] as $input) {
?>
<p style="margin-left: auto; margin-right: auto; width: <?php echo $input['inputwidth']; ?>px"> <?php echo $input['inputtext']; ?> </p>
<?php } ?>
</div>
<?php
}
?>
<div style="width: 100%; text-align: center; background-color: #eee; font-weight: 200; line-height: 0.92em; padding: 23px 0; font-size: 30px; clear: both;">Galeria zdjęć</div>
<?php
$gallery = array_combine($_POST['srcphoto'], $_POST['descphoto']);
foreach ($gallery as $source => $alt) {
?>
<img style="width: 100%; margin-bottom: 25px;" src="<?php echo $source; ?>" alt="<?php echo $alt; ?>" /></img>
<?php } ?>
</div>
<?php
$szablon = ob_end_flush();
echo $szablon;
$fp = fopen('plik.html', 'w');
fwrite($fp, $szablon);
fclose($fp);
file_put_contents('plik.html', $szablon);
?>
You can use output buffering in your script (http://php.net/manual/en/book.outcontrol.php)
Something like...
ob_start();
echo 'Some html';
$text = ob_get_flush();
echo "Content is:".$text;
will output
Content is:Some html
Update:
If you wanted to capture all of the output which your generating, the ob_start(); starts the buffering (where you have it in your example is fine), then when you've generated what your after (so for example )...
</tbody></table>
<?php
$content = ob_get_flush();
fwrite($fp, $content);
You will have to get the generated HTML by accessing your generate.php script through a web server (e.g. http://localhost/generate.php, depending on where your code is located).
file_get_contents('http://localhost/generate.php');

How can I insert pagination in my search engine?

How can I insert pagination in my search engine search.php page?
If there is 1 page, I do not want the Previous button and the Next button.
If there are 2 pages and I am on the first page, I hope that I can have the Next button.
If there are 2 pages and I am on the second page, I also hope that I can only have the Previous button.
This is my current code, hope that you can help me:
<?php
//php code goes here
include 'connect.php'; // for database connection
include 'script_suggestion.php';
include 'script_close_suggestion_box.php';
$query = $_GET['q']; // query
$button = $_GET ['submit'];
$page_number = $_GET['page'];
if (!$page_number);
$page_number = 0;
$results_per_page = 10;
$next = $page_number + $results_per_page;
$prev = $page_number - $results_per_page;
?>
<html>
<head>
<title>
Brandon's Search Engine
</title>
<style type="text/css">
#title a {
font-size: 17pt;
margin: 5px;
padding: 2px;
border-color: black;
text-decoration: underline;
width: 544px;
}
#search-result {
display: block;
border: 1px solid grey;
border-color: grey;
}
#search-result:hover {
background-color: #dddddd;
width: 544px;
}
#link {
font-size: 17pt;
margin: 5px;
padding: 2px;
width: 544px;
}
#description {
font-size: 17pt;
margin: 5px;
padding: 2px;
width: 544px;
}
#search-page-number {
display: block;
width: auto;
height: auto;
border: 1px solid gray;
margin: 2px;
padding-left: 5px;
padding-right: 5px;
padding-bottom: 2px;
padding-top: 2px;
list-style: none;
float: left;
text-align: center;
}
#search-page-number:hover {
background-color: #dddddd;
}
#suggestion {
border: 1px solid black;
visibility: hidden;
position: fixed;
background-color: white;
z-index: 10;
}
#suggestion a {
font-size: 12pt;
color: black;
text-decoration: none;
display: block;
width: 548px;
height: auto;
text-align: left;
padding: 2px;
}
#suggestion a:hover {
background-color: #dddddd;
width: 544px;
padding: 2px;
}
</style>
</head>
<body>
<form method="GET" action="search.php">
<table>
<tr>
<td>
<h2>
Brandon's Search Engine
</h2>
</td>
</tr>
<tr>
<td>
<input type="text" value="<?php echo htmlspecialchars($_GET['q']); ?>" name="q" style="height: 27px; width: 550px; padding: 2px" name="q"
onkeyup="getSuggestion(this.value)" autocomplete="off" onblur="closeBox()" placeholder="Search Now"/>
<input type="submit" value="Search" name="submit" style="height: auto; width: 60px; padding: 2px" />
<div id="suggestion" style="width: 548px">
</div>
</td>
</tr>
</table>
<br>
<hr>
<table>
<tr>
<td>
<?php
//SQL query
$stmt = "SELECT * FROM searchengine WHERE title LIKE '%" . mysqli_real_escape_string($con,$query) . "%' OR keywords LIKE '%" . mysqli_real_escape_string($con,$query) . "%' OR link LIKE '%" . mysqli_real_escape_string($con,$query) . "%' LIMIT " . $page_number . " , $results_per_page";
$result = mysqli_query($con,$stmt) or die(mysqli_error($con));
$number_of_result = mysqli_num_rows($result);
$x++;
if($x==1)
if ($number_of_result < 1) {
echo "<b>No results found!</b>";
echo "<p>";
echo "Your search - <b>$query</b>" . " - did not match any documents. Please try different keywords.";
} elseif ($number_of_result > 1) {
echo "<b>$number_of_result results found!</b>";
echo "<p>";
//results found here and display them
$index = 1;
while (($row = \mysqli_fetch_assoc($result)) && ($index < 10)) {//10 results per page
$title = $row["title"];
$description = $row["description"];
$link = $row["link"];
echo "<div id='search-result'>";
echo "<div id='title'><a href='$link'>" . $title . "</a></div>";
//echo "<br />";
echo "<div id='link'><small>" . $link . "</small></div>";
//echo "<p>";
echo "<div id='description'><small>" . $description . "</small></div>";
echo "</div>";
echo "<br />";
$index++;
}
} elseif ($number_of_result = 1) {
echo "<b>$number_of_result result found!</b>";
echo "<p>";
//results found here and display them
$index = 1;
while (($row = \mysqli_fetch_assoc($result)) && ($index < 10)) {//10 results per page
$title = $row["title"];
$description = $row["description"];
$link = $row["link"];
echo "<div id='search-result'>";
echo "<div id='title'><a href='$link'>" . $title . "</a></div>";
//echo "<br />";
echo "<div id='link'><small>" . $link . "</small></div>";
echo "<br />";
echo "<div id='description'><small>" . $description . "</small></div>";
echo "</div>";
echo "<br />";
$index++;
}
}
?>
</td>
</tr>
<tr>
<td>
<input type="hidden" name="page" value="<?php echo 1; ?>" />
<div id="page-number">
Select Page Number:
<?php
//ie if 35 results are therer then we require 4 pages that are 0 to max_page_number
//current page number is equal to page_number
$max_page_number = $number_of_result / 10;
//echo $max_page_number;
echo "<ul>";
//both the condition are not the neccesary
if(!$page_number <= 0)
{
//print the link to previous page
echo "<li id='search-page-number'>";
echo "Previous";
echo "</li>";
}
$i = 1;
for($index = 0; $index < $number_of_result; $index=$index+$results_per_page)
{
echo "<li id='search-page-number'>";
echo "<a href=search.php?q=$query&page=$i>";
echo $i++ . "</a>";
echo "</li>";
}
if($page_number < $number_of_result - $results_per_page)
{
//print the link to next page
echo "<li id='search-page-number'>";
echo "Next";
echo "</li>";
}
echo "</ul>";
?>
</div>
</td>
</tr>
<tr>
<td align="center">
To insert your site in result fill in the form at here.
</td>
</tr>
</table>
</form>
</body>
</html>
Thanks in advance.
<?php
//php code goes here
include 'connect.php'; // for database connection
include 'script_suggestion.php';
include 'script_close_suggestion_box.php';
$query = $_GET['q']; // query
$button = $_GET ['submit'];
$page_number = (int)$_GET['page'];
if (!$page_number)
$page_number = 0;
$results_per_page = 10;
$next = $page_number + $results_per_page;
$prev = $page_number - $results_per_page;
?>
<html>
<head>
<title>
Brandon's Search Engine
</title>
<style type="text/css">
#title a {
font-size: 17pt;
margin: 5px;
padding: 2px;
border-color: black;
text-decoration: underline;
width: 544px;
}
#search-result {
display: block;
border: 1px solid grey;
border-color: grey;
}
#search-result:hover {
background-color: #dddddd;
width: 544px;
}
#link {
font-size: 17pt;
margin: 5px;
padding: 2px;
width: 544px;
}
#description {
font-size: 17pt;
margin: 5px;
padding: 2px;
width: 544px;
}
#search-page-number {
display: block;
width: auto;
height: auto;
border: 1px solid gray;
margin: 2px;
padding-left: 5px;
padding-right: 5px;
padding-bottom: 2px;
padding-top: 2px;
list-style: none;
float: left;
text-align: center;
}
#search-page-number:hover {
background-color: #dddddd;
}
#suggestion {
border: 1px solid black;
visibility: hidden;
position: fixed;
background-color: white;
z-index: 10;
}
#suggestion a {
font-size: 12pt;
color: black;
text-decoration: none;
display: block;
width: 548px;
height: auto;
text-align: left;
padding: 2px;
}
#suggestion a:hover {
background-color: #dddddd;
width: 544px;
padding: 2px;
}
</style>
</head>
<body>
<form method="GET" action="search.php">
<table>
<tr>
<td>
<h2>
Brandon's Search Engine
</h2>
</td>
</tr>
<tr>
<td>
<input type="text" value="<?php echo htmlspecialchars($_GET['q']); ?>" name="q" style="height: 27px; width: 550px; padding: 2px" name="q"
onkeyup="getSuggestion(this.value)" autocomplete="off" onblur="closeBox()" placeholder="Search Now"/>
<input type="submit" value="Search" name="submit" style="height: auto; width: 60px; padding: 2px" />
<div id="suggestion" style="width: 548px">
</div>
</td>
</tr>
</table>
<br>
<hr>
<table>
<tr>
<td>
<?php
//count
$count_sql = "SELECT count(*) as c FROM searchengine WHERE title LIKE '%" . mysqli_real_escape_string($con,$query) . "%' OR keywords LIKE '%" . mysqli_real_escape_string($con,$query) . "%' OR link LIKE '%" . mysqli_real_escape_string($con,$query) . "%' ";
$search_count = mysqli_fetch_array(mysqli_query($con,$count_sql));
$number_of_result = $search_count['c'];
//SQL query
$stmt = "SELECT * FROM searchengine WHERE title LIKE '%" . mysqli_real_escape_string($con,$query) . "%' OR keywords LIKE '%" . mysqli_real_escape_string($con,$query) . "%' OR link LIKE '%" . mysqli_real_escape_string($con,$query) . "%' LIMIT " . $page_number . " , $results_per_page";
$result = mysqli_query($con,$stmt) or die(mysqli_error($con));
//$number_of_result = mysqli_num_rows($result);
$x++;
if($x==1)
if ($number_of_result < 1) {
echo "<b>No results found!</b>";
echo "<p>";
echo "Your search - <b>$query</b>" . " - did not match any documents. Please try different keywords.";
} elseif ($number_of_result > 1) {
echo "<b>$number_of_result results found!</b>";
echo "<p>";
//results found here and display them
$index = 1;
while (($row = \mysqli_fetch_assoc($result)) && ($index < 10)) {//10 results per page
$title = $row["title"];
$description = $row["description"];
$link = $row["link"];
echo "<div id='search-result'>";
echo "<div id='title'><a href='$link'>" . $title . "</a></div>";
//echo "<br />";
echo "<div id='link'><small>" . $link . "</small></div>";
//echo "<p>";
echo "<div id='description'><small>" . $description . "</small></div>";
echo "</div>";
echo "<br />";
$index++;
}
} elseif ($number_of_result == 1) {
echo "<b>$number_of_result result found!</b>";
echo "<p>";
//results found here and display them
$index = 1;
while (($row = \mysqli_fetch_assoc($result)) && ($index < 10)) {//10 results per page
$title = $row["title"];
$description = $row["description"];
$link = $row["link"];
echo "<div id='search-result'>";
echo "<div id='title'><a href='$link'>" . $title . "</a></div>";
//echo "<br />";
echo "<div id='link'><small>" . $link . "</small></div>";
echo "<br />";
echo "<div id='description'><small>" . $description . "</small></div>";
echo "</div>";
echo "<br />";
$index++;
}
}
?>
</td>
</tr>
<tr>
<td>
<input type="hidden" name="page" value="0" />
<div id="page-number">
Select Page Number:
<?php
//ie if 35 results are therer then we require 4 pages that are 0 to max_page_number
//current page number is equal to page_number
$max_page_number = ceil($number_of_result / $results_per_page);
//echo $max_page_number;
echo "<ul>";
//both the condition are not the neccesary
if ($max_page_number > 2) { // if more than 2 pages
if ($page_number > 0 ) { //Previous
echo "<li id='search-page-number'>";
echo "Previous";
echo "</li>";
}
for($index = 0 ; $index < $max_page_number ; $index++)
{
echo "<li id='search-page-number'>";
echo "<a href=search.php?q=$query&page=".($index * $results_per_page).">";
echo ($index + 1) . "</a>";
echo "</li>";
}
if (($page_number + $results_per_page) < $number_of_result ) { //Next
echo "<li id='search-page-number'>";
echo "Next";
echo "</li>";
}
} elseif (($max_page_number == 2 ) ) {
echo "<li id='search-page-number'>";
echo "".($page_number == 0 ? "Next":"Previous" )."";
echo "</li>";
} elseif (($max_page_number == 1 ) ) {
echo "<li id='search-page-number'>";
echo "<a href=search.php?q=$query&page=0>1</a>";
echo "</li>";
}
echo "</ul>";
?>
</div>
</td>
</tr>
<tr>
<td align="center">
To insert your site in result fill in the form at here.
</td>
</tr>
</table>
</form>
</body>
</html>

Styling multiple while loop results, getting them next to each other?

I have a search form the searches through a packaging database. Everything works fine and dandy, when the search from is submitted I get returned results on a different page displayed in styled boxes with a picture. But unfortunately the seem to display one after another underneath each other. Although it is good that they are returning and I am getting the correct results. I want to be able to display three next to each other, then they go to the next row and display three more, so on and so forth until I have run out of results.
Here is the PHP:
<?php
$con = mysql_connect ("localhost", "horizon1", "D2j616H5O#Lw");
mysql_select_db ("horizon1_delyn", $con);
if (!$con)
{
die ("Could not connect: " . mysql_error());
}
$descrip = mysql_real_escape_string($_POST['descrip']);
$depth = mysql_real_escape_string($_POST['depth']);
$varWidth = mysql_real_escape_string($_POST['traywidth']);
$varHeight= mysql_real_escape_string($_POST['trayheight']);
$varRange = mysql_real_escape_string($_POST['trayrange']);
$varType = mysql_real_escape_string($_POST['traytype']);
$varShape = mysql_real_escape_string($_POST['trayshape']);
$varImage = mysql_real_escape_string($_POST['imagename']);
if (isset($varHeight) && !empty($varHeight)) {
$low = ($varHeight."00");
$high = ($varHeight."99");
} else {
$low = ("000");
$high = ("999");
}
if (isset($varWidth) && !empty($varWidth)) {
$min = ($varWidth."00");
$max = ($varWidth."99");
} else {
$min = ("000");
$max = ("999");
}
$sql = "SELECT * FROM range WHERE
description LIKE '%".$descrip."%'
AND trayrange LIKE '%".$varRange."%'
AND traytype LIKE '%".$varType."%'
AND trayshape LIKE '%".$varShape."%'
AND traywidth BETWEEN '".$min."' AND '".$max."'
AND trayheight BETWEEN '".$low."' AND '".$high."' ";
$r_query = mysql_query($sql);
while ($row = mysql_fetch_array($r_query))
{
echo '<div id="results">';
echo '<p class="image">
<img src=" '. $row['imagename'] . '" width="150" length="80">
</p>';
echo '<div id="table"><br />
<strong> Tool Code: </strong> '. $row['toolcode'];
echo '<br /><strong> Description: </strong> '. $row['description'];
echo '<br /><strong> Tray range: </strong> '. $row['trayrange'];
echo '<br /><strong> Tray type: </strong> '. $row['traytype'];
echo '<br /><strong> Tray size: </strong> '. $row['traysize'];
echo '<br /><strong> Tray shape: </strong> '. $row['trayshape'] . '</div>' . '<br />';
echo 'Enquiry Page <br />' .
'Back to Search';
echo '</div>' . '<br />';
}
if (mysql_num_rows($r_query) <= 0){
echo 'No results match your search, please try again';
}
?>
And here is the CSS:
<style>
#boxes {
padding: 10px;
margin-top: 20px;
margin: 10px;
float: left;
display: block;
}
#results {
width: 212px;
padding: 5px;
background: #E8CF24;
display: block;
overflow:auto;
font-family: Verdana, Geneva, sans-serif;
font-size: 11px;
font-color: #FFF;
border: 2px solid #cccccc;
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
border-radius: 7px;
-moz-box-shadow: 2px 2px 2px #cccccc;
-webkit-box-shadow: 2px 2px 2px #cccccc;
box-shadow: 2px 2px 2px #cccccc;
}
#table {
margin-top: 10px;
width: 200px;
padding: 3px;
background: #FFF;
display: block;
overflow:auto;
border: 2px solid #cccccc;
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
border-radius: 7px;
-moz-box-shadow: 2px 2px 2px #cccccc;
-webkit-box-shadow: 2px 2px 2px #cccccc;
box-shadow: 2px 2px 2px #cccccc;
}
.image {
margin-left: 28px;
margin-bottom: 0px;
margin-top: 5px;
}
a:link {
color: #000423;
font-family: Arial, Helvetica, sans-serif;
font-size: 13px;
}
</style>
I have tried to edit it with the CSS but I can change the position and padding, margins and so on forth. But I can't get them to align next to each other.
Anyone able to help? Thanks in advance :)
In your css add this to your #results selector.
#results {
float:left
}
EDIT: Sorry that was not the correct answer. Delete the above code and look into thee below code.
Replace the while loop with the below code.
EDIT: Dont forget to initialize the $count variable. ($count = 0;)
Just copy-paste the code and it should work for you.
$count = 0;
while ($row = mysql_fetch_array($r_query))
{
$t = $count%3;
echo ($t==2) ? '<div id="results">' : '<div id="results" style="float:left">';
echo '<p class="image">
<img src=" '. $row['imagename'] . '" width="150" length="80">
</p>';
echo '<div id="table"><br />
<strong> Tool Code: </strong> '. $row['toolcode'];
echo '<br /><strong> Description: </strong> '. $row['description'];
echo '<br /><strong> Tray range: </strong> '. $row['trayrange'];
echo '<br /><strong> Tray type: </strong> '. $row['traytype'];
echo '<br /><strong> Tray size: </strong> '. $row['traysize'];
echo '<br /><strong> Tray shape: </strong> '. $row['trayshape'] . '</div>' . '<br />';
echo 'Enquiry Page <br />' .
'Back to Search';
echo '</div>';
$count++;
}
This is what i get. I didnt use the css file.

Categories