TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 01-10-2012, 12:55 PM   #1 (permalink)
The Visitor
Newcomer 
 
Join Date: Jan 2012
Posts: 1
Thanks: 0
ChrisGuru is on a distinguished road
Default PHP update script

Having trouble with this upload script, it grabs and displays the content from the database fine. It won't however update the database although the code is throwing up no errors;
this is the script that displays the content

PHP Code:
############### Code

<?php
include("includes/connection.php");

$sql="SELECT * FROM mot";
$result=mysql_query($sql);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<table width="400" border="1" cellspacing="0" cellpadding="3">
<tr>
<td colspan="4"><strong>List data from mysql </strong> </td>
</tr>

<tr>
<td align="center"><strong>Name</strong></td>
<td align="center"><strong>Lastname</strong></td>
<td align="center"><strong>Update</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><? echo $rows['header']; ?></td>
<td><? echo $rows['content']; ?></td>

// link to update.php and send value of id 
<td align="center"><a href="update_content.php?id=<? echo $rows['id']; ?>">update</a></td>
</tr>
<?php
}
?>
</table>
</td>
</tr>
</table>
<?php
mysql_close
();
?>
this next bit of code is the code that user updates the content;

PHP Code:
<?php 

include("includes/connection.php");

// get value of id that sent from address bar
$id=$_GET['id'];


// Retrieve data from database 
$sql="SELECT * FROM mot WHERE id='$id'";
$result=mysql_query($sql);

$rows=mysql_fetch_array($result);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<form name="form1" method="post" action="update_ac.php">
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>&nbsp;</td>
<td colspan="3"><strong>Update data in mysql</strong> </td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center"><strong>Name</strong></td>
<td align="center"><strong>Lastname</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="center"><input name="name" type="text" id="name" value="<? echo $rows['header']; ?>"></td>
<td align="center"><input name="lastname" type="text" id="lastname" value="<? echo $rows['content']; ?>" size="15"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>"></td>
<td align="center"><input type="submit" name="Submit" value="Submit"></td>
<td>&nbsp;</td>
</tr>
</table>
</td>
</form>
</tr>
</table>

<?

// close connection 
mysql_close();

?>
this final bit is the update code for the database which isnt working but not throwing up any errors

PHP Code:
<?php
 
include("includes/connection.php");

// If form button has been pressed then do the following 
if(isset($_POST['update'])){ 
// Get id of post 
$id $_GET['id'];

$header $_POST['header'];
$content $_POST['content'];
 
// update data in mysql database 
$sql="UPDATE mot SET header = '$header', content = '$content' WHERE id='$id'";
$result=mysql_query($sql);

// if successfully updated. 
if($result){
echo 
"Successful";
echo 
"<BR>";
echo 
"<a href='mot_edit.php'> View result</a>";
}

else {
echo 
"ERROR";
}
}
?>
Any help would be much appreciated
ChrisGuru is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Beginner Guide #1 Hershey Absolute Beginners 1 11-07-2011 10:42 PM
Part 2: Giving our Currency Conversion Script some Responsibility Wildhoney General 15 03-17-2009 01:53 PM
Basic php form update mysql script dp2 Absolute Beginners 3 03-11-2009 04:06 PM
Nginx Rewrite Causing Wrong Path for PHP Script stewart General 0 11-09-2008 12:32 AM


All times are GMT. The time now is 03:55 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design