Can anyone help me out, not the expert on php/sql. Have looked about but can't find my answer to my problem. My logged in user has an inout field which they put in their answer. On the submit button I want it to update to the sql the users answer. But nothing happens
I have an input field which is this.
<div class="collapse navbar-collapse">
<form class="navbar-form navbar-right" method="post">
<div class="form-group">
<input type="text" name="answer" placeholder="Answer" class="form-control" value="<?php ($_POST['answer']); ?>" />
<input type="submit" name="submit" class="btn btn-success" value="Submit" />
</div>
</form>
And my php which is this.
function post_answer() {
$answer = $_POST['answer'];
$sql = "UPDATE users SET answer = '".$answer."' WHERE id='".$_SESSION['id']."'";
}
Any help would be much appreciated.
Related
My update function is not working the browser is showed $_GET['ticketID'] is not set.
<form action="ticketResolve.php" role="form" method="post">
<input type="hidden" name="ticketID" value="<?=$ticket['ticketID']?
<label for="username">Sender_name</label>
<input type="text" class="form-control" name="sender_name"placeholder="Enter Username" value="<=$ticket['sender_name']>"readonly>
</div>
<div class="form-group col-xs-6">
label for="firstName">Contact</label>
<input type="text" class="form-control" name="contact" placeholder="Enter First Name" value="<?=$ticket['contact']?>" readonly>
</div>
<br><br>
<button type="submit" class="btn btn-orange-1" name="resolveTicket">Resolve</button>
</form>
this is my form
ticketID is from this loop and transfer it to the ticketResolve.php page where the ticketID is use to get the details of the ticket, which works data from the database populate the input tags.
and this is the code in the ticketResolve.php page
$ticket = getTicketDetails($_GET['ticketID']);
if(isset($_POST['resolveTicket'])) {
resolveTicket($loggedUser['userName'], $loggedUser['userID'],
$_POST['ticketID']);
header("Location: admin_viewTickets.php");
}
<input type="text" value="<?=$text?>"> //this is showing 1
the "resolve" field should change from 0 to 1
Please help thank you
You're missing a = in the href attribute, change it to
<a class="btn btn-info btn-sm" href="ticketResolve.php?ticketID=<?=$ticket['ticketID']?>">view</a>
Update it is now working there was a typo error in my sql command -_- thank you for your help guys. All it took was a little nap.
I am making a forum, and I can add a reaction to save in the database, the only problem now is that it will leave empty id in the database.
The database:
How it will post it now:
Now I need to find a way to add the ledenpagina_id, topic_id and klant_id automatic. The klant_id needs to be set based on the klant session, but I am not sure how to get that.
The topic_id is set as active_id like this:
$actieftopicid = $topic['id'];`
But I don't know how to add that in the post so it will save it the correct way in the database.
I have tried doing this:
$q1['topic_id'] = $app->check_string($_POST[$topic['id']]);
But that isn't working.
The code to post it in the database:
<?php
if(isset($_POST['react_btn'])){
unset($q1);
$q1['reactie'] = $app->check_string($_POST['reactie']);
$q1['topic_id'] = $app->check_string($_POST[$topic['id']]);
$app->insert_query('reacties', $q1, 'id');
}
?>
<form action="" method="post">
<div class="form-group">
<label for="comment">Reactie:</label>
<textarea class="form-control" name="reactie" rows="3" id="comment"></textarea>
<button type="submit" name="react_btn" class="btn btn-primary">Plaats reactie</button>
</div>
</form>
You can add the id of the topic into the form like this:
<form action="" method="post">
<div class="form-group">
<label for="comment">Reactie:</label>
<textarea class="form-control" name="reactie" rows="3" id="comment"></textarea>
<input type="hidden" name="topicid" value="<?php echo $topic['id']; ?>">
<button type="submit" name="react_btn" class="btn btn-primary">Plaats reactie</button>
</div>
</form>
and then you can use it like $_POST['topicid'], since that is the name of the hidden input. Also, instead of
unset($q1);
you need to initialize $q1 properly:
$q1 = array();
I'm stumped. I've looked this up on multiple answers on Stackoverflow, but just can't get it. Maybe I'm just not seeing something.
I'm making a Family Feud game and using PHP and MySQL databases to store and retrieve information. For the Fast Money Round, I have a database with a Table called "FastMoney1" I'm using an HTML5 form and PHP to post the data in the form to that table, which has two columns: answer and score
I'm running my query through a for loop, but it's not posting anything to the table. I'm wondering what I'm doing wrong.
HTML:
<form method="post" class="form-horizontal">
<div class="form-group">
<div class="col-xs-9">
<input type="text" class="form-control" id="question1answer" name="answer[0]" placeholder="Question 1">
</div>
<div class="col-xs-3">
<input type="number" class="form-control" id="question1score" name="score[0]" placeholder="0">
</div>
</div>
<div class="form-group">
<div class="col-xs-9">
<input type="text" class="form-control" id="question1answer" name="answer[1]" placeholder="Question 2">
</div>
<div class="col-xs-3">
<input type="number" class="form-control" id="question1score" name="score[1]" placeholder="0">
</div>
</div>
<div class="col-xs-4 col-xs-offset-4" align="center">
<input type="submit" class="btn btn-success" name="Submit" />
</div>
</form>
PHP:
<?php
if(isset($_POST['submit'])){
require "config.php";
for ($i = 0; $i<count($_POST); $i++){
$answer = $_POST['answer'][$i];
$score = $_POST['score'][$i];
$sql = "INSERT INTO `fastMoney1`(`answer`, `score`) VALUES ('$answer','$score')";
if ($conn->query($sql) === TRUE) {
echo "";
} else {
echo $conn->error;
}
}
$conn->close();
echo "<meta http-equiv='refresh' content='0'>";
}
?>
All of this lives on the same PHP page, which is why I do not have an action attached to the form.
The config.php is an include that calls the host, username, password and database and opens the connection
Remember that PHP variables as case sensitive you have given name Submit in form while in php you are checking if(isset($_POST['submit'])){ which never become true.
change it to
if(isset($_POST['Submit'])){ //<----- S in upper case
EDIT
You also need to change your loop to
for ($i = 0; $i<count($_POST['answer']); $i++){
see your sql statement you don't need those ampersand in table name and column names INSERT INTO fastMoney1(answer, score) VALUES ('$answer','$score')
<input type="submit" class="btn btn-success" name="submit" />
i changed
name="Submit"
to
name="submit"
"Submit" to "submit" ----->"S" to "s"
and it works fine
So I am actually not sure what I am doing wrong, and I am sure it is just some small mistake, but I can't seem to get the submit button to take the information in the form and and send it to the database.
Here is what my code looks like.
So with this I am able to successfully connect to the database:
<?php
$mysql_host = 'localhost';
$mysql_pass = '';
$mysql_user = 'root';``
$mysql_db = 'blog';
if (! #mysql_connect($mysql_host, $mysql_user, $mysql_pass) || ! #mysql_select_db($mysql_db)){
die('Error');
}
?>
and I able to see the contents of table by printing them to the screen.
I believe the problem is here in this simple html form:
<form action="index.php" method = "post">
<div class="ui form">
<div class="field" name = "title">
<label>Title</label>
<input type="text">
</div>
<div class="field" name = "post">
<label>New Post</label>
<textarea></textarea>
</div>
</div>
<br>
<div class="ui submit button" name = "submit">Submit New Post</div>
</form>
I am just curious as to which php code I should use to connect this form so I am able to send the contents of the form over to the database.
elements can be styled just like elements and can have type="submit" so the instead of div you can use and avoid extra spaces between attributes and values. Instead of your code:
<div class="ui submit button" type="submit" name="submit">Submit New Post</div>
you can use:
<button class="ui submit button" type="submit" name="submit">Submit New Post</button>
as like :
<form action="index.php" method="post">
<div class="ui form">
<div class="field">
<label>Title</label>
<input type="text" name="title">
</div>
<div class="field">
<label>New Post</label>
<textarea type="text" name="post"></textarea>
</div>
</div>
<br>
<button class="ui submit button" type="submit" name="submit">Submit New Post</button>
</form>
I hope you will get your desire result.
provide the name field into the html tags e.g.
<form action="index.php" method="post">
<input type="text" name="title">
<input type="text" name="Sub-title">
<input type="submit" name="submit">
</form>
Inside index.php you can write
$title = $_POST['title'];
$subtitle = $_POST['Sub-title'];
You missing name attribute from the fields and elements can be styled just like elements and can have type="submit" so the instead of div you can use and avoid extra spaces between attributes and values.
and change input of a submit div
Submit New Post
You are missing name attribute from the input fields , and the submit should be a input if you are a using normal PHP form submit
<input type="text" name="title">
and change the submit div to a input
<input type="submit" name="submit" value="Submit New Post" />
You are missing a name attribute in your form fields:
<input type="text">
Should be something like:
<input type="text" name="title">
This is mandatory in order to be able to retrieve your POST datas in your PHP page, and it applies to every input you need to process in your PHP page (in this case your <input> and your <textarea> elements).
Once done this, you'll be able to retrieve each specific POST value in your PHP page by accessing the superglobal array $_POST:
$title = $_POST['title'];
The problem is here:
<div class="ui submit button" name = "submit">Submit New Post</div>
it should be:
<div class="ui submit button" type="submit" name = "submit">Submit New Post</div>
However, I suggest you use PDo to handle this for better.
Hi having a problem with this code even if i clicked on cancel it will still proceed to use the action of my form even though the CANCEL button is not part of the form, Would appreciate any help.
Here is the code.
<form method="post" action="input_enroll.php" >
<div id="overlay1">
<div>
<h1> Enter Educational Level Entry</h1>
<input type="text" name="level" >
<input type="submit" value="Proceed To Enroll" '>
</form>
<input type="submit" value="Cancel" onclick='overlay()'>
</div>
</div>
EDIT: Any suggestions what would be a better idea? I'm thinking putting the cancel outside the div.
You are having form started, then divs started, then form closed..start form after divs..
as your markup is not correct, browsers will change it as thier parser suggest,
In chrome </form> tag is postponed after </div>s..
<div id="overlay1">
<div>
<form method="post" action="input_enroll.php" >
<h1> Enter Educational Level Entry</h1>
<input type="text" name="level" />
<input type="submit" value="Proceed To Enroll" />
</form>
<input type="submit" value="Cancel" onclick='overlay()' />
</div>
</div>