Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I'm trying to make a private message system where users can have conversations with each other. Each conversation has its unique hash. I want to store the messages in my database but for some reason the value of hash gets stored as 0 instead of the number I am requesting.
<form method="post" action="exiConversations.php" id="sendMessageFooterForm">
<input type="text" name="userNewMessage" id="userMessage" placeholder="Type een bericht" />
<input type="submit" name="sendNewMessageSubmit" id="sendMessageSubmit" value="Verzend" />
<?php
if (isset($_POST['sendNewMessageSubmit'])) {
$message = $_POST['userNewMessage'];
$fromUser = $_SESSION['userID'];
$today = date("y/m/d H:i:s");
$exiHash = $_GET['hash'];
$insertNewMessage = $conn->query("INSERT INTO messages (fromuser, messagedate, message, grouphash) VALUES ('$fromUser', '$today', '$message', '$exiHash')");
}
?>
</form>
I dont know what to do anymore. It used var_dump($exiHash); which does show me the hash number I want to store but it only stores a 0.
Change your action attr in form tag.
it must me like
action="exiConversations.php?<?=$_GET['hash']?>"
but it will work only if you have current URL like ....?hash=45345345
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I had some help yesterday on passing a variable to a PHP page (Thanks). I now am stuck again.
Scenario - I am new so I know there is an easier way but at the moment I have a database that I want to query. Page 0 - I select a place (Called 'categorynum' [ I then pass that to page 1 (Which is the code below where it pulls in the categorynum from previous page and allows me to select a date. I now want to pass that date (categoryevent) and place (categorynum) to page 2. The below code passes categoryevent no problem but what am I doing wrong as its only passing the text of categorynum over.
CODE for page 1
<form method="get" action="page2.php">
<p>Date of Investigation:</p>
<select name="categoryevent">
<?php
foreach ($catByDate as $num=> $event){
print "<option value=\"$event\">$event</option>\n";
}
?>
</select>
<input type="hidden" name='categorynum' value='$categorynum'>
<input type="submit" value="Show Summary">
</form>
Ahh now I see it. You are not actually loading the value of $categorynum into the hidden input.
So change how you set the value into the input element
<input type="hidden" name='categorynum' value='<?php echo $categorynum; ?>'>
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
It is possible to hide get value from url (rozgaarexpress.com/profile.php?id=22) using .Htaccess.I want to hide ?id=22.
Then URL Looks like rozgaarexpress.com/profile.php
My first page demo.php
I am just passing this url
HTACCESS
second page profile.php
<?php
$id=$_GET['id'];
echo $id;
?>
You can't hide the ID parameter, even if you use .htaccess to achieve that. I mean you can do it but you will be able to use a single ID when accessing profile.php page which I don't think is the case you want.
You can do it by using sessions like:
demo.php
session_start();
$_SESSION['id'] = 22;
echo 'My profile';
profile.php
session_start();
echo $_SESSION['id'];
im sure you asked this question to find a way to avoiding show ID to public.
you can use session in this case like this:
<?php
session_start();
$_SESSION['session_name']=$id; // Set the value of the id you want to pass.
?>
and in profile.php page you need this:
<?php
session_start();
$id = $_SESSION['session_name'];
?>
or you can use JQuery.post to pass your data.
I would rather take the desired profile ID from the Client. This allows the end-user the option to open two different profiles from the same page:
<script type="text/javascript">
function setInputAndSubmit(input) {
var form=document.getElementById("skfrom");
var inputEl=document.getElementById("LANG");
inputEl.value = input;
form.submit();
} </script>
<form id="skfrom" name="myform" action="http://rozgaarexpress.com/profile.php" method="POST">
<div align="center">
First ID
<br>
Another ID
<br><br>
Same ID
<br><br>
You can even receive input from users and send it together with the ID.
<input type="text" size="25" value="Some other field you want visible">
<input type="hidden" id="LANG" name="Language" value="English">
</div>
</form>
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Sorry I am asking a question that has been asked before but in spite of reading all of them, I am still confused what to do.
What exactly I have to do to implement the remember me feature in my website I am building as my final year project. Is calling the function "setcookie()" alone sufficient?
setCookie() is all you need.
You can use it like this:
$cookie_value = 'MyUsername';
$cookie_expire = time() + 60*60*24*365;// 365 days
$cookie_path = '/';
setcookie('remember_me',$cookie_value, $cookie_expire, $cookie_path);
On the next pageload, you can fetch the remember_me cookie value with:
$_COOKIE['remember_me'];
But the 'next pageload' part is important because PHP cookies cannot be set and also read in the same browser action.
In the most simple way possible. The way I would bring this all together for demonstration for your project is have a php page with an html <form> that posts to itself.
Your filename would be something like my_form.php
inside it would be:
<?php
// If we received a username from the form, remember it for a year.
if( $_POST['username'] ):
setcookie('remember_me',$_POST['username'], time()+60*60*24*365, '/');
endif;
?>
<?php
// Display a message if the user is remembered.
if( isset($_COOKIE['remember_me']) ):
echo '<h2>Welcome back, '.$_COOKIE['remember_me'].'!</h2>';
endif;
?>
<form action="" method="post">
<input name="username" type="text" placeholder="Your Username" value="<?php echo $_COOKIE['remember_me'] ?>" required />
<button type="submit">Remember me</button>
</form>
This form submits to itself. If you see the username you just entered in the welcome message, then it is remembering you.
Very important! The setcookie() call in PHP must be the first thing in your my_form.php file. Otherwise setcookie() will not work if any output has happened to the web-browser before you call the setcookie() function.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have a html form, and i want that when u send the value of the html, to be a php variable
<form action="callback2.php" method="POST">
Telefoon nummer invoeren: <input type="text" size="10" name="nummerb" id="nummerb"> <input type="submit" value="submit">
this is the html and the value of this should be
$nummerb ="" ;
so the nummerb should have the value of the sended form.
You said in a comment:
i know that it should be $nummerb = $_POST ['nummerb']; but when i put
that in an run it, it says Undefined index, so it means it can't find
the 'nummerb'. So i should put ifisset right?
So the answer is:
$nummerb = "";
if(isset($_POST['nummerb']))
$nummerb = $_POST['nummerb'] ;
You also can check first if you got a form submission to make sure you do not check for the $nummerb if the user didn't pressed on the Send button:
add a name to your submit button
<input type="submit" name="submitButton" value="submit"/>
check if the user clicked on the submit button:
<?php
// If the user pressed on submit button
if(isset($_POST['submitButton'])) {
// Get the nummerb
$nummerb = "";
if(isset($_POST['nummerb']))
$nummerb = $_POST['nummerb'] ;
// Do your job here
}
?>
The answer to this very basic and silly question is:
$nummerb = $_POST["nummerb"];
You should learn more PHP before asking another question here.
The answer to your question could have been found within the PHP manual.
A simple Google query for php post returns the answers you are looking for.
http://php.net/manual/en/reserved.variables.post.php
You can access nummerb by this :
$nummerb = $_POST['nummerb'] ;
Or if you don't want to create "manually" the variables, use extract function :
extract($_POST);
echo $nummerb;
I am not sure for what you are looking.
But your html should be:
<form action="callback2.php" method="POST">
Telefoon nummer invoeren:
<input type="text" size="10" name="nummerb" id="nummerb">
<input type="submit" value="submit" name="submit">
</form>
And php code should be like that:
if(isset($_POST['submit'])){
$nummerb = $_POST['nummerb'] ;
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
Hello I am a beginner in php.
I've recently learned a bit about functions. But how do I dynamically insert data into the (). I've tried using get and post but that didn't work (Perhaps I just did something wrong). Any examples on how i could do it?
Thanks
action.php
<form action="action.php" method="post">
<p>Your name: <input type="text" name="name" /></p>
<p>Your age: <input type="text" name="age" /></p>
<p><input type="submit" /></p>
</form>
<?php
function myFunction($argOne, $argTwo) {
echo "inside function argOne=".$argOne;
}
if (isset($_POST['name']) {
//call the function only if the form is submited
myFunction($_POST['name'], $_POST['age']);
}
?>
I think you want to pass some data to your function
The post just send the data to your php page.
If you want to send some data to your function you should do that as a parameter.
Example:
$myvar = $_POST;
dumpData($data){
var_dump($data);
}
dumpData($myvar);
//OR
dumpData($_POST);
You can't just send the post to your function, you need to call that and use it as a param.