473,800 Members | 2,367 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Update news entry

1 New Member
Hi, I was wondering if anyone could help me with this problem. Here is the case, I have a News database which you are able to view here:

http://lotrtw.com/news/index_.php

And users will be able to add/delete/edit. Ive worked out how to add and delete entries but Im stuck with the editing part, everytime when you click the Edit button after checking a box of the record you want to edit (and ofcourse changed the text inside the field) it gets the data from the last item you added instead of the text from the checked record. Can anyone help me so that it will take the information from the checked record.
Sorry if Im a bit vague, check out what happens here:

http://lotrtw.com/news/news_admin.php

News_del.php, where the delete and edit command get executed.

[PHP]<?php
$host="localhos t";
$user="xxx";
$pass="xxx";
$db="news_";

$connect = mysql_connect($ host, $user, $pass);
$dbselect = mysql_select_db ($db, $connect);
$query = "SELECT * FROM news ORDER BY id";
$result = mysql_query($qu ery);
$num_rows = mysql_num_rows( $result);

if(isset($_POST["del"]))
{
for($i=0;$i<$nu m_rows;$i++)
{
$cb = $_POST['cb'];
$delete_records = $cb[$i];
$sql = "DELETE FROM news WHERE ID=$delete_reco rds";
$result = mysql_query($sq l);
}
echo '<script language="javas cript">alert("D eletion succesful, returning to admin...")</script>';
echo "<META HTTP-EQUIV='Refresh' CONTENT='0; URL=news_admin. php'> ";
}
elseif(isset($_ POST["edit"]))
{
for($i=0;$i<$nu m_rows;$i++)
{
$cb = $_POST['cb'];
$edit_records = $cb[$i];
$title = $_POST['rows1'];
$sql = "UPDATE news SET title = '$title' WHERE id=$edit_record s";
$result = mysql_query($sq l);
}
echo '<script language="javas cript">alert("E dit succesful, returning to admin...")</script>';
echo "<META HTTP-EQUIV='Refresh' CONTENT='0; URL=news_admin. php'> ";
}
else
{
echo '<script language="javas cript">alert("E dit/deletion failed, returning to admin...")</script>';
}

mysql_close();
?>
[/PHP]


News_admin.php, where you select the records and input new data

[PHP]<?php
//$user_chk=$_POS T['user'];
//$pass_chk=$_POS T['pass'];

$user_test="xxx ";
$pass_test="xxx ";

$host="localhos t";
$user=$user_tes t;
$pass=$pass_tes t;
$db="news_";

$connect = mysql_connect($ host, $user, $pass);
$dbselect = mysql_select_db ($db, $connect);
$query = "SELECT * FROM news ORDER BY submitted";
$result = mysql_query($qu ery);

$submit=$_POST['submit'];

//if(($user_chk == $user_test) & ($pass_chk == $pass_test))
//{
echo "<iframe src='news_add.p hp' height='217' width='100%' scrolling='no' name='frame'>
</iframe>";
echo "<form action='submit. php' method='post'>
<input type='submit' name='submit' value='Refresh content' style='outline: solid'/>
</form>";

echo "<form action='news_de l.php' method='post'>" ;
echo ("<table border='1' width='100%' cellspacing='2' height='100'>") ;
echo "<tr border='0'><td colspan='6'><in put type='submit' name='del' value='Delete selected records' style='outline: solid'/>' '<input type='submit' name='edit' value='Edit selected records' style='outline: solid'/></td></tr>";
while($rows = mysql_fetch_row ($result))
{
echo ("<tr bgcolor='lightb lue'><td><input type='checkbox' name='cb[]' value='$rows[0]'></td><td><input type='text' name='rows1' value='$rows[1]'></td><td><input type='text' name='rows2' value='$rows[2]' size='100'></td><td><input type='text' name='rows3' value='$rows[3]'></td><td><input type='text' name='rows4' value='$rows[4]'></td><td><input type='text' name='rows5' value='$rows[5]'></td></tr>");
}
echo "</form>";
echo "</table>";
/*}
else
{
echo "Error: Return to login screen <a href='news_logi n.php'>here</a>.";
}*/

