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'] : '';
}
Related
In my application, I have faced several issues when I try to insert multiple rows of data into a database in laravel 8. Basically this issues is related to image upload. I have add related code to get help.
Controller View:
foreach($request->param_img as $key => $param_img){
$data = new PortfolioParam;
$data->param_desc = $request->param_desc[$key];
if($request->hasfile('param_img')){
$file = $request->file('param_img');
$extension = $file->getClientOriginalExtension();
$filename = time().'.'.$extension;
$file->move('upload/portfolio_param/', $filename);
$portfolio->param_img = $filename;
}
$data->portfolio_id = $portfolio->id;
$data->save();
}
Blade View:
<td class="pl-0 border-0">
<textarea class="form-control" name="param_desc[]" id="" cols="30" rows="3"></textarea>
</td>
<td class="border-0">
<input type="file" class="form-control" name="param_img[]">
</td>
Error
Call to a member function getClientOriginalExtension() on array
How can I get rid of this problems??
You have looped through the image but you have not used it in your image uploading code. You are still using the request data. Check this out, hopefully it helps.
// $file = $request->file('param_img');
$file = $param_img;
$extension = $file->getClientOriginalExtension();
$filename = time().'.'.$extension;
$file->move('upload/portfolio_param/', $filename);
$portfolio->param_img = $filename;
While uploading the file through codeigniter, I am getting the following error:
My file upload result is:
My Controller function is below:
public function Upload files($data='')
{
ini_set("display_errors",1); // I added so it would help me show errors
error_reporting(E_ALL);
print_r($_POST);exit('I am in the tp');
$config['upload_path'] = 'assets/images/uploads/';
//$config['allowed_types'] = 'gif|jpg|png';
//$config['max_size'] = 100;
//$config['max_width'] = 1024;
//$config['max_height'] = 768;
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ( ! $this->upload->do_upload('userfile'))
{
$error = array('error' => $this->upload->display_errors());
print_r($error);exit('The first loop');
$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
print_r($data);exit();
$this->load->view('upload_success', $data);
}
}
And my view file:
<div id="Upload_div">
<?php //echo $error;?>
<form action="<?php echo site_url() ?>/Admin/Upload_files/" method="POST" enctype="multipart/form-data">
<label for="myfile">Select a file:</label>
<input type="file" id="myfile" name="userfile"><br><br>
<input type="submit" name="submit" value="submit">
</form>
</div>
Can anyone help me figure out why post value is empty?
Thanks
$_POST does not contain any file data.
Remove the line
print_r($_POST);exit('I am in the tp');
And then tell us what happens.
The method OpenMods that you see below, is supposed to take an array generated by an fgetcsv function, and put it into an HTML table. __construct is supposed to, as is typically the case, define the attributes for the class, and shortcode is supposed to take two attributes from the shortcode, and if mods comes back, it is supposed to call another function in the class.
OpenMods did function when it was outside of a class, without the class attribute calls, so I'm fairly certain that isn't the source of my problem. My problem most likely lies within __construct and shortcode; However please don't overlook OpenMods as it may contain errors that are contributing to the problem, I'm just giving my estimation which isn't worth much since I'm having to ask to for help.
This is an example of the shortcode I'm trying to make work:
[priceguide file=’test.csv’ type=’mods’]
class CsvImporter
{
private $parse_header;
private $header;
private $delimiter;
private $length;
//--------------------------------------------------------------------
function __construct($parse_header=false, $delimiter="\t", $length=8000)
{
add_shortcode( 'priceguide', array( $this, 'shortcode' ) );
$this->parse_header = $parse_header;
$this->delimiter = $delimiter;
$this->length = $length;
}
//--------------------------------------------------------------------
public function shortcode($atts) {
$attributes = extract( shortcode_atts( array(
'file' => '',
'type' => '',
), $atts ));
if ($attributes['mods'])
{
$this->OpenMods($attributes['file']);
}
}
//--------------------------------------------------------------------
function OpenMods($file) {
ob_start();
$fp = fopen(plugin_dir_path( __FILE__ ) . $file , "r" );
if ($this->parse_header)
{
$header = fgetcsv($fp, $this->length, $this->delimiter);
}
// table header and search html
echo('<input type="text" class="search" id="search" placeholder="Search">');
echo('<br>');
echo('<table id="table"> <tr class="hidden">
<th><b>
Name</b>
</th>
<th><b>
Cheese</b>
</th>
<th><b>
Price</b>
</th>
<th><b>Vote</b>
</th>
</tr>
<tbody>');
// integer for drop down/price submit
$a = 1;
// set values for table data
while ($header !== FALSE) {
$name = $header[0];
$quanid = $header[2];
$table = $header[3];
unset($header[2]);
unset($header[3]);
$cssId = 'row-'.$a;
$a++;
//generate HTML
echo('<tr>');
foreach ($header as $index=>$val) {
echo('<td>');
echo htmlentities($val, ENT_QUOTES);
echo('</td>');
}
// query to get item prices
$sql = "SELECT ItemID, Price
FROM {$table}
WHERE ItemID = %d
GROUP BY Price
ORDER BY COUNT(*) DESC LIMIT 1";
global $wpdb;
$results = $wpdb->get_var( $wpdb->prepare( $sql, $quanid));
// put the results in the table
echo('<td>');
print_r($results);
echo('</td>');
// HTML for hidden row/price submission
echo('<td>
<button class="toggler" data-prod-cat="' . $cssId . '">Vote</button>
</td>');
echo('</tr>');
echo('<tr class="cat' . $cssId . ' hidden" style="display:none">');
echo('<td colspan="4" style="white-space: nowrap">Enter ' . $name . ' Price:
<form action="" name="form' . $quanid . '" method="post"><input type="text" id="' . $quanid . '" maxlength="4" name="' . $quanid . '" value="price_input" class="input" />
<button id="submit" name="submit" class="submit" type="submit" value="Submit">Submit</button></form>
<?php
?>
</td>
</tr>');
wp_nonce_field('price_input');
}
echo("</table>");
fclose($fp);
return ob_get_clean();
}
}
Based on OP comment, the problem is, the object can not created and in this case, __constructor() will not run, and add_shortcode( 'priceguide', array( $this, 'shortcode' ) ); will never triggered.
There are two solutions. One, if you are make the shortcode method to static, and add this in your functions.php file:
add_shortcode( 'priceguide', 'CsvImporter::shortcode' ) );
The second option, if you do not want to make it static if you instantiate an object from your class, before anythings happens. In your functions.php
add_action('init', 'my_init');
global $CsvImporter;
function my_init() {
global $CsvImporter;
$CsvImporter = new CsvImporter();
}
In this case, when no output send to the buffer, you create a new CsvImporter object, so the __construct() will run, so shortcode will registered.
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))
{
//
}
}
I have the following function written in function.php in a wordpress theme
function get_mms($my_post) {
$post_id = $my_post; //$_GET["p"];
$queried_post = get_post($post_id);
$title = $queried_post->post_title;
preg_match_all('#\[mms\](.+)\[\/mms\]#', $queried_post->post_content, $matches);
echo 'EN: ' . $matches[1][0];
echo '<br><br><form action= " ' . get_permalink( $id ) . ' " method="post">
Numar: <input type="text" name="fname" />
<input name="submito" type="submit" />
</form>';
$numero = $_POST["fname"];
if(isset($_POST['submito'])&& $_POST['fname']){
$numero = $_POST["fname"];
header("Location: http://server/&to=$numero&text='.$matches[1][0].'&from=Moldcell");
}
When I submit the form instead of getting the value of $matches[1][0] I get Array[0].
Is there someting I did wrong? What can I do to make it grab the value of preg_match_all results?