search form error - sql

I'm webdesigner and I touch NOTHING in development, so, I really need your help (exam in school). So, indeed, I've made a search form in the same page. There a field to search by town (ville) and the results should be appareate in a div. Sometimes it works, but I really need to fix that.
The error: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\Program Files (x86)\EasyPHP-5.3.8.1\www\foodsurfing\index.php on line 55
There is the code
<?php
require_once('Connections/foodsurfing.php');
if(isset($_GET['recherche']))
$requete="SELECT * FROM fiche_membres WHERE ville LIKE '%".$_GET['recherche']."%'
LIMIT 0 , 1 ";
else
$requete="SELECT * FROM fiche_membres
LIMIT 1 , 1 ";
mysql_query("SET NAMES UTF8");
$resultat=mysql_query($requete);
if (false === $resultat) {
echo mysql_error();
}
?>
and the result's div
<div id="gmap_result_container">
<div class="gmap_result">
<?php while($fiche_membres=mysql_fetch_array($resultat)) {?> <p>
<a class="prenom"><?php echo($fiche_membres['prenom']); ?></a>
<a> , </a>
<a class="ville"><?php echo($fiche_membres['ville']); ?></a></p>
<img src="images/avatar_unknown.jpg">
<p><?php echo($fiche_membres['experience_culinaire']); ?></p>
<p><img src="images/ensavoirplus.png" name="roll" border="0" alt="En savoir plus" align="middle" class="ensavoirplus"></p>
<?php }?>
</div>
</div>
Thank you so much for your help !!
Glad to be into the community I just discover as beginner !

Warning says that the resource is not valid which is parameter of mysql_fetch_array() method. You have to verify the reference before retrieving rows.
if(isset($_GET['recherche']))
$requete="SELECT * FROM fiche_membres WHERE ville
LIKE '%" . mysql_real_escape_string($_GET['recherche']) . "%' LIMIT 0 , 1 ";
else
$requete="SELECT * FROM fiche_membres LIMIT 1 , 1 ";
$resultat=mysql_query($requete);
if($resultat)
{
while($fiche_membres=mysql_fetch_array($resultat))
{
//
}
}

Related

Magento 2 : How to display customer email on checkout success page?

My code is given below
app/code/custom/checkout/block/success.php
class Success extends \Magento\Checkout\Block\Onepage\Success
{
public function getOrder()
{
$order = $this->_checkoutSession->getLastRealOrder();
return $order;
}
app/design/frontend/vendor/themename/Magento_Checkout/layout/checkout_onepage_success.xml
<referenceContainer name="content">
<block class="Custom\Checkout\Block\Success" name="checkout.success" template="Magento_Checkout::success.phtml" cacheable="false">
<container name="order.success.additional.info" label="Order Success Additional Info"/>
</block>
</referenceContainer>
app/design/frontend/vendor/themename/Magento_Checkout/templates/success.phtml
<?php if($block->getOrderId):?>
<div class="success-title" data-bind="i18n: 'Thank you for your purchase!'" data-role="title">
<h2><?= __('Thank you for your purchase!');?></h2>
</div>
<p><?= __('Your payment has been received. A confirmation of your order has been sent to ');?><?php echo '"'.$block->getOrder()->getCustomerEmail().'"'?></p>
<?php if ($block->getCanViewOrder()) :?>
<p class="successmessge"><?= __('Your order number is: %1.', sprintf('<strong>%s</strong>', $block->escapeHtml($block->getViewOrderUrl()), $block->escapeHtml($block->getOrderId()))) ?></p>
<?php else :?>
<p class="successmessge"><?= __('Your order number is: <span>%1</span>.', $block->escapeHtml($block->getOrderId())) ?></p>
<?php endif;?>
<p><?= /* #escapeNotVerified */ __('Check your inbox for estimated delivery time') ?></p>
<p><?= /* #escapeNotVerified */ __('If you have any questions regarding your order , please contact our customer service department on contact#cii.co.uk or +44(0)12 3456 7891') ?></p>
<?php endif;?>
$block->getOrder()->getCustomerEmail();
this is returning error : call to non-member function is null
app/code/Custom/Checkout/etc/frontend/di.xml
<preference for="Custom\Checkout\Block\Success" type="Magento\Checkout\Block\Onepage\Success" />
All the things are working well.
but not getting block to success page
Please help me what is wrong in my code?

Converting Pdo OOP To Mysqli Procedural

Folks, :)
My 3+ pages are all in mysqli procedural. I cannot just switch to pdo and oop and throw 6 mnths of work down the drain! And so, let's try converting the following code suggestion by another to mysqli procedural.
I really need the following code converted to mysqli procedural from pdo oop. Once that is done, my 7 months project will come to an end. And, I can move-on to learning pdo. Right now, can't afford to jump into pdo without finishing my current project.
So, who will help me convert ? Other newbies would learn from your conversion.
Thanks!
[code]
/*
ERROR HANDLING
*/
declare(strict_types=1);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
include 'config.php';
// check if user is already logged in
if (is_logged() === true)
{
//Redirect user to homepage page after 5 seconds.
header("refresh:2;url=home.php");
exit; //
}
if (
array_key_exists('login_username_or_email', $_POST) &&
array_key_exists('login_password' , $_POST)
) {
$usernameoremail = trim($_POST["login_username_or_email"]); //
$password = $_POST["login_password"];
// don't bother trimming, they can't enter it right, don't let them log
in!
$stmt = $conn->prepare('SELECT ids, usernames, passwords, emails,
accounts_activations_statuses
FROM users WHERE ' . (
strpos($usernameoremail, '#') === false) ? 'usernames' : 'emails'
) . ' = ?
');
$stmt->bind_param('s', $_POST['login_username_or_email']);
$stmt->execute();
$stmt->bind_result(
$db_id, $db_username, $db_password, $db_email,
$db_account_activation_status
);
if (
$stmt->fetch() &&
password_verify($_POST['login_password'], $db_password)
) {
echo '
<p>Login Successful</p>
<dl>
<dt>User Id</dt>
<dd>', $db_id, '</dd>
<dt>E-Mail</dt>
<dd>', $db_email, '</dd>
<dt>Username</dt>
<dd>', $db_username, '</dd>
<dt>Activation Stats</dt>
<dd>', $db_account_activation_status, '</dd>
</dl>
';
} else echo '<p>Invalid username or password</p>';
$stmt->close();
} else echo '<p>Missing username or password</p>';
?>
<!DOCTYPE html>
<html>
<head>
<title><?php $site_name?> Member Login Page</title>
<meta charset="utf-8">
</head>
<body>
<div class = "container">
<form method="post" action="">
<h3><?= $site_name ?> Member Login Form</h3>
<fieldset>
<label for="login_name">Username/Email:</label>
<input type="text" name="login_username_or_email" id="login_name">
<br>
<label for="login_pass">Password:</label>
<input type="password" name="login_password" id="login_pass">
</fieldset>
<div class="submitsAndHiddens">
<button type="submit">Login</button><br>
Forgot your Password?<br>
Register New Account
</div>
</form>
</div>
</body>
[/code]

Notice: Undefined variable: on line 24

I have the code:
if(isset($_POST['id'])){ $res = $_POST['id']; }
if(isset($_POST['ora2'])){ $oratwo = $_POST['ora2']; }
$operator = $_SESSION['login'];
$order = "
UPDATE `frontdes_dep`.`flux_receptie`
SET `status_preluare` = 'ALOCAT', `ora_preluare` =$oratwo, `operator_preluare` =$operator
WHERE `flux_receptie`.`id` =$res";
$result = mysqli_query($connection, $order);
When I press the submit button which take actions above, it returns me error:
( ! ) Notice: Undefined variable: oratwo in C:\wamp\www\interfata_client.php on line 24
The code is working because when I look into DB, the columns populate with values.
Line 24 is the line with $order = ...
The submit is in an echo:
echo "<div id='example3'>
<form style='padding:15px 0px 0px 0px' id='interfata' name ='interfata' method='POST' action='interfata_client.php' enctype='multipart/form-data'>
<input type='hidden' name='id' value='$res[0]'>
<input type='hidden' name='ora2' value='now()'>
<input type='submit' name='name' value='ALOCARE'>
</form>
<td><center>preluat de:<p><b>$res[8]</center></b></td>
</tr>
</div>
<br>
";
Does anynone know what am I doing wrong? I have WAMP installed.
Thanks! :)
There are 2 ways to get rid of this issue , The first one is to ignore the issue by turning of Notice exceptions .
error_reporting(E_ALL ^ E_NOTICE );
Or try the second solution below.
Notice : check whether the value is coming up from the form ('ora2')
before trying the second one.
Your code
if(isset($_POST['ora2'])){ $oratwo = $_POST['ora2']; }
Updated code
if(isset($_POST['ora2'])){
$oratwo = isset($_POST['ora2']) ? $_POST['ora2'] : '';
}

