when i edit data from form field it only select/fetch one word though form field has many words/ or complete sentence where is wrong?
<?php
//getting id from url
$id = $_GET['id'];
//selecting data associated with this particular id
$result = mysql_query("SELECT * FROM list WHERE id=$id");
while($res = mysql_fetch_array($result))
{
$Test_name = $res['Test_name'];
}
?>
<form name="form1" method="post" action="edit.php">
<table border="0">
<tr>
<td>Test Name</td>
<td><input type="text" name="Test_name" value=<?php echo
$Test_name;?>></td>
</tr>
<tr>
<td><input type="hidden" name="id" value=<?php echo
$_GET['id'];?>></td>
<td><input type="submit" name="update" value="Update"></td>
</tr
</table>
</form>
You can use TextArea for long value edit.
Hope below example will help you.
<form name="form1" method="post" action="edit.php">
<table border="0">
<tr>
<td>Test Name</td>
<td><textarea name="Test_name" value=<?php echo
$Test_name;?>><?php echo
$Test_name;?></textarea></td>
</tr>
<tr>
<td><input type="hidden" name="id" value=<?php echo
$_GET['id'];?>></td>
<td><input type="submit" name="update" value="Update"></td>
</tr
</table>
</form>
Try this.
Use textarea for long value edit.
<form name="form1" method="post" action="edit.php">
<table border="0">
<tr>
<td>Test Name</td>
<td><textarea name="Test_name" value=<?php echo
$Test_name;?>><?php echo
$Test_name;?></textarea></td>
</tr>
<tr>
<td><input type="hidden" name="id" value=<?php echo
$_GET['id'];?>></td>
<td><input type="submit" name="update" value="Update"></td>
</tr
</table>
</form>
Related
I have those codes that help to update and delete a row from a table:
html:
<table class="imagetable" cellpadding="3" cellspacing="1" width="400px" border="1">
<th>ID</th>
<th>Name</th>
<th>Informations</th>
<th>Actions</th>
<tr>
<td><input type="text" name="id" value="<?php echo $rows['id'] ?>"/></td>
<td><input type="text" name="med_name" value="<?php echo $rows['med_name'] ?>"/></td>
<td><input type="text" name="info" value="<?php echo $rows['info']?>"/></td>
<td>
<form action="update_del.php" method="post">
<input class="imgClass_update" type="submit" name="submit1" value="" />
<input class="imgClass_dell" type="submit" name="submit2" value=""/>
</form>
</td>
</tr>
<tr>
PHP:
<?php
require_once('../include/global.php');
$id=$_POST['id'];
if(isset($_POST['submit1']))
{
$name=$_POST['med_name'];
$info=$_POST['info'];
$sql = "UPDATE med SET med_name='$name',
info='$info'
WHERE id='$id'";
$result=mysqli_query($con,$sql) or die('Unable to execute query. '. mysqli_error($con));
if($result){
header("location:med.php");
}
else
{
header("location:update_false.php");
}
}
if(isset($_POST['submit2']))
{
$sql = "DELETE FROM med WHERE id='$id'";
$result=mysqli_query($con,$sql) or die('Unable to execute query. '. mysqli_error($con));
if(mysqli_affected_rows($con) == 1)
{
header("location:med.php");
}
else
{
header("location:update_false.php");
}
}
?>
Nothing is updated nor deleted. And no errors are shown. If someone could help me, I think the problem is too easy but can't see it where.
You are placing <form> tag at wrong place.
Therefore, your other elements: id, med_name and info are not children of form.
And they are not getting posted.
You should start <form> before table and end after table.
Corrected Code:
<form action="update_del.php" method="post">
<table class="imagetable" cellpadding="3" cellspacing="1" width="400px" border="1">
<tr>
<th>ID</th>
<th>Name</th>
<th>Informations</th>
<th>Actions</th>
</tr>
<tr>
<td><input type="text" name="id" value="<?php echo $rows['id'] ?>"/></td>
<td><input type="text" name="med_name" value="<?php echo $rows['med_name'] ?>"/></td>
<td><input type="text" name="info" value="<?php echo $rows['info']?>"/></td>
<td>
<input class="imgClass_update" type="submit" name="submit1" value="Update" />
<input class="imgClass_dell" type="submit" name="submit2" value="Delete"/>
</td>
</tr>
</table>
</form>
just do this -
<table class="imagetable" cellpadding="3" cellspacing="1" width="400px" border="1">
<form action="update_del.php" method="post">
<th>ID</th>
<th>Name</th>
<th>Informations</th>
<th>Actions</th>
<tr>
<td><input type="text" name="id" value="<?php echo $rows['id'] ?>"/></td>
<td><input type="text" name="med_name" value="<?php echo $rows['med_name'] ?>"/></td>
<td><input type="text" name="info" value="<?php echo $rows['info']?>"/></td>
<td>
<input class="imgClass_update" type="submit" name="submit1" value="" />
<input class="imgClass_dell" type="submit" name="submit2" value=""/>
</td>
</tr>
</form>
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>
Trying to print data from multiple submission, I want the names and roll numbers to get printed/passed to another form. These data will generated from several submissions. In the following code, only the last submission data is getting printed. Where am I going wrong.
`
<?php
$name[] = $_POST['name'];
$rollno[] = $_POST['rollno'];
$arrlength=count($name);
for($x=0;$x<$arrlength;$x++)
{
echo $name[$x]." - - - - - -".$rollno[$x] ;
echo "<br>";
}
?>
<form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td>Name</td>
<td><input type="text" name="name" id="textfield" /></td>
</tr>
<tr>
<td>Roll No.</td>
<td><input type="text" name="rollno" id="textfield2" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="button" id="button" value="Submit" /></td>
</tr>
</table>
</form>
`
Your input types are not array type. Use LIKE THIS
<input type="text" name="name[1]" id="textfield" />
<input type="text" name="name[2]" id="textfield" />
.
.
.
<input type="text" name="name[n]" id="textfield" />
IN PHP CODE
foreach( $_POST['name'] as $v ) {
echo $v;
}
figured it out. here is the revised code.
<?php
$name = $_POST['name'];
$rollno = $_POST['rollno'];
$arrlength=count($name);
for($x=0;$x<$arrlength;$x++)
{
echo $name[$x]."--".$rollno[$x] ;
echo "<br>";
}
?>
<form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td>Name</td>
<td><?php
$arrlength1=count($name);
for($x=0;$x<$arrlength1;$x++)
{
echo "<input type='hidden' name='name[]' value='$name[$x]' /> " ;
echo "<input type='hidden' name='rollno[]' value='$rollno[$x]' /> " ;
}
?>
<input type="text" name="name[]" id="textfield" /></td>
</tr>
<tr>
<td>Roll No.</td>
<td><input type="text" name="rollno[]" id="textfield2" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="button" id="button" value="Submit" /></td>
</tr>
</table>
</form>
My form is not submitting, My database insert class works and I have tested. But my form seems not to want to submit or post values from my form. Is there something I left out?
<form name="form1" method="post" action="sub_newsletter.php" enctype="multipart/form-data">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2">Newsletter</td>
</tr>
<tr>
<td>Name : </td>
<td><input name="name" type="text"></td>
</tr>
<tr>
<td>Email : </td>
<td><input name="email" type="text"></td>
</tr>
<tr>
<td> <input type="text" name="check_spam" id="check_spam" size="30" style="display:none;" /> </td>
<td> </td>
</tr>
<tr>
<td colspan="2" align="center"><input type="image" name="submit" src="images/sub.jpg" style="width:180px; height:70px;"></td>
</tr>
</form>
</table>
My submit script
<?php
include('includes/database.php');
include('includes/settings.php');
include('includes/newsletter.php');
if (isset($_POST['submit'])){
//to check if posting
echo $username=rtrim($_POST['name']);
echo $myemail=rtrim($_POST['email']);
//
$check=$_POST['check_spam'];
if(!empty($check)){ echo "You are spam"; } else{
$username=rtrim($_POST['name']);
$myemail=rtrim($_POST['email']);
$news = new Newsletter();
$new->first_name=$username;
$new->email=$myemail;
$new->create();
echo "<script>alert(\"Thank you for your subscription\"); </script>";
echo "<script>window.location.replace(\"index.html\"); </script>";
}
}
?>
You obviously missed submit button
<input type="submit" name="submit">
Since you have already a field with that name, just change it or use a different name.
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>