echo a form and some jquery codes [closed] - php

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I would like to post and redirect some values to my path.
I find out the best solution is using a echo form .
but my code does not work :
function goToCodes($method = '' , $tr_ids = '')
{
$path = base_url().'cart/codes';
$jquery = base_url().'assests/new/js/jquery.js';
echo '<form action="'.$path.'" method="post" >';
echo '<input name="method" type="hidden" value="'.$method.'" />';
echo '<input name="tr_ids" type="hidden" value="'.$tr_ids.'" />';
echo '<input id="goToCodeSubmit" type="submit"/>';
echo '</form>';
echo '<script src="'.$jquery.'"></script>';
echo '<script>';
echo '$(function(){
$(#goToCodeSubmit).click();
});';
echo '</script>';
}
in the console I get this error :
SyntaxError: illegal character

You should put quotes around your jQuery selector, $("#goToCodeSubmit").
As a side note, without the quotes around #goToCodeSumit you're attempting to reference an element by the name #goToCodeSumit, which isn't an element in the DOM. Also, the hashtag is probably the thing causing the illegal character error.

Related

my all value is not showing in view, what can i d [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
This is my edit page where i want to get data from database in input box
#php
$abs = explode(',' , $order->product);
$quantitys = explode(',' , $order->quantity);
foreach (array_combine( $quantitys, $abs) as $quantity => $ab) {
$val = $ab . " " . $quantity;
echo "<input type=text name=pro value=$val>";
echo $val;
echo '<br>';
}
#endphp
This is pic you understand well after see image at bottom of input box this is original value that has to come
Rewrite this:
echo "<input type=text name=pro value=$val>";
to this
// add double quotes to attribute values
echo '<input type="text" name="pro" value="'.$val.'">';

Session variables in PHP not appearing [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I have read all the questions concerning this but I'm still at a loss.
Using a test script like this
// PAGE 1
<?php session_start();
echo var_dump($_SESSION) . "<br>";
$_SESSION[‘session_var’] = "stuff";
$PHPSESSID = session_id();
echo session_id() . "<br>";
?>
<html>
<head><title>Testing Sessions page 1</title></head> <body>
<p>This is a test of the sessions feature.
<form action="sessionTest2.php" method="POST">
<input type= "text" name= "form_var" value= "testing">
<input type= "submit" value= "Go to Next Page"> </form>
</body>
</html>
//PAGE 2
<?PHP session_start();
echo var_dump($_SESSION);
$session_var = $_SESSION['session_var'];
$form_var = $_POST['form_var'];
echo "session_var =" . $session_var. "</br>";
echo "form_var =" . $form_var. "<br>";
$PHPSESSID = session_id();
echo session_id();
?>
the results I get in page 2 are
array(1) { ["‘session_var’"]=> string(5) "stuff" } session_var =
form_var =testing
al89u6vu02lstp99cs4damdn04
As you can see the variable session_var can be seen in the array but is not being output to the screen where expected, and yes session_start() is at the very top of both pages.
Any ideas what may be wrong
$_SESSION[‘session_var’] = "stuff";
Is using non ascii ‘’ quote marks.
Are you using a word processor to edit your code?
Those quotes are now part of the key name, see this ["‘session_var’"].
Stick to simple ascii single and double quotes ' or "

PHP: $_FILES returns empty [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
Pardon if parts of this question don't make sense—I'm a newb to programming in general. Feel free to correct me!
Here's my problem: I'm making a PHP upload page that uses $_POST. There are two upload fields in the HTML section, both of which are optional. So here's my code for, let's say, example-upload.php:
<form action="" enctype="multipart/form-data" method="post">
<input type="file" id="upload1" name="upload1" accept=".jpg">
<input type="file" id="upload2" name="upload2" accept=".jpg">
<button type="submit" name="submit">Submit either, both, or none of these</button>
</form>
<?php
if (isset($_POST['submit'])) {
if (!empty($_POST['upload1'])) {
$filename_upload1 = $_FILES['upload1']['name'];
}
if (!empty($_POST['upload2'])) {
$filename_upload2 = $_FILES['upload2']['name'];
}
// Checks if there is no upload at all
if (!isset($filename_upload1) && !isset($filename_upload2)) {
echo 'You didn\'t upload anything and that\'s OK';
} else {
if (isset($filename_upload1)) {
move_uploaded_file($_FILES['upload1']['tmp_name'], 'path/to/file/' . $filename_upload1);
}
if (isset($filename_upload2)) {
move_uploaded_file($_FILES['upload2']['tmp_name'], 'path/to/file/' . $filename_upload2);
}
echo 'One or two files was successfully uploaded';
}
}
?>
Each time I run this, submitting either one or both files, I get the "You didn't upload anything and that's okay" message, leading me to believe that I'm doing something wrong with the $_FILES variable. The unusual thing is that I have a different form on a similar page, except with one upload field instead of two. That seems to work.
Any advice? Thank you!
There's no $_POST['upload1'] variable in your form.
Files are passed within $_FILES array.
So, in simplest case you can check $_FILES['upload1']['name']:
if (!empty($_FILES['upload1']['name'])) {
$filename_upload1 = $_FILES['upload1']['name'];
}
And the same check for upload2:
if (!empty($_FILES['upload2']['name'])) {
$filename_upload2 = $_FILES['upload2']['name'];
}
You have to check $_FILES and not $_POST
if (!empty($_FILES['upload1']))
{
$filename_upload1 = $_FILES['upload1']['name'];
}

how to check textbox with ctype_digit PHP [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
This is my code, I get variable from textbox but nothing appears.
This code checks if a input is number:
this is a number
or not:
this is not a number
<?php
echo'<form method="post" action="">';
echo '<input type=text name=t/>';
echo'<input type=submit name=su/>';
echo'</form>';
if(isset($_POST['su']))
{
if (ctype_digit($_POST['t'])) {
echo "This is number.\n";
} else {
echo "This is not a number.\n";
}
}
?>
All of code is in one page.
Your code is failing because you have unquoted elements/attributes.
The following require quotes for:
echo '<input type=text name=t/>';
^^^^ ^^^^^^
echo'<input type=submit name=su/>';
^^^^^^ ^^^^^^^
Modify your code to read as:
<?php
echo'<form method="post" action="">';
echo '<input type="text" name="t"/>';
echo'<input type="submit" name="su"/>';
echo'</form>';
if(isset($_POST['su']))
{
if (ctype_digit($_POST['t'])) {
echo "This is number.\n";
} else {
echo "This is not a number.\n";
}
}
?>
Certain web browsers will not accept unquoted elements/attributes and will simply be ignored, such as the current version of Firefox and will fail silently even with error reporting set to catch/display, strangely enough.
You can test for a number using the JS function isNAN. PHP processes on the server so once the page is loaded it is not available. Javascript is available though after the page loads. JS is client side and is executed on the browser. Here's a js solution:
var test = 1;
if(isNaN(test)) {
alert('String');
} else {
alert('number');
}
This would alert number.
Here's a longer write up on that JS function, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN.
If method is not defined in <form> then the default is GET. So
<form>
is the same as
<form method="GET">
If you want to use $_POST, you need to do
<form method="POST">

PHP Function name needs to be a string [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm trying to make an incredibly basic php form that outputs some text a user puts in to a database. Looked at a couple other questions like this to make sure and from what I can tell no one else asked about this. Here's the create.php that takes input from the html.
<?php
include 'connection.php';
$firstname= $_POST('inputName');
$lastname= $_POST('inputName2');
if($_POST ['SUBMIT']) { echo "please fill out the form";
header('location: ../index.html');
} else {
mysql_query("INSERT INTO requestdata ('firstname', 'lastname')
VALUES ('$firstname', '$lastname')") or die(mysql_error());
echo "User has been added"; header ('Location: ../index.html');
}
?>
Here's the html code for the form:
<form action = "php/create.php" method = "POST">
First Name <input type ="text" name='inputName' value=""/>
Last Name <input type="text" name='inputName2' value=""/>
<br />
<input type="submit" name = "button">
</form>`
and the error I'm getting is:
"Fatal error: Function name must be a string in
mywebsite.com/php/create.php on line 8
I think your $_POST variables are wrong.
Please try $_POST['inputName'] instead of $_POST('inputName') and $_POST['inputName2'] instead of $_POST('inputName2')

Categories