Deleting single item with submit from database results in two ID's and strings

When I try and delete an entry from the code below it seems to spew out two array values with different index numbers and will not delete the entry. If I click multiple times it finally gets the correct ID but only by some random chance.
Using echo var_dump($deleted) results in something like:
String(2) "10"
String(1) "7"
These can vary and seems to be random.
I have reduced my whole plugin to just the code below thinking that maybe some other submit query might be interfering with it. And still I get two ID's with unknown string assignments.
Any ideas?
function myplugin_update_page(){
global $wpdb;
$update_page_list = $wpdb->get_results('SELECT * FROM wp_update_page');
$active = $wpdb->get_var("SELECT * FROM wp_update_page WHERE active='on'");
echo '<form method="post" action=""><table>';
foreach ( $update_page_list as $update ) { ?>
<tr>
<td><input type="image" src="<?php echo plugin_dir_url(__FILE__).'images/delete.png'; ?>" name="delete[]" value="<?php echo $update->ID; ?>" /></td>
</tr>
</table>
</form>
</div>
<?php
}
if(isset($_POST['delete'])) {
$delete = $_POST['delete'];
foreach ($delete as $deleted) {
$wpdb->query("DELETE FROM wp_update_page WHERE ID = $deleted");
}
echo "<script type='text/javascript'>window.location=document.location.href;</script>";
}
}

Auto navigate (scroll) to certain table row

I have a table with few thousand records on few pages in a simple html table.. I made a search function that works fine apart from one thing... It displays only one result in a table (which is great cause it means it works!).But... I was wondering is there a way to display back the table with all records, with the one that i was searching for in the middle and highlighted? Here's a simplified table that I have :
<table class="nogap" cellpadding="1" bgcolor="#00000" cellspacing="1" style="margin:110px 0 0 5px; width:100%; border-color:#B6D6F6;" >
<tbody>
<?php include 'dbconn.php';?>
$con = mysqli_connect($host,$user,$pass,$db) or (header( 'Location: errorpage.php' ));
if (mysqli_connect_errno($con)) { header( 'Location: errorpage.php' ); }
$sql = "SELECT * FROM $tb1 ORDER BY (Serial_num +1) LIMIT $offset, $rowsperpage";
$result = mysqli_query($con, $sql) or (header( 'Location: errorpage.php' ));
$row = mysqli_num_rows($result);
while ($row = $result->fetch_assoc())
{
$product = $row['Prod_type'].$row['Serial_num'];
<tr id="mstrTable" class="lovelyrow">
<td width="5%"><?php echo $product;?></td>
<td width="5%"><?php echo $row['Customer'];?></td>
<td width="7%">
<a href="#"
onmouseover="ajax_showTooltip(window.event,'getptn.php?prd=<?php echo $p;?>',this);return false"
onmouseout="ajax_hideTooltip()">
<?php echo$row['Prod_info'];?>
</a>
</td>
</tr>
}
</table>
Thanks!
First of all don't give the same html id attribute to each row (mstrTable). Html Ids should be unique per page.
Instead mark table rows with unique ids, eg:
$html .= "<td id='row_".$row['id']."'>"
Then do a search query first, remember item id, figure out what page should be queried, query the whole page, attach classess 'greyedout' and 'highlighted' to rows accordingly and then you might try this javascript function to scroll down to the item:
https://developer.mozilla.org/en-US/docs/Web/API/element.scrollIntoView