Current location: Hot Scripts Forums » Programming Languages » PHP » update command won't update...


update command won't update...

Reply
  #1 (permalink)  
Old 08-21-09, 11:43 PM
topsidemarketing topsidemarketing is offline
Newbie Coder
 
Join Date: Aug 2009
Posts: 23
Thanks: 4
Thanked 0 Times in 0 Posts
update command won't update...

Hi Guys,

This is probably a rookie mistake, so if you could help me debug this I'd appreciate it greatly.

A few points of info regarding what's below:
A) "connect.php" contains the database name, username and password. It works with all my other pages so it's probably not the problem.
B) The variables are being passed from an update form. The idea is to pull the data out of the database via the earlier form, examine and update it and pass the changes to the database with this script.
C) When the update form is submitted, there are no error messages returned, and the echo "Record updated now" appears on the screen. It just simply doesn't change the data in the database.
D) The table name "schools" is correct and works great in my other "insert" form. There are only 4 fields in the table - id, name, city and region.

I'm sure I've just overlooked something...any suggestions? *bangs head on monitor*

THANKS!!!!
****************code**************************
PHP Code:

<?php
include("connect.php");
  
$connection mysql_connect('localhost'$username$password) or die('Could not connect to database.<br />'.mysql_error());
  
mysql_select_db($database) or die('Could not select database.<br />'.mysql_error());
$ud_id$_POST['ud_id'];
$ud_name=$_POST['ud_name'];
$ud_city=$_POST['ud_city'];
$ud_region=$_POST['ud_region'];
$query"UPDATE schools SET name='$ud_name', city='$ud_city', region='$ud_region' WHERE id='$ud_id'";
$result=mysql_query($query);
echo 
"Record Updated Now";
mysql_close();
?>

Last edited by Nico; 08-22-09 at 03:27 AM.
Reply With Quote
  #2 (permalink)  
Old 08-22-09, 10:14 AM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
Does your username and password have permission to update tables in the database?
Reply With Quote
  #3 (permalink)  
Old 08-23-09, 01:23 PM
topsidemarketing topsidemarketing is offline
Newbie Coder
 
Join Date: Aug 2009
Posts: 23
Thanks: 4
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Jcbones View Post
Does your username and password have permission to update tables in the database?
Yes it does. Very valid question, but not the problem. Thanks for your response. Any other suggestions?
Reply With Quote
  #4 (permalink)  
Old 08-23-09, 01:35 PM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
You could add a:
PHP Code:

mysql_query($query) or die('Invalid query: ' mysql_error()); 

That might tell you what is wrong.
Reply With Quote
  #5 (permalink)  
Old 08-23-09, 05:14 PM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
You might want to show the form you're using also.
Reply With Quote
  #6 (permalink)  
Old 08-24-09, 10:46 AM
topsidemarketing topsidemarketing is offline
Newbie Coder
 
Join Date: Aug 2009
Posts: 23
Thanks: 4
Thanked 0 Times in 0 Posts
Hi guys,

I added the 'or die' you showed and there are still no error messages.

There are two forms involved in the process, so I will show both. First there is a search form to find the info out of the database. It appears to work fine, as it does pull the data out of the database and load it into a form for editing:

**********************code************************ ********
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form action="updateschoolname.php" method="POST" name="schoolnamesearch">
  Search by school name: 
  <input name="search" type="text" size="50" maxlength="50" /><input name="submit" type="submit" value="Submit" /></form>
</body>
</html>
********************end of code*******************************************

Then the editing form (named "updateschoolname.php) allows the user to change the data and passes that changed data to my original script (named "updated.php") to be updated in the database. Here is the editing form:

*****************************code***************** *******************

PHP Code:

<?
include("connect.php");
$search=$_POST['search'];
mysql_connect(localhost,$username,$password);
@
mysql_select_db($database) or die( "Unable to Select database");
$query="SELECT * FROM schools WHERE name='$search'";
$result=mysql_query($query);
$num=mysql_numrows($result); 
mysql_close();

$i=0;
while (
$i $num) {
$id=mysql_result($result,$i,"id");
$name=mysql_result($result,$i,"name");
$city=mysql_result($result,$i,"city");
$region=mysql_result($result,$i,"region");
?>
<form action="updated.php">
<input type="text" name="ud_id" value="<? echo "$id"?>">
School Name: <input type="text" size="35" name="ud_name" value="<? echo "$name"?>"><br>
City: <input type="text" name="ud_city" value="<? echo "$city"?>"><br>
Region: <input type="text" name="ud_region" value="<? echo "$region"?>"><br>
<input type="Submit" value="Update">
</form>

<?
++$i;

?>
***************************end of code************************************

There HAS to be something I'm missing here. As I said, everything APPEARS to run just fine - there are no error messages returned anywhere - but the data in the database doesn't change.

I really appreciate any help anyone here can offer. Thanks so much!

Last edited by Nico; 08-24-09 at 12:49 PM.
Reply With Quote
  #7 (permalink)  
Old 08-24-09, 02:09 PM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
Try your "updated.php" file like this ....

PHP Code:

 
include("connect.php");
  
$connection mysql_connect('localhost'$username$password) or die('Could not connect[IMG]http://kona.kontera.com/javascript/lib/imgs/grey_loader.gif[/IMG] to database.<br />'.mysql_error());
  
mysql_select_db($database) or die('Could not select database.<br />'.mysql_error());
$ud_id$_POST['ud_id'];
$ud_name=$_POST['ud_name'];
$ud_city=$_POST['ud_city'];
$ud_region=$_POST['ud_region'];
$query"UPDATE schools SET name='$ud_name', city='$ud_city', region='$ud_region' WHERE id='$ud_id'";
$result=mysql_query($query);
echo 
"Record Updated Now<br/><br/>
ID = 
$ud_id<br/>
Name = 
$ud_name<br/>
City = 
$ud_city<br/>
Region = 
$ud_region
"
;
mysql_close(); 
See if the actual values from the form display.
Reply With Quote
  #8 (permalink)  
Old 08-25-09, 09:41 AM
topsidemarketing topsidemarketing is offline
Newbie Coder
 
Join Date: Aug 2009
Posts: 23
Thanks: 4
Thanked 0 Times in 0 Posts
Hey guys.

I just fixed this problem....after mdhall asked me to post the form code, I was looking at it from a new perspective and noticed there was no method defined in the form tag that called "updated.php" (if you look above you will notice this right away if you know to look for it). Hence the forms and scripts were working fine but it wouldn't update because no data was actually being passed via POST but the script was looking for POSTed data. Thanks for your help, it got me thinking on the right path instead of wondering what was wrong with the last .php script. Appreciate it!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
IE6 Bug? My center column drops to footer position goatchaps CSS 5 08-31-07 12:15 PM
Update multiple rows outside loop - need help ElvansX PHP 1 12-03-06 01:55 AM
Update: I can't update multi data into DB ahlai Database 4 08-10-06 12:55 PM
Problem with a mysql table update lppa2004 PHP 2 12-24-05 05:11 AM
need help creating an update page within admin mikewooten PHP 2 11-01-04 10:39 PM


All times are GMT -5. The time now is 07:58 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.