MySql php data display in tables - php

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>

Related

How to edit data from form field?

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>

Update profile using session PHP MySQL

I'm doing project in eCommerce website using PHP and MySQL. I'm having a problem updating user profile page - when I click update button then I check the database, nothing is changed. These is my update.php.
<?php
session_start();
if(!isset($_SESSION["n"]))
{
header("location:error.php");
}
if(isset($_POST["submit"]))
{
$nm=$_POST["name"];
$lnm=$_POST["lname"];
$ad=$_POST["add"];
$u=$_SESSION["un"];
$id=$_GET["id"];
require_once("vars.php");
$conn=mysqli_connect(host,uname,pass,db) or die(mysqli_connect_error());
$query="update signup set name='$nm', lname='$lnm', address='$ad' where User_ID='$id' ";
$execute=mysqli_query($conn,$query);$r=mysql_affected_rows();
mysqli_close($conn);
if(!$execute)
{
$msg="Information Updated Successfully";
}
header("location:mydetails.php");
}
?>
<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Untitled Document</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
</head>
<body>
<table width="950" align="center">
<tr>
<td>
<table cellspacing="0" cellpadding="0" width="100%">
<tr align="right">
<td>Welcome
<?php
if(isset($_SESSION["n"]))
{
print $_SESSION["n"];
print " <a href='myprofile.php'>My Profile</a>";
print " <a href='signout.php'>Log Out</a>";
}
else
{
print "Guest ";
print "<a href='signup.php'>Sign up</a> ";
print "<a href='login.php'>Login</a>";
}
?></td>
</tr>
<tr>
<td><img src="pics/new2.JPG" alt="banner" width="950" height="234" /></td>
</tr>
<tr align="center">
<td height="58"><table width="100%">
<tr align="center">
<td width="158" bgcolor="#f9b67b"><font color="#FFFFFF">Home</font></td>
<td width="158" bgcolor="#f9b67b" ><font color="#FFFFFF">About us</font></td>
<td width="158" bgcolor="#f9b67b"><font color="#FFFFFF">Products</font></td>
<td width="158" bgcolor="#f9b67b"><font color="#FFFFFF">Search</font></td>
<td width="158" bgcolor="#f9b67b"><font color="#FFFFFF">Contact us</font></td>
</tr>
<tr align="center">
<td colspan="6" align="left"><!-- InstanceBeginEditable name="EditRegion3" -->
<table width="100%">
<tr>
<td><form id="form1" name="form1" method="post" action="">
<table width="100%">
<tr>
<td><h2><strong>Update My Information</strong></h2></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<tr>
</label></td>
</tr>
<tr>
<td><strong>Name:</strong></td>
<td><label>
<input type="text" name="name" id="name" />
</label></td>
</tr>
<tr>
<td><strong>Last name:</strong></td>
<td><label>
<input type="text" name="lname" id="lname" />
</label></td>
</tr>
<tr>
<td><strong>Address:</strong></td>
<td><label>
<input type="text" name="ad" id="ad" />
</label></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><label>
<input type="submit" name="submit" id="submit" value="Update" />
<input type="reset" name="reset" id="reset" value="Reset" /></td>
</label></td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
<!-- InstanceEndEditable --></td>
</tr>
</table></td>
</tr>
</table>
</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</body>
<div id="footer" >
<h4 style="text-align:center">©2016 by www.thebeautyskin.com</h4>
</div>
<!-- InstanceEnd --></html>
</div>
update signup set name='$nm', lname='$lname', address='$ad'
Where are variables $nm and $ad defined? I see $name and $address....

SQL not updating Row

I have tried to get this working for a couple hours now, i think its related to the fact that i have a $_GET['ID']; on the first script but im not sure:
Script 1 (FORM):
<?php
require_once('db_access.php');
$editID = $_GET['id'];
$query = mysql_query("SELECT * from routes where id = '".$editID."'");
$row = mysql_fetch_assoc($query);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Form Edit Data</title>
</head>
<body>
<table border=1>
<tr>
<td align=center>Route Edit Data</td>
</tr>
<tr>
<td>
<table>
<form method="post" action="complete_edit.php">
<tr>
<td>ID #</td>
<td>
<input type="hidden" name="formid" value="<?php echo $row['id'] ?>">
</td>
</tr>
<tr>
<td>Route Name</td>
<td>
<input type="text" name="route_title" size="40"
value="<?php echo $row['route_title']?>">
</td>
</tr>
<tr>
<td>Total Price</td>
<td>
<input type="text" name="total_price" size="40"
value="<?php echo $row['total_price']?>">
</td>
</tr>
<tr>
<td>Down Payment</td>
<td>
<input type="text" name="down_payment" size="40"
value="<?php echo $row['down_payment']?>">
</td>
</tr>
<tr>
<td>Weekly Net</td>
<td>
<input type="text" name="weekly_net" size="40"
value="<?php echo $row['weekly_net']?>">
</td>
</tr>
<tr>
<td>Location</td>
<td>
<input type="text" name="location" size="40"
value="<?php echo $row['location']?>">
</td>
</tr>
<tr>
<td>Remarks</td>
<td>
<input type="text" name="remarks" size="40"
value="<?php echo $row['remarks']?>">
</td>
</tr>
<tr>
<td align="right">
<input type="submit"
name="submit value" value="Edit">
</td>
</tr>
</form>
</table>
</td>
</tr>
</table>
</body>
</html>
SCRIPT 2(PROCESSING):
<?php
$id = $_POSt['formid'];
$editroute = $_POST['route_title'];
$editprice = $_POST['total_price'];
$editdownpay = $_POST['down_payment'];
$editweeklynet = $_POST['weekly_net'];
$editlocation = $_POST['location'];
$editremarks = $_POST['remarks'];
$query = "UPDATE routes SET id = '$id', route_title = '$editroute', total_price = '$editprice', down_payment = '$editdownpay', weekly_net = '$editweeklynet', location = '$editlocation', remarks = '$editremarks' WHERE id = '$id'";
header('Location:index.php');
?>
The first lot of code is where my form is placed and the second is where the processing happens
Thanks for your help people :)
Alex
$id = $_POSt['formid'];
$_POSt is not $_POST
Im so silly after reading the comments to the question here i realised that i had no mysql_query string :)
Thanks guys for giving me my mind haha :)
Alex

