help me on updating my table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sj1983msh
Forum Newbie
Posts: 15
Joined: Thu Feb 28, 2008 12:01 pm

help me on updating my table

Post by sj1983msh »

Hi friends,

I have a problem with my code. I have written a code with dream-weaver CSIII ( I mean I developed a section in a project ), I have uploaded the files on the server but the code which I asked you to help me, doesn't work properly.
This code is for UPDATING a table on this project. It works on my PC well but when I put that on the server it Updates no data. The Query is not working what should I do!?
Here is my query :

Code: Select all

 
$newsId=$HTTP_POST_VARS['newsId'];
$news_title=$HTTP_POST_VARS['news_title'];
$news_title=trim($news_title);
$news=$HTTP_POST_VARS['news'];
$news=trim($news);
 
$query="update news set subject='$news_title',description='$news' where id='$newsId'";
$link=mysql_connect("localhost", "MyUSER", "MyPASS") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db("myDB",$link);
mysql_query($query, $link);
mysql_close($link);
 
The $newsId is the ID for a specific news. The $news if the main text of a news. and $news_title is the topic of the same news.
The Query is not working on the server. Where may the problem be? Please Help me through.

Sincerely
Saman J.
Last edited by Weirdan on Sat Apr 12, 2008 7:39 am, edited 2 times in total.
Reason: bbtags
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Re: help me on updating my table

Post by andym01480 »

Ye Olde

Code: Select all

echo $query;
just after the $query=... line may show up a problem!
Post the error too.
Last edited by andym01480 on Sat Apr 12, 2008 3:06 am, edited 1 time in total.
sj1983msh
Forum Newbie
Posts: 15
Joined: Thu Feb 28, 2008 12:01 pm

Re: help me on updating my table

Post by sj1983msh »

Sorry would you please explain what you meant?
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Re: help me on updating my table

Post by andym01480 »

Code: Select all

$newsId=$_POST['newsId']; //$HTTP_POST_VARS is old use $_POST instead
$news_title=trim($_POST['news_title']); //$HTTP_POST_VARS is old use $_POST instead
$news=trim($_POST['news']);
$query="update news set subject='$news_title',description='$news' where id='$newsId'";
echo $query;  // This lets you see what your query looks like with the variables populated. Often you can see what has gone wrong
$link=mysql_connect("localhost", "MyUSER", "MyPASS") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db("myDB",$link);
mysql_query($query, $link) OR DIE (mysql_error()); //post what is produced on screen by mysql_error if it didn't work
echo "Updated";
mysql_close($link);
sj1983msh
Forum Newbie
Posts: 15
Joined: Thu Feb 28, 2008 12:01 pm

Re: help me on updating my table

Post by sj1983msh »

Thanks alot for your help.
You were right the Echo $query; can solve most of this kind of problems.

I used it and at last I found the problem. Thank you very much and also thank you for giving me the tips of the old server variable use.

Sincerely
Saman J.
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Re: help me on updating my table

Post by andym01480 »

No problem - just out of interest what had gone wrong?
sj1983msh
Forum Newbie
Posts: 15
Joined: Thu Feb 28, 2008 12:01 pm

Re: help me on updating my table

Post by sj1983msh »

Infact the problem was for this:
The code was correct but the values which must be in the variables ($newsId....) was not set properly, I don't know why, but that code was run successfuly on my PC!!

Anyway, Thanks alot again and again.

Sincerely
Saman J.
Post Reply