?>[/PHP]
Dec 4 '07 #1
1 2585
stepterr
157 New Member
Hi mac89,
I do something similar except I'm deleting a record from the database where the user has checked a box. I find doing a foreach is easier than a for loop for this kind of thing, at least that is my personal preference. So maybe seeing how I do it will help you.

This is within my form. I'm doing a while loop, like you are, to go through each record in the database.
[PHP]
echo '<td>Check to Delete this photo:';
echo '<input type="checkbox" name="delPhoto[]" value="' . $array['photoid'] . '" </td>';
[/PHP]

When the form is submitted:

[PHP]
if (!empty($_POST['delPhoto']))
{
foreach($_POST['delPhoto'] as $v)
{
$del_id = mysql_real_esca pe_string($v);
$sql = "DELETE FROM portfolio WHERE photoid ='$del_id'";
mysql_query($sq l);
}
} [/PHP]
Jan 2 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
3024
by: Guinness Mann | last post by:
I have a column in one of my tables that needs to have about half of its values updated. The data looks like this: A\B0andSomeVaryingStuff.mp3 I'd like to update it to: A\C-B0andSomeVaryingStuff.mp3
2
1994
by: Richard Cornford | last post by:
Anyone who has taken a look at the online FAQ today may have noticed that I have updated it. The majority of the changes are the updating of broken links and the implementation of that extensive suggestions for re-wording provided by Michael Winter. Other changes are listed below. Fore those interested, a zipped snapshot of the entire FAQ and notes, as it now is, is available at:- <URL:...
6
2430
by: Jeff Kowalczyk | last post by:
I need to adapt this an update statement to a general form that will iterate over multiple orderids for a given customerinvoiceid. My first concern is a form that will work for a given orderid, then an expanded version that will work on all orderids with a specific customerinvoiceid as a parameter. I'm sure appropriate joins will handle it, but I'm not making any headway, everything comes back with multiple tuple selected for update...
25
4077
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
31
2457
by: Lag | last post by:
Having a problem updating my database from a web page, through a submission form. Can anyone help? ----THIS IS MY CODE IN update.php----(user, pass, and database are typed in directly, I changed them here for securiy reasons :) ) <?php /*---CONNECT TO DATABASE---*/
6
5019
by: Dixie | last post by:
I have asked this question before, but I could not get the suggested solution work. So I will give more details this time. I have an append query that adds several hundred records to a table into a text field. Next to this text field is a separate Number (Single) field with a unique ID number for the entry. I want each number to be 1 more than the previous entry's number to keep it unique (I don't want autonumbering for this, as I...
5
2602
by: njb35 | last post by:
Hi all I'm beginning my foray from VBA into VB 2005 Express, and enjoying some of the efficiencies it provides! I'm stuck with some dataset handling however that I _think_ can be automated but I can probably code what I want to do the hard way. I've searching around online but can't find an answer to this specific question. Here's the situation: I have a dataset table with 3 fields: one indexed as a primary key and the other two...
5
1794
by: P.J.M. Beker | last post by:
Hi there, I'm currently writing a program in which I use the FileMonitor to monitor a folder in which I store downloaded images. I know that I can't add much coding in the filemonitor's event in risk of losing some new entries, so I've deceided to create an update thread. This thread is created when the program's start and should (for various reason) run not in sync with the Filemonitor. The Filemonitor event creates an entry in a...
4
3926
by: ahling | last post by:
Hi all. As mentioned in my first post, I'm currently doing an asp.net blog where user can update their profile, and update their blog entry. But I encountered problem with the update of entry part. When I tried to post a blog entry by hitting the 'Post' button, it brings me to a blank page which is supposed to show me the gridview that contains the Blog subject, title of the blog entry, date and the name of the poster itself. But what...
0
10505
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10276
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10253
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10035
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9090
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5471
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.