Update failed after edit the data [no error]

I have made a edit form...but when i press the edit button..it works...when after complete the edit if i press the update button...it goes to main page but no field updated.
edit.page
<body>
<table align="center">
<tr>
<td align="center">Edit data</td>
</tr>
<tr>
<td>
<table border="2">
<th>SL</th>
<th>name</th>
<th>address</th>
<th>action</th>
<?php
include"dbc.php";//database conncetion
$order = "select * from tbl_record";
$result = mysqli_query($con,$order);
while ($row=mysqli_fetch_array($result)){
echo ("<tr><td>$row[employees_number]</td>");
echo ("<td>$row[name]</td>");
echo ("<td>$row[address]</td>");
echo ("<td>Edit</td></tr>");
}
mysqli_close($con);
?>
</table>
</td>
</tr>
</table>
</body>
</html>
edit form
<body>
<table border=2>
<tr>
<td align=center>Form Edit Employees Data</td>
</tr>
<tr>
<td>
<table border="1">
<?php
include "dbc.php";//database connection
$id = $_GET["id"];
$order = "SELECT * FROM tbl_record where employees_number='$id'";
$result = mysqli_query($con,$order);
$row = mysqli_fetch_array($result);
?>
<form method="post" action="edit_data.php">
<input type="hidden" name="id" value="<?php echo "$row[employees_number]"?>">
<tr>
<td>Name</td>
<td>
<input type="text" name="name"
size="20" value="<?php echo "$row[name]"?>">
</td>
</tr>
<tr>
<td>Address</td>
<td>
<input type="text" name="address" size="40"
value="<?php echo "$row[address]"?>">
</td>
</tr>
<tr>
<td align="right">
<input type="submit"
name="submit value" value="Edit">
</td>
</tr>
</form>
</table>
</td>
</tr>
</table>
</body>
update page
<?php
//edit_data.php
include "dbc.php";
if (isset($_POST['submit']))
{
$id = $_GET['id'];
$name = $_POST["name"];
$address = $_POST["address"];
mysqli_query("UPDATE tbl_record SET name='$name', address='$address' WHERE employees_number='$id'")
or die(mysqli_error());
}
header("location:edit.php");
?>
As per your comment "i am getting this error now mysqli_query() expects at least 2 parameters, 1 given ...for update page"
Add your connection parameter to the query:
mysqli_query("UPDATE
to that it reads as
mysqli_query($con, "UPDATE ...
Plus, your submit button should read as:
<input type="submit" name="submit" value="Edit">
The name="submit value" in it now, doesn't match the conditional statement for it
if (isset($_POST['submit']))

How to paste dummy text from 1 site to my own using PHP and MySQL?

When I'm pasting dummy text from any website to my textarea it is not saving into MySQL server but sometimes it works correctly. I don't know why it is happening.
Here is my code:
<table align="center" border="10">
<form method="post" action="insert.php" enctype="multipart/form-data">
<tr>
<td>News Title</td>
<td><input type="text" name="title" /></td>
</tr>
<tr>
<td>Select Category</td>
<td>
<select name="cat">
<option>Select Your category</option>
<?php
include('db.php');
$query="select * from nav";
$run=mysql_query($query);
while($row=mysql_fetch_array($run)){
$m_id=$row[0];
$m_title=$row['m_title'];
echo "<option value='$m_id'>$m_title</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td>News Image</td>
<td><input type="file" name="news_image" /></td>
</tr>
<tr>
<td>News Description</td>
<td><textarea cols="40" rows="10" name="desc"></textarea></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="btn" value="Insert News"/> </td>
</tr>
</form>
</table>`
<?php
if(isset($_POST['btn'])){
$news_title=$_POST['title'];
$news_cat=$_POST['cat'];
$news_desc=$_POST['desc'];
$news_image=$_FILES['news_image']['name'];
$tmp_image=$_FILES['news_image']['tmp_name'];
if($news_title=='' || $news_cat=='' || $news_desc==''){
echo "<script>alert('Any of your field is Empty')</script>";
exit();
}
else{
move_uploaded_file($tmp_image,"../images/$news_image");
$insert_query="insert into pages(cat_id,page_title,news_image,page_desc) VALUES ('$news_cat','$news_title','$news_image','$news_desc')";
$insert_run=mysql_query($insert_query);
echo "<script>alert('News Inserted...!!!')</script>";
}
}
?>`
You need to escape the input data in case it contains quote characters.
$news_title=mysql_real_escape_string($_POST['title']);
$news_cat=mysql_real_escape_string($_POST['cat']);
$news_desc=mysql_real_escape_string($_POST['desc']);
$news_image=mysql_real_escape_string($_FILES['news_image']['name']);
It would be better if you switched form the deprecated mysql extension to PDO or mysqli, and used prepared statements.

Categories