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();
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.
How to make something like this:
<td>
<?php echo $row['id']; ?>
</td>
to act like this:
<form action="test.php" method="post">
<div class="form-group">
<input type="text" class="form-control" name="input" />
</div>
<button type="submit" name="action">Show</button>
</form>
By other words, when I fill the form-control with some value and press "Show", the desired action performs.
I want to make the same action by pressing the link in the table.
Solved
Just : if (isset($_GET['input'])){…….}
Jeff thank you for explanation and suggestions.
I have problem with reciving $_GET value, I need it as a ID to update my table.
Im using <a href='includes/edit_section.php?id=$id'>Change</a>. Variable $id is properly fetched and it is working, when I click on this link (because it is in table) it shows right value.
But problem is in next part, when I recive it with $_GET. I tryed to make variable ($id = $_GET['id']) but there is no any change.
When I execute this, nothing updates, when I replace $_GET with number it works perfectly.
My table looks like this Table(ID,Title,Paragraph,Image)
This is my code:
<?php
if(isset($_POST['submit'])) {
$title = $_POST['title'];
$paragraph = $_POST['paragraph'];
$query = "UPDATE table SET title = '{$title}', paragraph = '{$paragraph}' WHERE id = '{$_GET['id']}' ";
$c= mysqli_query($connection, $query);
}
This is my form
<form action="edit_section.php" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="title">Title</label>
<input type="text" class="form-control" name="title">
<label for="paragraph">Paragraph</label>
<input type="text" class="form-control" name="paragraph">
</div>
<div class="form-group">
<input class="btn btn-primary" type="submit" name="submit" value="cHANGE">
</div>
</form>
The problem is that you need to send the id when you submit the form, a traditional way of doing it is using a hidden type input, for example <input type="hidden" name="id" value="<?= $id ?>"> And of course it is necessary to pass the id to the view where the form is rendered
So you could try this
<form action="edit_section.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="id" value="<?= $id ?>">
<div class="form-group">
<label for="title">Title</label>
<input type="text" class="form-control" name="title">
</div>
<div class="form-group">
<label for="paragraph">Paragraph</label>
<input type="text" class="form-control" name="paragraph">
</div>
<div class="form-group">
<input class="btn btn-primary" type="submit" name="submit" value="cHANGE">
</div>
</form>
And when processing the form
<?php
if(isset($_POST['submit'])) {
$id = $_POST['id'];
$title = $_POST['title'];
$paragraph = $_POST['paragraph'];
$query = "UPDATE table SET title = '{$title}', paragraph = '{$paragraph}' WHERE id = '{$id}' ";
$c= mysqli_query($connection, $query);
}
I separated in its respective form-group the inputs of title and paragraph
At top add
$id = $_GET['id'];
then
basically problem is in
<form action="edit_section.php"
it should be
<form action="edit_section.php?id=<?php echo $id;?>"
plus in your update query id should be ID (capital).. also check for other column names for case-sensitivity
change the action for form at HMTL like tihs
<form action="edit_section.php?<?=$_GET['id']?>" method="post" enctype="multipart/form-data">
Add "id" as a hidden variable in your form.
Edited - Missed out an enclosing double quote for the hidden 'id' value in the form.
<form action="edit_section.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="id" value="<?php echo $_GET['id']; ?>">
<div class="form-group">
<label for="title">Title</label>
<input type="text" class="form-control" name="title">
<label for="paragraph">Paragraph</label>
<input type="text" class="form-control" name="paragraph">
</div>
<div class="form-group">
<input class="btn btn-primary" type="submit" name="submit" value="cHANGE">
</div>
</form>
Make the following changes to your PHP script
<?php
if(isset($_POST['submit'])) {
$title = $_POST['title'];
$id = $_POST['id'];
$paragraph = $_POST['paragraph'];
$query = "UPDATE table SET title = '{$title}', paragraph = '{$paragraph}' WHERE id = '{$id}' ";
$c= mysqli_query($connection, $query);
}
?>
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.