This is advertisement query
INSERT into advertise_management(advertisement_name,adv_code) values('".$adv_name."','".$adv_code."')
post management:
<input type="text" name="post_name" value="<?php if(isset($post_value)){ echo $post_value['post_name'];} else { echo ''; }?>" required="required">
<?php $res= mysql_query("select * from advertise_management ");
while($result= mysql_fetch_array($res)){
$adv=$result['advertisement_name'];
{ ?>
<input type="checkbox" value="<?php echo $adv?>" name="post_adv[]">
<?php } ?>
Post Management insert query :
$post_name = $_POST['post_name'];
$post_adv1 = $_POST['post_adv'];
$post_adv = implode(",", $post_adv1);
$post_id = $_POST['post_id'];
$res = mysql_query("INSERT into post_managment(post_name,post_adv) values('".$post_name."','".$post_adv."')") or die(mysql_error());
Post management edit :
$result = mysql_query("SELECT * FROM post_managment where post_id='$pid'");
$post_value = mysql_fetch_array($result);
><input type="text" name="post_name" value="<?php if(isset($post_value)){ echo $post_value['post_name'];} else { echo ''; }?>" required="required">
<?php $res= mysql_query("select * from advertise_management ");
while($result= mysql_fetch_array($res)){
$adv=$result['advertisement_name'];
{ ?>
<input type="checkbox" value="<?php echo $adv?>" name="post_adv[]">
<?php } ?>
<input type="submit" value="" id="create"><input type="reset" value="" id="cancel">
I want to return the values that is checked and the values that is not checked.
The browser normally won't send anything for checkboxes that aren't checked. You can work around this by also rendering a hidden input () with the same name and a different value. Make sure it's output right before the checkbox.
Related
I'm trying to call the old values to be edited. What part am I wrong at?
<?php
if (isset($_GET['edit'])) {
$id = $_GET['edit'];
$update = true;
$record = mysqli_query($db, "SELECT * FROM bookinfo WHERE BookNo='$BookNo'");
if (mysqli_num_rows($record) == 1 ) {
$n = mysqli_fetch_array($record);
$BookNo = $n['BookNo'];
$ISBN = $n['ISBN'];
$title = $n['title'];
$author = $n['author'];
$publisher = $n['publisher'];
$status = $n['status'];
$cost = $n['cost'];
}
}
?>
<a href="viewBook.php?edit=<?php echo $row['BookNo']; ?>" class="edit_btn" >Edit</a>
</td>
<?php
if (isset($_GET['edit'])) { ?>
<form method="post" action = "viewBook.php">
<input type="hidden" name="BookNo" value="<?php echo $BookNo; ?>">
<input type="text" name="ISBN" value="<?php echo $ISBN; ?>">
<input type="text" name="title" value="<?php echo $title; ?>">
<input type="text" name="author" value="<?php echo $author; ?>">
<input type="text" name="publisher" value="<?php echo $publisher; ?>">
<input type="text" name="status" value="<?php echo $status; ?>">
<input type="text" name="cost" value="<?php echo $cost; ?>">
<?php if ($update == true): ?>
<button class="btn" type="submit" name="update" style="background: #556B2F;" >update</button>
<?php else: ?>
<button class="btn" type="submit" name="save" >Save</button>
<?php endif ?>
<?php } ?>
</form>
So far, what it does is, when the user clicks the edit button, it just shows 6 text fields. I thought by doing what I did, it was supposed to show the details already filled in the textbox.
When you do
$record = mysqli_query($db, "SELECT * FROM bookinfo WHERE BookNo='$BookNo'");
$BookNo is not defined.
maybe you wanted to do something like this:
$id = $_GET['edit'];
$update = true;
$record = mysqli_query($db, "SELECT * FROM bookinfo WHERE BookNo='$id'");
<form method="post" action = "viewBook.php">
your form method is "post" but you are checking $_GET You must check $_POST
if (isset($_GET['edit']))
you are passing value in $id And using $BookNo which not define.
only 6 input field will be show because first one is using hidden property.
<input type="hidden" name="BookNo" value="<?php echo $BookNo; ?>">
when you click on submit button data will be receive by $_POST
I am creating a simple CRUD application that will be used as a blog. For the edit page, I want to have a dropdown menu with the blog titles of each post. When an option/blog post is selected, I want it to populate the "Title" and "Message" fields, so it can then be edited and saved to the database.
I got it to retrieve the titles of the blog posts, but I am struggling to make it populate the "Title" and "Message" fields so it can be edited when the option is selected.
I have 4 rows in my database: row[0] is the title, row[1] is the message, row[2] is the timestamp and row[3] is the ID.
Thanks guys. I appreciate it.
<form action="edit.php" id="myform" method="post" autocomplete=off>
<input type="hidden" name="action" value="show">
<p><label>Entry:</label><select name="blog">
<?php
$result = mysqli_query($con, "SELECT * FROM blog");
while ($row = mysqli_fetch_array($result)) {
$chosen = $row['bid'];
}
if (isset($_GET['blog'])) {
$id = $_GET['blog'];
$result = mysqli_query($con, "SELECT * FROM blog WHERE bid='$id'");
$row = mysqli_fetch_array($result);
}
$result = mysqli_query($con, "SELECT * FROM blog");
while ($row = mysqli_fetch_array($result)) {
$id = $row['bid'];
$title = $row['title'];
$selected = '';
if ($id == $chosen) {
$selected = "selected='selected'";
}
echo "<option value='$id' $selected>$title</option>\n";
}
?>
</select></p>
<p><label>Title:</label> <input type="text" id="newtitle" name="newtitle" value="<?php echo $row[0]; ?>"></p>
<p><label>Message:</label> <input type="text" id="newmessage" name="newmessage" value="<?php echo $row[1]; ?>"></p>
<p><input type="hidden" name="id" value="<?php echo $row[3]; ?>"></p>
<br><p><input type="submit" name="submit" value="Submit"></p>
</form>
I have managed to somewhat figure out the answer on my own. It's probably not the most ideal way of doing it, but for anyone else potentially stuck on this - here is my code:
The only issue I'm having now is figuring out how to keep my option selected.
<form action="edit.php" id="myform" method="post" autocomplete=off>
<input type="hidden" name="action" value="show">
<p><label>Entry:</label><select name="blog" onchange="window.location.href = blog.options[selectedIndex].value">
<option selected disabled>Select One</option>
<?php
$result = mysqli_query($con, "SELECT * FROM blog");
while ($row = mysqli_fetch_array($result)) {
$id = $row['bid'];
$title = $row['title'];
echo "<option value='edit.php?edit=$row[bid]'>$title</option>\n";
}
if (isset($_GET['edit'])) {
$id = $_GET['edit'];
$result = mysqli_query($con, "SELECT * FROM blog WHERE bid='$id'");
$row = mysqli_fetch_array($result);
}
?>
</select></p>
<p><label>Title:</label> <input type="text" id="newtitle" name="newtitle" value="<?php echo $row[0]; ?>"></p>
<p><label>Message:</label> <input type="text" id="newmessage" name="newmessage" value="<?php echo $row[1]; ?>"></p>
<p><input type="hidden" name="id" value="<?php echo $row[3]; ?>"></p>
<br><p><input type="submit" name="submit" value="Submit"></p>
</form>
I have this code in a loop in my code, The loop makes one submit button for every member found. I need each button to have the members name stored in it, in a way it can be sent though post when that button is clicked. Im not sure if this is possible with post but i was trying a way i do it with URLS. Does anyone know how to do this?
<input type="submit" value="Attack" name="Attack?name=<?php echo $Member_name; ?>" />
<?php
if(isset($_POST['Attack'])){
$sql = "SELECT * FROM users WHERE name='".mysql_real_escape_string($_GET['name'])."'";
$query = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_object($query);
}
Here is the whole code i was trying to store it in a hidden form but it only grabs the last member found and wont get others.
<?php
$sql = "SELECT name, rank FROM users ORDER BY rank DESC"; // Searches the database for every one who has being last active in the last 5 minute
$query = mysql_query($sql) or die(mysql_error());
$count = mysql_num_rows($query);
$i = 1;
while($row = mysql_fetch_object($query)) {
$Member_name = htmlspecialchars($row->name);
$Member_level = htmlspecialchars($row->rank);
?>
<td><?php echo $i; ?></td>
<td><?php echo $Member_name; ?></td><td><?php echo $Member_level; ?></td><td>
<input type="hidden" name="thename" value="<?php echo $Member_name; ?>">
<input type="submit" value="Attack" name="Attack" />
</td>
<?
if($i != $count) { // this counts the amount of people that are online and display the results.
echo "</tr><tr>";
}
$i++;
}
?>
<?php
if(isset($_POST['Attack'])){
$sql = "SELECT * FROM users WHERE name='".mysql_real_escape_string($_POST['thename'])."'";
$query = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_object($query);
$profile_id = htmlspecialchars($row->id);
$profile_userip = htmlspecialchars($row->userip);
$profile_name = htmlspecialchars($row->name);
$profile_money = htmlspecialchars($row->money);
$profile_gang = htmlspecialchars($row->gang);
$profile_exp = htmlspecialchars($row->exp);
$profile_profile = htmlspecialchars($row->profile);
$profile_rank = htmlspecialchars($row->rank);
$profile_health = htmlspecialchars($row->health);
$profile_defence = htmlspecialchars($row->defence);
$profile_stanima = htmlspecialchars($row->stanima);
?>
OK, assuming everything else is working ok, and you are retrieving data.
Change this:
<input type="hidden" name="thename" value="<?php echo $Member_name; ?>">
<input type="submit" value="Attack" name="Attack" />
To this:
<form method="POST" action="">
<input type="hidden" name="name" value="<?php echo $Member_name; ?>">
<input type="submit" value="Attack" name="Attack" />
</form>
And also in your PHP, change this line:
$sql = "SELECT * FROM users WHERE name='".mysql_real_escape_string($_GET['name'])."'";
To:
$sql = "SELECT * FROM users WHERE name='".mysql_real_escape_string($_POST ['name'])."'";
This isn't the best way to do this, you will be generating loads of HTML elements depending how many users you have, but it should solve you problem (providing everything else is working and receiving data).
HTML 5 & Javascript would be perfect for this and is something you should look into.
I am trying to update my products table using a product form but it is throwing an error for an undefined variable here is my code for the productform.php
<?php
$ProductID= $_GET['ProductID'];
//Connect and select a database
mysql_connect ("localhost", "root", "");
mysql_select_db("supplierdetails");
{
$result = mysql_query("SELECT * FROM products WHERE ProductID=$ProductID");
while($row = mysql_fetch_array($result))
{
$ProductID= $_GET['ProductID'];
$ProdDesc = $row['ProdDesc'];
$SupplierID = $row['SupplierID'];
$Location = $row['Location'];
$Cost = $row['Cost'];
$Status = $row['Status'];
$MRL = $row['MRL'];
$ProductID = $row['ProductID'];
}
?>
//form
<form action="Edit_Prod.php" method="post">
<input type="hidden" name="ProductID" value="<?php echo $ProductID; ?>"/>
<label>Product Description:
<span class="small">Please enter a description for the product </span>
</label>
<input type="text" name="ProdDesc" value="<?php echo $ProdDesc ;?>" />
<label>Supplier ID
<span class="small">Please enter the Supplier ID</span>
</label>
<input type="text" name="SupplierID" value="<?php echo $SupplierID ;?>" />
<label>Bay Location:
<span class="small">Please select the bay location for this product </span>
</label>
<select name="Location" value="<?php echo $Location ;?>" />
<option>A1</option>
<option>A2</option>
<option>A3</option>
<option>A4</option>
<option>A5</option>
<option>B1</option>
<option>B2</option>
<option>B3</option>
<option>B4</option>
<option>B5</option>
<option>C1</option>
<option>C2</option>
<option>C3</option>
<option>C4</option>
<option>C5</option>
<option>D1</option>
<option>D2</option>
<option>D3</option>
<option>D4</option>
<option>D5</option>
<option>E1</option>
<option>E2</option>
<option>E3</option>
<option>E4</option>
<option>E5</option>
</select>
<label>Product Cost:
<span class="small">Please enter a new cost for the product (per roll) </span>
</label>
<input type="text" name="Cost" value="<?php echo $Cost ;?>" />
<label>Status:
<span class="small">Please select a status for the product </span>
</label>
<select name="Status" value="<?php echo $Status ;?>" />
<option>Live</option>
<option>Mature</option>
<option>Obsolete</option>
</select>
<label>MRL
<span class="small">Please enter a minimum re-order level for this product </span>
</label>
<input type="text" name="MRL" value="<?php echo $MRL ;?>" />
<input type="submit" value= "Edit Product Details"/>
Undefined variable all lines, do i have to do anything differently if using drop down areas*
*Edit_Prod.php*
<?php
$con = mysql_connect("localhost", "root", "");
mysql_select_db("supplierdetails");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
//Run a query
$ProductID = $_POST['ProductID'];
$result = mysql_query ("SELECT * FROM products WHERE Productid= '".$Productid."'") or die(mysql_error());
$row = mysql_fetch_array($result);
$ProdDesc = $_POST['ProdDesc'];
$SupplierID = $_POST['SupplierID'];
$Location = $_POST['Location'];
$Cost = $_POST['Cost'];
$Status = $_POST['Status'];
$MRL = $_POST['MRL'];
$Productid=$row['Productid'];
$query="UPDATE products SET ProdDesc='".$ProdDesc."', SupplierID='".$SupplierID."', Location='".$Location."', Cost='".$Cost."', Status='".$Status."', MRL='".$MRL."' WHERE ProductID='".$ProductID."'";
$result = mysql_query($query);
//Check whether the query was successful or not
if($result)
{
echo "Products Updated";
header ("Location: Products.php");
}
else
{
die ("Query failed");
}
?>
i think $row vairable is used to get values from database which you have missed
$productID= $_GET['productid'];
$records =mysql_query(" select * from tableName where productid=$productID");
$row=mysql_fetch_array($records);
then your code will work
$supplId= $row['supplId'];
...
Answering to your question "do i have to do anything differently if using drop down areas", of course you have to change it. Change:
<select name="Location" value="<?php echo $Location ;?>" />
<option>A1</option>
<option>A2</option>
<option>A3</option>
<option>A4</option>
<option>A5</option>
.
.
. . .. .
To:
<select name="Location" />
<option value="<?=$Location;?>" selected="selected" ></option>
<option>A1</option>
<option>A2</option>
<option>A3</option>
<option>A4</option>
<option>A5</option>
like that. I think you got the idea. You have to get value as an option under select. Try it. Good luck.
I would like a change from the drop down to the checkbox, I want to change it because I want firstly select the list in the array can be selected before store to database via the checkbox, so the dropdown script was as follows
<?php
session_start();
define('DEFAULT_SOURCE','Site_A');
define('DEFAULT_VALUE',100);
define('DEFAULT_STC','BGS');
include('class/stockconvert_class.php');
$st = new st_exchange_conv(DEFAULT_SOURCE);
if(isset($_GET['reset'])) {
unset($_SESSION['selected']);
header("Location: ".basename($_SERVER['PHP_SELF']));
exit();
}
?>
<form action="do.php" method="post">
<label for="amount">Amount:</label>
<input type="input" name="amount" id="amount" value="1">
<select name="from">
<?php
$stocks = $st->stocks();
asort($stocks);
foreach($stocks as $key=>$stock)
{
if((isset($_SESSION['selected']) && strcmp($_SESSION['selected'],$key) == 0) || (!isset($_SESSION['selected']) && strcmp(DEFAULT_STC,$key) == 0))
{
?>
<option value="<?php echo $key; ?>" selected="selected"><?php echo $stock; ?></option>
<?php
}
else
{
?>
<option value="<?php echo $key; ?>"><?php echo $stock; ?></option>
<?php
}
}
?>
</select>
<input type="submit" name="submit" value="Convert">
</form>
and i Changed it to the checkbox as follows
<?php
session_start();
define('DEFAULT_SOURCE','Site_A');
define('DEFAULT_VALUE',100);
define('DEFAULT_STC','BGS');
include('class/stockconvert_class.php');
$st = new st_exchange_conv(DEFAULT_SOURCE);
if(isset($_GET['reset'])) {
unset($_SESSION['selected']);
header("Location: ".basename($_SERVER['PHP_SELF']));
exit();
}
?>
<form action="do.php" method="post">
<label for="amount">Amount:</label>
<input type="input" name="amount" id="amount" value="1"><input type="submit" name="submit" value="Convert">
<?php
$stocks = $st->stocks();
asort($stocks);
foreach($stocks as $key=>$stock)
{
if((isset($_SESSION['selected']) && strcmp($_SESSION['selected'],$key) == 0) || (!isset($_SESSION['selected']) && strcmp(DEFAULT_STC,$key) == 0))
{
?>
<br><input type="checkbox" id="scb1" name="from[]" value="<?php echo $key; ?>" checked="checked"><?php echo $stock; ?>
<?php
}
else
{
?>
<br><input type="checkbox" id="scb1" name="from[]" value="<?php echo $key; ?>"><?php echo $stock; ?>
<?php
}
}
?>
</form>
but does not work, am I need to display Other codes related?
Thanks if some one help, and appreciated it
UPDATED:
ok post the first apparently less obvious, so I will add the problem of error
the error is
Fatal error: Call to undefined method st_exchange_conv::convert() in C:\xampp\htdocs\test\do.php on line 21
line 21 is $st->convert($from,$key,$date);
session_start();
if(isset($_POST['submit']))
{
include('class/stockconvert_class.php');
$st = new st_exchange_conv(DEFAULT_SOURCE);
$from = mysql_real_escape_string(stripslashes($_POST['from']));
$value = floatval($_POST['amount']);
$date = date('Y-m-d H:i:s');
$_SESSION['selected'] = $from;
$stocks = $st->stocks();
asort($stocks);
foreach($stocks as $key=>$stock)
{
$st->convert($from,$key,$date);
$stc_price = $st->price($value);
$stock = mysql_real_escape_string(stripslashes($stock));
$count = "SELECT * FROM oc_stock WHERE stock = '$key'";
$result = mysql_query($count) or die(mysql_error());
$sql = '';
if(mysql_num_rows($result) == 1)
{
$sql = "UPDATE oc_stock SET stock_title = '$stock', stc_val = '$stc_price', date_updated = '$date' WHERE stock = '$key'";
}
else
{
$sql = "INSERT INTO oc_stock(stock_id,stock_title,stock,decimal_place,stc_val,date_updated) VALUES ('','$stock','$key','2',$stc_price,'$date')";
}
$result = mysql_query($sql) or die(mysql_error().'<br />'.$sql);
}
header("Location: index.php");
exit();
}
Why I want to change it from dropdown to checkbox?
because with via checkbox list I will be able to choose which ones I checked it was the entrance to the database, then it seem not simple to me, I looking for some help< thanks So much For You mate.
You have not removed the opening <select> tag.
But you removed the <submit> button.
You changed the name from "from" to "from[]".
EDIT: After your additions:
Using the dropdown list you were only able to select one value for from. Now you changed it to checkboxes and thus are able to select multiple entries. This results in receiving an array from[] in your script in do.php. Your functions there are not able to handle arrays or multiple selections in any way.
You have to re-design do.php, change your form back to a dropdown list or use ratio buttons instead.