I am echo values by the codes below. but i want to create for each values form for saving to database.
How can i insert form inside echo ?
I am beginer in php and i want form like this and it must replace with all echo values.
----FORM----
Thumbnail url :
url :
description:
submit Button
----FORM----
this is the code
foreach($posts as $post){
if ($post){
echo $post->thumbnail . "<br />";
echo $post->url . "<br />";
echo $post->description . "<br />";
}
}
I solved how to add.
foreach($posts as $post){
if ($post){
echo '<input id="title" class="form-control" type="text" name="title" value="'.htmlspecialchars($post->thumbnail).'">';
echo '<input id="teaser" class="form-control" type="text" name="teaser" value="'.htmlspecialchars($post->Url).'">';
echo '<input id="text" class="form-control" type="text" name="text" value="'.htmlspecialchars($post->description).'">';
echo '<button class="btn btn-primary" type="submit">add</button>';
}
}
this works fine... My second question is how i can add the code below codes to inside echo in a same way ?
i tried to add same way but (if isset line ) gives error
<input type="hidden" name="mode" value="news" />
<input type="hidden" name="edit_news_submit" value="true" />
<?php if(isset($edit_news['id'])): ?>
<input type="hidden" name="id" value="<?php echo $edit_news['id']; ?>" />
<?php endif; ?>
Related
I am new to codeigniter and i want to run my sms web service code in view when user insert number.
but the post method is empty! can anyone help me?
var_dump($_POST['sendSms']);exit;
if(array_key_exists('sendSms', $_POST)) {
sendSms();
}
function sendSms(){ //my sms web service code}
echo '<form method="Post" action= "http://crm.oynarco.ir/admin/settings?group=sms">';
?>
<input type="hidden"
name="<?php echo $this->security->get_csrf_token_name()?>"
value="<?php echo $this->security->get_csrf_hash()?>">
<?php
echo '<input type="hidden" name="username" value="09172030433"/><br />';
echo '<input type="hidden" name="password" value="Oynar1234" /><br />';
echo '<input type="text" name="to" class="form-control test-phone" placeholder="'._l('staff_add_edit_phonenumber').'" /><br />';
echo '<textarea type="text" name="text" class="form-control sms-gateway-test-message" placeholder="'._l('test_sms_message').'" ></textarea><br />';
echo '<input type="text" name="From" class="form-control" value="5000203069627" /><br />';
echo '<input type ="submit" name="sendSms" class="btn btn-info send-test-sms" value="'._l('send_test_sms').'" />';
echo '</form>';
in action root to controller then in controller get the post method and add your sms function.
?>
<form method="Post" action= "settings/sendSms">
<input type="hidden"
name="<?php echo $this->security->get_csrf_token_name()?>"
value="<?php echo $this->security->get_csrf_hash()?>">
<?php
echo '<input type="hidden" name="username" value = "09172030433"/><br />';
echo '<input type="hidden" name="password" value ="Oynar1234" /><br />';
echo '<input type="text" name="to" class="form-control test-phone" placeholder="'._l('staff_add_edit_phonenumber').'" /><br />';
echo '<textarea type="text" name="text" class="form-control sms-gateway-test-message" placeholder="'._l('test_sms_message').'" ></textarea><br />';
echo '<input type="text" name="From" class="form-control" value = "5000203069627" /><br />';
echo '<input type ="submit" name="sendSms" class="btn btn-info send-test-sms" value = "'._l('send_test_sms').'" />';
echo '</form>';
in controller:
public function sendSms(){
//var_dump($_POST);exit;
if (isset($_POST) ){
//send sms
}
I am in the middle of creating a CMS in PHP & MySQL for the company I work for and have hit a bump in the road.
So I have a table that fetches and lists everything from a table, then next to each record is an edit button.
This button has the following code:
<?php
echo '<td><form method="POST" action="editRecord.php?id='.$id.'">
<input type="submit" name="Edit"></form></td>';
?>
Which then obviously goes to that page, however on the next page i have the following code and it's not running anything.
I don't understand why it's not fetching the information from the database if I have given it the ID...
include 'login/connection.php';
$id = $row['id'];
$result = $db->query("SELECT * FROM vehicleOrderForm WHERE id = ' $id ' ");
$row = mysqli_fetch_array($result);
That code is at the start and then further down is this;
<?php
echo $row["id"];
$id = $row["id"];
$make = $row["make"];
$varient = $row["varient"];
$stockno = $row["stockno"];
$transmission = $row["transmission"];
$cc = $row["cc"];
$colour = $row["colour"];
$delivery = $row["delivery"];
$stock = $row["stock"];
$sold = $row["sold"];
$customer = $row["customer"];
$tax = $row["tax"];
$comments = $row["comments"];
?>
<div>
<h1><?php echo $id; ?></h1>
</div>
<form method="POST" action="">
<p>Make:</p>
<?php echo '<input type="text" name="make" value="'.$make.'" />;' ?>
<p>Varient:</p>
<input type="text" name="varient" value=" <?php echo $varient; ?>" /> <br />
<p>Stock Number:</p>
<input type="email" name="stockno" value="<?php echo $stockno; ?>" /> <br />
<p>Transmission:</p>
<input type="number" name="transmission" value="<?php echo $transmission; ?>" /> <br />';
<p>CC:</p>
<input type="username" name="cc" value="<?php echo $cc; ?>" /> <br />';
<p>Colour:</p>
<input type="text" name="colour" value="<?php echo $colour; ?>" /> <br />';
<p>Expected Delivery:</p>
<input type="text" name="delivery" value="<?php echo $delivery; ?>"/> <br />';
<p>In Stock:</p>
<input type="text" name="stock" value="<?php echo $stock; ?>"/> <br />';
<p>Status:</p>
<input type="text" name="sold" value="<?php echo $sold; ?>"/> <br />';
<p>Customer:</p>
<input type="text" name="customer" value="<?php echo $customer; ?>"/> <br />';
<p>Tax:</p>
<input type="text" name="tax" value="<?php echo $tax; ?>"/> <br />';
<p>Comments:</p>
<input type="text" name="comments" value="<?php echo $comments; ?>"/> <br />';
<input type="Submit" name="Edit" value="Edit">';
</form>
If anyone can understand it, that would be great.
That form around the Edit button looks like it's totally useless.. You can't sent the form with POST method, and attach an id to the action url: that param won't be sent.
Solution 1: If you can, I would suggest you to switch to GET param and use an anchor. Like this:
<?php echo '<td>Edit</td>'; ?>
And edit your code on page editRecord.php as follows:
$id = $_GET['id']; // you need to receive the param from the url
Solution 2: If you want to keep the <form>, you should write the following code:
<?php
echo '<td><form method="POST" action="editRecord.php"> '.
'<input type="hidden" name="id" value="'.$id.'" />'.
'<input type="submit" name="Edit"></form></td>';
?>
And on page editRecord.php:
$id = $_POST['id']; // you need to receive the param from the url
Been searching around here but where only able to find to show/hide if the variable isset or not.
I want to show two different infos depending if the variable is zero or not.
If variable is zero the text input and submit button should be visible.
If variable is not zero the facebook variable should be echoed and the reset button showed.
What am i doing wrong?
Heres my code ive been trying:
<?php
$sql2 = $db->query( "SELECT facebook FROM ".$db->prefix."users WHERE id = ".$id);
while ( $row = mysql_fetch_assoc ( $sql2 ) ) {
if (empty($row)) {
?>
<input type="hidden" name="form_sent" value="1" />
<input type="text" name="form[facebook]" value="<?php echo pun_htmlspecialchars($user['facebook']) ?>" size="40" maxlength="50" />
<input type="submit" name="update" value="<?php echo $lang_common['Submit'] ?>" />
<?php
} else {
?>
<?php echo pun_htmlspecialchars($user['facebook']) ?>
<a href="reset.php">
<input type="button" value="Request reset" />
</a>
<?php
}
}
?>
FIX EDIT
I just did it this way and it works fine.
<?php
if($user['facebook'] == '0'){
echo '<input type="button" value="Submit" />';} ?>
<?php
if($user["facebook"] > 0){
echo '<input type="button" value="Request reset" />'; }?>
Now why cant i add this in the echo?
<input type="text" name="form[facebook]" value="<?php echo
pun_htmlspecialchars($user['facebook']) ?>" size="40"
maxlength="50" />
I guess its because php echoes php?
Is there a workaround for this?
try this
<?php
$sql2 = $db->query( "SELECT facebook FROM ".$db->prefix."users WHERE id =
".$id);
while ( $row = mysql_fetch_assoc ( $sql2 ) ) {
if ( $row['facebook'] == 0 ) {
?>
<input type="hidden" name="form_sent" value="1" />
<input type="text" name="form[facebook]" value="<?php echo
pun_htmlspecialchars($user['facebook']) ?>" size="40"
maxlength="50" />
<input type="submit" name="update" value="<?php echo
$lang_common['Submit'] ?>" />
<?php
} else {
echo pun_htmlspecialchars($user['facebook'])
?>
<a href="reset.php">
<input type="button" value="Request reset" />
</a>
<?php
}
}
?>
I just did it this way and it works fine.
<?php
if($user['facebook'] == '0'){
echo '<input type="button" value="Submit" />';} ?>
<?php
if($user["facebook"] > 0){
echo '<input type="button" value="Request reset" />'; }?>
Now why cant i add this in the echo?
<input type="text" name="form[facebook]" value="<?php echo
pun_htmlspecialchars($user['facebook']) ?>" size="40"
maxlength="50" />
I guess its because php echoes php?
Is there a workaround for this?
I have this url: torneioJogo.php?equipaleft=24&equiparight=25&torneioid=8
The following code is in this url...
<form method='GET' action='torneioJogoSub.php?'>
//THESE INPUTS DOWN HERE
<input type="hidden" name="equipa1" value="<?php $_GET['equipaleft'] ?>">
<input type="hidden" name="equipa2" value="<?php $_GET['equiparight'] ?>">
<input type="hidden" name="torneioid" value="<?php $_GET['torneioid'] ?>">
<div id="pontos">
<input type="submit" name="win1" value="<=Vencedor">
<input type="submit" name="emp" value="Empate">
<input type="submit" name="win2" value="Vencedor=>">
<br>
<=Pontos=><br>
//AND THESE INPUTS DOWN HERE
<input type="text" name="pontos1" size="3">
<input type="text" name="pontos2" size="3">
<br>
</div>
</form>
When I submit the form, I need all the data from those inputs in the next page where I have this:
echo "equipa1: " . $_GET['equipa1'];
echo "equipa2: " . $_GET['equipa2'];
echo "torneioid: " . $_GET['torneioid'];
echo "pontos1: " . $_GET['pontos1'];
echo "pontos2: " . $_GET['pontos2'];
What happens is $_GET['pontos2'] and $_GET['pontos1'] work but the values from the hidden inputs (which are being pulled from the url variables), echo nothing. What's happening? Is this a problem with GETs and POSTs or am I missing something else?
You need to echo the values out
<input type="hidden" name="equipa1" value="<?php echo $_GET['equipaleft'] ?>">
<input type="hidden" name="equipa2" value="<?php echo $_GET['equiparight'] ?>">
<input type="hidden" name="torneioid" value="<?php echo $_GET['torneioid'] ?>">
You need to actually output the variables into the form fields
<input type="hidden" name="equipa1" value="<?php echo $_GET['equipaleft'] ?>">
^^^^
I want to check if either of my search fields are empty, and if they are i write out a failure message. For some reason the following code doesn't work when I try to submit empty values in both search fields, or leaving the q2 search field empty. It only writes out the failure message when I only insert a value into the first field. Hope you guys can help.
<div id="searchField">
<form name="searchField" action="" method="get">
<input type="search" name="q" id="submitQuery" autofocus="autofocus" value="<?= $_GET['q']; ?>" placeholder="enter one movie"/>
<input type="search" name="q2" id="submitQuery2" value="<?= $_GET['q2']; ?>" placeholder="and then another one"/>
<input type="hidden" id="v" name="v" value="2" />
<input type="hidden" id="b" name="b" value="" />
<button type="submit" id="loop" style="border:0px; background:transparent; vertical-align:middle; margin-left:-85px; margin-top:-3px;">
<img src="images/loop.png" width="75" height="75" alt="submit" />
</button>
</form>
</div>
<div id="theData">
<?
if(str_replace(" ", "",$_GET['q'])!="" && str_replace(" ","",$_GET['q2'])!=""){
$qContent = $_GET['q'];
$succes = mysql_query("SELECT*FROM film WHERE name='".$qContent."'");
include("searchMaster.php");
if(mysql_num_rows($succes)) {
while($o = mysql_fetch_array($succes)){
echo $o['name'];
if($o['trailer']){
echo '<div id="ytplayerWrap">';
echo '<iframe id="ytplayer" type="text/html" width="640" height="390"
src="http://www.youtube.com/embed/'.$o['trailer'].'?http://amnestic.ueuo.com"
frameborder="0"/>';
echo '</div>';
}else {
echo '<span style="font-size:20px;">';
echo '<br /><br /> No trailer was found for <em>'.$_GET['q'].'</em> :(';
echo '</span>';
}
}
}else{
echo 'You did the fuckup :(';
}
}else{
echo 'You did the fuckup :(';
}
?>
The name and id of your input fields must be same
Like this
<input type="text" name="submitQuery" id="submitQuery" autofocus="autofocus" value="<?= $_GET['q']; ?>" placeholder="enter one movie"/>
<input type="text" name="submitQuery2" id="submitQuery2" value="<?= $_GET['q2']; ?>" placeholder="and then another one"/>