i want to display the name based on previous selection of group name commerce.
i hard code the first option and want to select the data based on previous one
iam still confused how to do this... kindly guide me
`<form action="" method="post">
<table width="39%" height="67" border="0" align="center">
<tr>
<td width="22%" height="27">Group</td>
<td width="33%"><select name="option">
<option>Commerce</option>
<option>Computer</option>
<option>Pre-engineering</option>
<option>Pre-Medical</option>
</select>
</td>
<td width="8%">Name</td>
<td width="37%">
<? if ($option=='Pre-engineering')
$sql = mysql_query("SELECT name FROM std_reg where faculty='$option'") or die(mysql_error());
while($row = mysql_fetch_array($sql)){
echo "<option>".$row[name]."</option>";}
?>
</td>
<td width="8%">Class</td>
<td width="37%"><input name="class" /></td>
</tr>
<tr>
<td height="34" colspan="4"><strong><h3>
<input type="submit" name="submit" value="SEARCH" />
</h3></strong></td>
</tr>
<br />
<br />
'
Fix the key here
echo "<option>".$row['name']."</option>";}
Related
I am doing a simple set of PHP scripts to edit and return MySQL records from a web site.
Everything works fine but there is a cosmetic that I just cannot seem to correct.
I presume being very rusty I am missing something obvious - I have tried everything I can think of though.
The content of field ADDTEXT can be fairly large and i would like to word wrap it all into the table cell. This script truncates it when a single line length is exceeded.
And yes I know I should be using mysqli_... but I am deaeling with that !
<html>
<head>
<title>Form Edit Data</title>
</head>
<body>
<table border=1>
<tr>
<td align=center>EDIT NEWS ITEM</td>
</tr>
<tr>
<td>
<table style="width:100%">
<tr>
<?
$id=$_GET['id'];
include "D***************.uk\public_html\html\ConnectDB.php";//database connection
$order = "SELECT * FROM st¬¬¬¬¬¬¬ where TYPE = '".$id."'";
$result = mysql_query($order);
$row = mysql_fetch_array($result);
?>
<form method="post" action="edit_data.php">
<input type="hidden" name="id" value="<? echo "$row[TITLE]"?>">
<tr>
<td>Item Title</td>
<td>
<input type="text" name="title"
value="<? echo "$row[TITLE]"?>">
</td>
</tr>
<tr>
<td>Item Text</td>
<td>
<input type="text" name="text"
value="<? echo "$row[ADDTEXT]"?>">
</td>
</tr>
<tr>
<td align="right">
<input type="submit"
name="submit value" value="Edit">
</td>
</tr>
</form>
</table>
</td>
</tr>
</table>
</body>
Change it to textarea field.
<textarea name="text"><?php echo $row['ADDTEXT'];?></textarea>
Try it
<html>
<head>
<title>Form Edit Data</title>
</head>
<body>
<table border=1>
<tr>
<td align=center>EDIT NEWS ITEM</td>
</tr>
<tr>
<td>
<table style="width:100%">
<tr><td>
<?
$id=$_GET['id'];
include "D***************.uk\public_html\html\ConnectDB.php";//database connection
$order = "SELECT * FROM st¬¬¬¬¬¬¬ where TYPE = '".$id."'";
$result = mysql_query($order);
$row = mysql_fetch_array($result);
?>
<form method="post" action="edit_data.php">
<input type="hidden" name="id" value="<?php echo $row['TITLE']?>">
<tr>
<td>Item Title</td>
<td>
<input type="text" name="title"
value="<?php echo $row['TITLE']?>">
</td>
</tr>
<tr>
<td>Item Text</td>
<td>
<input type="text" name="text"
value="<?php echo $row['ADDTEXT']?>">
</td>
</tr>
<tr>
<td align="right">
<input type="submit"
name="submit value" value="Edit">
</td>
</tr>
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
I have retrieved data from my table and displayed them using the code below.
<?php require_once('../Connections/bidco.php'); ?>
<body>
<table width="671" height="43" border="1" align="center">
<table width="781" height="190" align="center">
<tr>
<td height="61" colspan="4"><div align="center"><strong> Inventory </strong></div></td>
</tr>
<tr>
<td width="77" height="68"><strong>ID</strong></td>
<td width="152"><strong>Item name.</strong> </td>
<td width="253"><strong>unit price</strong> </td>
<td width="253"><strong>Update price</strong></td>
</tr>
<?php
$query=mysql_query("SELECT *FROM manuf ") or die (mysql_error());
while($row=mysql_fetch_array($query))
{
$id=$row['id'];
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['itemname']; ?></td>
<td><?php echo $row['unitprice']; ?></td>
<td>change</td>
</tr>
<?php
}
?>
</table>
</body>
</html>
Now this PHP code is supposed to allow me to edit individual rows that have been displayed when i click on 'change' but it it not selecting the row. Any ideas how to solve this?
<?php require_once('../Connections/bidco.php'); ?>
<?php
$id = isset($_GET['id']) ? $_GET['id'] : null;
$query=mysql_query("SELECT * FROM manuf where id='$id' ")or die(mysql_error());
$row=mysql_fetch_array($query);
?>
<form action="updateprice.php" method="post" enctype="multipart/form-data">
<table align="center">
<tr>
<td> <label><strong>Item Name</strong></label></td>
<td> <input type='text' name='itemname' value=" <?php echo $row['itemname']; ?>" />
<input type="hidden" name="id" value="<?php echo $id; ?> " /> <br /></td>
</tr>
<tr>
<td><label><strong>Unit price </strong></label></td>
<td> <input type="text" name="unitprice" value="<?php echo $row['unitprice']; ?> " /><br /></td>
</tr>
<tr>
<td>
<input type="reset" name="Reset" value="CANCEL" />
<br></td>
<td>
<input type="submit" name="Submit2" value="Update" /> </td>
</tr>
</table>
</form>
</body>
</html>
Thank you in advance
Your forget to add you id to your link
<td>change</td>
I think you need
<a href="change.php?id=$row['id']">
Edit - use Arif_suhail_123's answer - I did not notice you have PHP mixed in with HTML
You need to pass rowid to href of Edit Link.
<td>change</td>
You are looking for id in change.php, but you are not sending that in the header. You must change change with
change
Also, I suggest you STOP using mysql_* commands, since the are Depreceted, and will no longer be supported. Use mysqli_* commands instead.
I have this PHP/HTML Code:
<form method="post" action="create_quote2.php">
<table width="800" border="0" cellspacing="5" cellpadding="5">
<tr>
<td><strong>Select</strong></td>
<td><strong>Image</strong></td>
<td><strong>Name</strong></td>
<td><strong>Sale Price</strong></td>
<td><strong>Quantity</strong></td>
</tr>
<?php
$sql="SELECT * from products ";
$rs=mysql_query($sql,$conn) or die(mysql_error());
$counter=0;
while($result=mysql_fetch_array($rs))
{
$counter++;
echo '<input type="hidden" name="product'.$counter.'" value="'.$_POST["checkbox$i"].'" />';
echo '<tr>
<td><input type="checkbox" value="'.$result["sequence"].'" name="checkbox'.$counter.'" /></td>
<td>Image</td>
<td>'.$result["title"].'</td>
<td>£'.$result["saleprice"].'</td>
<td><input type="text" name="qty" id="qty" size="20" /></td>
</tr>';
}
echo '<input type="hidden" name="counter" value="'.$counter.'" />';
?>
</table>
<input type="submit" name="submit" value="Next" />
</form>
so when boxes are checked you go to the next page with this code:
<table width="800" border="0" cellspacing="5" cellpadding="5">
<tr>
<td><strong>Image</strong></td>
<td><strong>Title</strong></td>
<td><strong>Sale Price</strong></td>
<td><strong>Trade Price</strong></td>
<td><strong>Quantity</strong></td>
<td><strong>Total Cost</strong></td>
</tr>
<?php
for($i=1; $i<=$_POST["counter"]; $i++)
{
if($_POST["checkbox$i"])
{
$counter++;
$sql="SELECT * from products where sequence = '".$i."' ";
$rs=mysql_query($sql,$conn) or die(mysql_error());
$result=mysql_fetch_array($rs);
echo '<tr>
<td>Image</td>
<td>'.$result["title"].'</td>
<td>£'.$result["saleprice"].'</td>
<td>£'.$result["tradeprice"].'</td>
<td> </td>
<td> </td>
</tr>';
}
}
?>
</table>
it works fine and selects all the correct products from the products table but i need a way to get the posted quantity values for each row.
how can i display the posted quantity values on the second page?
P.S. im not worried about SQL injection on this code...
Use <input type="text" name="qty'.$counter.'" id="qty'.$counter.'" size="20" /> on the first page
Then $_POST["qty{$counter}"] or $_POST['qty'.$i] in the relevant cell
As a side note, you may find it easier to use a HEREDOC structure so that you don't have to keep on adding quote marks to echo stuff:
echo <<<BLOCK
<tr>
<td>Image</td>
<td>{$result["title"]}</td>
<td>£{$result["saleprice"]}</td>
<td>£{$result["tradeprice"]}</td>
<td>Quantity - {$_POST['qty'.$i]}</td>
<td> </td>
</tr>
BLOCK;
I found HEREDOC a great help as the quote marks don't blend into one another so much
To get your quantities just change:
<input type="text" name="qty" id="qty" size="20" />
to
<input type="text" name="qty'.$counter.'" id="qty" size="20" />
and then reference the same way you do for other inputs.
I have the following page with an option box, when the user selects the following options and then clicks submit, it takes them to the relevant url. However the user must type the correct string in the box which matches a simple static captcha image which is on the screen.
Currently the code looks like this, however i need help setting the condition so that "abcdef" must be typed in the box before it is submitted otherwise giving an error.
<?php
// Check to see if the form has been submitted.
if(isset($_POST['menu1'])) {
// If the form has been submitted, force a re-direct to the choice selected.
header('Location: ' . $_POST['menu1']);
}
?>
<div style="padding-left: 50px">
<p class="arial"><strong></strong><br /><br /></p>
<form method="post">
<table class="freecontact2form" border="0" width="400px">
<tbody>
<tr>
<td colspan="2"><span style="font-size: x-small;"> </span> <font color=#000000 ></font>
<br /><br /></td>
</tr>
<tr>
<td valign="top"><table width="400px" class="freecontact2form">
<tr>
<td colspan="2"><br />
<br />
<div class="freecontact2formmessage"> </div></td>
</tr>
<tr>
<td valign="top"><label for="menu1" >These are the following options:<span class="required_star"> </span></label></td>
<td valign="top"><select name="menu1" id="menu1">
<option selected="selected" value ="http://www.google.com">Google </option>
<option value ="www.msn.com">MSN</option>
<option value ="www.youtube.com">Youtube</option>
<option value ="bing.com">Bing</option>
</select></td>
</tr>
<tr>
<td valign="top"><label for="captcha" ><span class="required_star"></span><span class="required_star"></span></label></td>
<td valign="top"><BR /><BR /><img src="captcha.jpg" /></td>
</tr>
<tr>
<td>Please enter the characters shown in the CAPTCHA image:</td>
<td><input type="text" name="captcha" id="captcha" value="" size="10" />
</td>
</tr>
<tr>
<td style="text-align:center" colspan="2"><br /><br />
<input type="submit" value=" Submit ">
</td>
</tr>
</table></td>
<td valign="top"> </td>
</tr>
<tr>
</tr>
<tr>
</tr>
</tbody>
</table>
</form> <br />
<p> </p>
<p> </p>
Save the code in a session when you first display the page. Then check the POST value of the code field against the session variable.
session_start();
$_SESSION['captcha'] = 'abcdef';
On form submission:
session_start();
if($_POST['captcha'] == $_SESSION['captcha'] && isset($_POST['menu1'])){
header();
}
i have a little problem here. What i am trying to achieve is User types in unique id into textbox then presses load button, script is looking for this parameter in MySql database. When found match data should be loaded into textbox below.
UPDATED VERSION
<?php
mysql_connect ("localhost", "root","84946dff6e1") or die (mysql_error());
mysql_select_db ("employees");
if(isset($_POST["loadbtn"]))
{
$load = $_POST["loadbtn"];
$sql = mysql_query("SELECT * FROM titles WHERE emp_no = '$load' ");
$details = mysql_fetch_array($sql);
$savedTitle = $details["title"];
}
?>
<form method="post" action="changeTitleView.php">
<table width="400" border="0" cellspacing="1" cellpadding="2" align="center">
<tr>
<td width="150">Employee number</td>
<td><input type="text" name="load" /></td>
<td><input type="submit" name="loadbtn" value="Load" /></td>
</tr>
</table>
</form>
<br />
<br />
<form method="get" action="changeTitleView.php">
<table width="400" border="0" cellspacing="1" cellpadding="2" align="center">
<td width="150">Employee Title</td>
<td><input name="salary" type="text" value="<?php echo $savedTitle; ?>"></td>
</tr>
<td width="150"> </td>
<td>
<input name="add" type="submit" id="add" value="Update">
</td>
</tr>
</table>
</form>
thank you for looking and help :)
Try this
<?php
error_reporting(-1);// show all errors when debugging
// don't use these database commands
//mysql_connect ("localhost", "root","84946dff6e1") or die (mysql_error());
//mysql_select_db ("employees");
// do it this way and don't show us your database credentials.
$conn = new mysqli('localhost', "root", "84946dff6e1", 'employees');
//declare your variables so if POST isn't true you don't have errors later
$load = "some Id";
$savedTitle = "no value yet!"; // use something interesting when testing
//you want the value of the textbox which name is load
if(isset($_POST["load"]))
{
//never trust the user directly
//$load = $_POST["load"];
// do this
$load = $conn->real_escape_string($_POST["load"]);
$result = $conn->query("SELECT * FROM titles WHERE emp_no = '$load' ");
$details = $result->fetch_assoc();
$savedTitle = $details["title"];
// show me error when testing to see if something is wrong with query
echo $conn->error;
}
?>
<form method="post" action="changeTitleView.php">
<table width="400" border="0" cellspacing="1" cellpadding="2" align="center">
<tr>
<td width="150">Employee number</td>
<td><input type="text" name="load" value="<?php echo $load; ?>" /></td>
<td><input type="submit" name="loadbtn" value="Load" /></td>
</tr>
</table>
</form>
<br />
<br />
<form method="get" action="changeTitleView.php">
<table width="400" border="0" cellspacing="1" cellpadding="2" align="center">
<td width="150">Employee Title</td>
<td><input name="salary" type="text" value="<?php echo $savedTitle; ?>"></td>
</tr>
<td width="150"> </td>
<td>
<input name="add" type="submit" id="add" value="Update">
</td>
</tr>
</table>
</form>
You will want to add another if branch to handle the second form which updates the title
And remember that form is GET instead of POST like the first form.
<td><input name="salary" type="text" value="<? echo $empTitle; ?>"></td>
try change that line to this:
<td><input name="salary" type="text" value="<?php echo $empTitle; ?>"></td>