You are here: Re: Update query issue... « PHP Programming Language « IT news, forums, messages
Re: Update query issue...

Posted by Joshua Ruppert on 12/17/29 11:55

ZafT wrote:
> Hi all - thanks in advance for any help.
>
> I am trying to write a simple update script. In fact, I am re-using code
> that I've used before (successfully) but I can't figure out why it is not
> working. The script completes without any errors, but does not actually
> update the database.
>
> Also, the "check for same name" query works fine, and will return the proper
> error if a duplicate is found.
>
> Thanks again!
> Shane
>
> Here is the code - pretty simple...
>
> <?PHP
> require('header.php');
> require('config.php');
>
> mysql_connect($dbserver,$username,$password)
> or die( "Unable to connect");
> @mysql_select_db($database)
> or die( "Unable to select database");
>
> $id=$_POST['id'];
> $name=$_POST['name'];
> $description=$_POST['description'];
> $show=$_POST['show'];
>
> ?>
>
> <TABLE width=500 cellpadding="15">
> <TR>
> <TD>
>
> <H1><font face="verdana">Edit Project</H1>
> <font face="verdana">
>
> <?php
>
> echo "$id <BR>";
> echo "$name <BR>";
> echo "$description <BR>";
> echo "$show <BR>";
>
> $query="SELECT * FROM project WHERE name = '$name'";
> $result=mysql_query($query);
> $num=mysql_numrows($result);
>
> //echo $num;
>
> //Check to see if there is already a project with the name
> //we are trying to change to. Ignore if the id is the same
> //since this just means there was no name change.
>
> if($num > 0){
> $conflictid=mysql_result($result,0,"id");
> if(!($id==$conflictid)){
> die("Error: There is already a project with that
> name in the database. Please try again.");
> }
> else{
>
> $query="UPDATE project SET name='$name',
> description='$description',
> show='$show'
> WHERE id=$id";
> mysql_query($query);
>
> echo "Record Updated";
>
> }
>
> }
>
> else{
>
> $query="UPDATE project SET name='$name',
> description='$description',
> show='$show'
> WHERE id=$id";
> mysql_query($query);
>
> echo "Record Updated";
>
> }
>
> mysql_close();
> ?>
>
> </TD>
> </TR>
> </TABLE>
> <?php
> require('footer.php');
> ?>

have you tried running mysql_error() after the update's. You may have a
single quote/apostrophy in $name, $description, or $show that needs to
be escaped before the string can be used in the query. I'm not sure
what the escape character is in MySQL, but in SQL Server you just have
to double the single quotes to have the dbms treat it as part of the
string instead of the end of the string.

Josh

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация