Why I cant set value with echo variable in text form jquery eui?
<input type="text" name="text1" class="easyui-validatebox" value="<? echo $varPhp; ?>" size="53"/></td>
My php function like this..
<?php
$query = "SELECT MAX(kode_barang) as maxID FROM tb_barang";
$hasil = mysql_query($query);
$data = mysql_fetch_array($hasil);
$idMax = $data['maxID'];
$noUrut = (int) substr($idMax, 1, 4);
$noUrut++;
$varPhp = "B" . sprintf("%04s", $noUrut);
?>
Anyone can help me?
Question Closed.. :) i pass the process and create in model.
May be your php version doesnt support the use of short tags.Check the documentation .And try this
<input type="text" name="text1" class="easyui-validatebox" value="<?php echo $varPhp; ?>" size="53"/>
Try
<?php echo $varPhp; ?>
I assume that your variable is empty.
To ensure that, use var_dump to dump it.
Try this:
<input type="text" name="text1" class="easyui-validatebox" value="<?php var_dump($varPhp); ?>" size="53"/>
Related
When user inputs text in 'ctext' field and press accept, I want to fill the value=" " field with user input, i achieved this but it fills all the value fields of same name in the page, how can i achieve it for different value of different ctext input? Anyone please give me solution with example, Many thanks
<?php
$connect = mysqli_connect('localhost', 'root', 'root123', 'font');
$query = 'SELECT * FROM pens ORDER by id ASC';
$result = mysqli_query($connect, $query);
if($result):
if(mysqli_num_rows($result)>0):
$i=0;
while( $pen = mysqli_fetch_assoc($result) ):
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>?action=add&id=<?php echo $pen['id']; ?>">
<div class="name pen-<?php echo $pen['id']; ?>">
<input type="text" name="ctext[]" class="form-control" placeholder="Type your text here" value="<?php $ctext = false; if(isset($_POST['ctext'])){ $ctext = $_POST['ctext']; } echo $ctext[$i]; ?>"></input>
<input type="hidden" name="id" value="<?php $pen['id']?>"></input>
</div>
<div class="btn-custom">
<input type="submit" name="add_to_cart" class="btn btn-block" value="Accept"></input>
</div>
</form>
<?php
$i++;
endwhile;
endif;
endif;
?>
I hope I understand what you want. You want to access the ctext for each individual $pen when printing the corresponding form.
You just need to name your <input> with a unique name and then access that value when printing. A possible solution is this:
<input type="text" name="ctext[<?php echo $pen['id']; ?>]" class="form-control" placeholder="Type your text here" value="<?php $ctext = ''; if(isset($_POST['ctext'][$pen['id']])){ $ctext = $_POST['ctext'][$pen['id']]; } echo $ctext; ?>"></input>
What does it do?
name="ctext[<?php echo $pen['id']; ?>]" ensures a unique name for each $pen. For a $pen with id 1 this will result in name="ctext[1]".
if(isset($_POST['ctext'][$pen['id']])){ $ctext = $_POST['ctext'][$pen['id']]; } uses $pen['id'] to look up the corresponding value in $_POST['ctext'].
By the way, when outputting user input you should always escape it, e.g. with htmlspecialchars. This will look like this: echo htmlspecialchars($ctext); That way malicious input like "><script>alert('Hello!')</script> won't execute the javascript.
Update: as requested a solution using session to store data:
<?php
$connect = mysqli_connect('localhost', 'root', 'root123', 'font');
$query = 'SELECT * FROM pens ORDER by id ASC';
$result = mysqli_query($connect, $query);
if($result):
if(mysqli_num_rows($result)>0):
session_start();
if (isset($_POST['ctext'])) {
$_SESSION['ctext'][$_POST['id']] = $_POST['ctext'];
}
while( $pen = mysqli_fetch_assoc($result) ):
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>?action=add&id=<?php echo $pen['id']; ?>">
<div class="name pen-<?php echo $pen['id']; ?>">
<input type="text" name="ctext" class="form-control" placeholder="Type your text here" value="<?php $ctext = ''; if(isset($_SESSION['ctext'][$pen['id']])){ $ctext = $_SESSION['ctext'][$pen['id']]; } echo htmlspecialchars($ctext); ?>"></input>
<input type="hidden" name="id" value="<?php echo $pen['id']?>"></input>
</div>
<div class="btn-custom">
<input type="submit" name="add_to_cart" class="btn btn-block" value="Accept"></input>
</div>
</form>
<?php
endwhile;
endif;
endif;
Note: I removed the now unnecessary counter $i. The session handling is mainly done before the while loop (start a session and store POST data). During output the values from the session are used. The name of the input is not an array anymore.
Change name of an input to an array.like this . When you submit the form you will get these values as an array. Give it a try
<input type="text" name="ctext[]" class="form-control" placeholder="Type your text here"></input>
I guess your code is misleading you, your form is in while loop so once any of the ctext input is filled your variable $_POST['ctext'] is set on server side and according to your code it sets all the value of ctext once accept is pressed.
You can have different names as a solution or an array indexing in input field name=“ctext[]” to avoid this.
I am new to PHP, and have a web form, that I am using PHP to get data from the database. What I have currently done, as I havent been able to find out another solution to do so (despite my searching - probably dont know the correct terms to look for), is individually executing a SQL Query for each input field on my form.
As below:
<div class="search-line">
<div class="search-option">
<label>Asset Tag:<i title=""></i></label>
<?php
$asset_tag_sql = "SELECT HardwareAsset.HardwareAssetAssetTag FROM HardwareAsset WHERE HardwareAssetID = '".$_SESSION["HardwareAssetID"]."'";
$asset_tag = sqlsrv_query($database_connection, $asset_tag_sql);
?>
<input type="text" id="AssetTag" disabled value="<?php while ($asset_tag_option = sqlsrv_fetch_object($asset_tag)){echo $asset_tag_option->HardwareAssetAssetTag;} ?>" />
</div>
<div class="search-option">
<label>Serial Number:<i title=""></i></label>
<?php
$serial_number_sql = "SELECT HardwareAsset.HardwareAssetSerialNumber FROM HardwareAsset WHERE HardwareAssetID = '".$_SESSION["HardwareAssetID"]."'";
$serial_number = sqlsrv_query($database_connection, $serial_number_sql);
?>
<input type="text" id="SerialNumber" disabled value="<?php while ($serial_number_option = sqlsrv_fetch_object($serial_number)){echo $serial_number_option->HardwareAssetSerialNumber;} ?>" />
</div>
</div>
Is there anyway to have one PHP piece of code to do one SQL query and then use that to fetch and echo the value for both input fields, as opposed to the two above?
Try it like this?
<?php
$asset_sql = "SELECT HardwareAsset.HardwareAssetAssetTag,HardwareAsset.HardwareAssetSerialNumber FROM HardwareAsset WHERE HardwareAssetID = '".$_SESSION["HardwareAssetID"]."'"
$asset_result = sqlsrv_query($database_connection, $asset_sql);
$asset_data = sqlsrv_fetch_object($asset_result);
?>
<div class="search-line">
<div class="search-option">
<label>Asset Tag:<i title=""></i></label>
<input type="text" id="AssetTag" disabled value="<?php echo $asset_data->HardwareAssetAssetTag; ?>" />
</div>
<div class="search-option">
<label>Serial Number:<i title=""></i></label>
<input type="text" id="SerialNumber" disabled value="<?php echo $asset_data->HardwareAssetSerialNumber; ?>" />
</div>
</div>
Why not just select two fields from the initial query like this:
$serial_number_sql = "SELECT HardwareAsset.HardwareAssetSerialNumber,
HardwareAsset.HardwareAssetAssetTag FROM HardwareAsset WHERE
HardwareAssetID = '".$_SESSION["HardwareAssetID"]."'";
Here, I want to get value of textbox, but I coudn't.
Where am I wrong?
Is it must to use session if i want to get value of textbox?
<input type="submit" id="processorder" name="processorder" class="submit-green" value="Process Order"/>
<?php
foreach ($order_list as $row)
{
?>
<td class="align-center">
<input type="text" name="text[]" autocomplete="off" id="txtid_<?php echo $row['id']; ?>" readonly value="<?php echo $text;?>">
</td>
</tr>
<?php
$i++;
}
?>
if(isset($_POST['processorder']))
{
$txtvalue = $_GET['text[]'];
echo "helo".print_r($txtvalue);
}
this is wrong,
$txtvalue = $_GET['text[]'];
it should be
$txtvalue = $_GET['text'];
^ no [] here
Replace $_GET['text[]'] to $_GET['text']
The field would not be called text[] to PHP. It would just be called text, but would be an array instead of a string.
Try this:
if(isset($_POST['processorder']))
{
$arrayvalue = $_GET['text'];
foreach($arrayvalue as $txtvalue){
echo "helo" . $txtvalue . "<br>";
}
}
As your text input name is text[] with a bracket, it indicates that it is sending as an array, so to get the value you need
if (!empty($_POST["test"][0]) ) {
$test_value = $_POST["test"][0];
}
I am using 0 here since your code only shows one input text, for the server-end will only receive one array value
why you use array name="text[]" if you don't want to get multiple data using "text" than make it name="text"
<input type="text" name="text" autocomplete="off" id="txtid_<?php echo $row['id']; ?>" readonly value="<?php echo $text;?>">
get value using
$_GET['text'] // get value
or
you want to multiple data using same name "Array"(mean using array)
<input type="text" name="text" autocomplete="off" id="txtid_<?php echo $row['id']; ?>" readonly value="<?php echo $text;?>">
get value using
$_GET['text'][0] // 0 is a index value
I am making a very simple storage system, and i want to make it so that the user puts a number in the box, and press the + or - button, to add or subtract.
I don't know if it's even possible to do it, as simple as i wanted it to be :)
but anyway, here is the code so far for index.php
<?php $v_stk = "v_stk" ?>
<form action="index_sql.php" method="POST">
<input name="v_id" type="hidden" value="<?php echo $v_assoc["v_id"] ?>" />
<input name="v_stk" type="textfield" size="8" />
<input name="+" type="submit" value="+" style="height:23px; width:35px;" />
<input name="-" type="submit" value="-" style="height:23px; width:35px;" />
</form>
<td class="width50 sidepadding">
<?php echo $v_assoc["v_stk"]; ?></td>
<?php }; ?>
and here is for index_sql.php
<?php
require("db/db.php");
$v_id = mysql_real_escape_string($_POST["v_id"]);
$v_stk = mysql_real_escape_string($_POST["v_stk"]);
$sql = mysql_query("SELECT v_stk FROM vare WHERE v_id = '$v_id'");
$assoc = mysql_fetch_assoc($sql);
$v_nu = $v_stk + $assoc;
mysql_query("UPDATE vare SET v_nu = '$v_stk' WHERE v_id = '$v_id'");
header("location: index.php");
?>
I don't know if it is remotely close to something that would work, but with this code it gives me:
Fatal error: Unsupported operand types in C:\wamp\www\lager\index_sql.php on line 8
Because, You are performing addition with an array type variable.
$assoc = mysql_fetch_assoc($sql);
Here, $assoc is an array variable so try like this,
$v_nu = $v_stk + $assoc['v_stk'];
I have an entry Form. When the page is loaded, it must check:
if ($_SESSION[WorkMode] == 'UPDATE')
Then fill the Form with values from the database, else open a blank Form.
If I fetch the results in a different PHP file and call this .php file on load, how to fill the Form.
Set the variables that hold the values for your form, then include the "template" of the form you're having.
File 1:
<?php
$res = mysql_query("..");
if($res) {
$row = mysql_fetch_assoc($res);
$name = $row['name'];
$birthday = $row['birthday'];
...
include('form.tpl');
}
File 2 (form.tpl)
<form action="">
<input type="text" name="username" value="<?php isset($name)?$name:""; ?>" />
.. and so on
</form>
Alternatetively you can use a full blown template engine like Smarty to do the job for you.
Best wishes,
Fabian
$formvalue = NULL;
if ($_SESSION[WorkMode] == 'UPDATE')
$formvalue = $some_database_value;
echo '<input type="text" name="myname" value="'.$formvalue .'" />';
I found out that the following did it for me, adding the variable after a column.
<label>Firstname : </label><input type="text" name="Firstname" value= "<?php echo (isset($_POST['firstname'])) ? htmlspecialchars($_POST['firstname']) : $firstname;?>"