Page 1 of 1

help me on updating my table

Posted: Fri Apr 11, 2008 3:58 pm
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.

Re: help me on updating my table

Posted: Fri Apr 11, 2008 4:05 pm
by andym01480
Ye Olde

Code: Select all

echo $query;
just after the $query=... line may show up a problem!
Post the error too.

Re: help me on updating my table

Posted: Fri Apr 11, 2008 4:08 pm
by sj1983msh
Sorry would you please explain what you meant?

Re: help me on updating my table

Posted: Sat Apr 12, 2008 3:04 am
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);

Re: help me on updating my table

Posted: Sat Apr 12, 2008 6:35 am
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.

Re: help me on updating my table

Posted: Sat Apr 12, 2008 7:33 am
by andym01480
No problem - just out of interest what had gone wrong?

Re: help me on updating my table

Posted: Sat Apr 12, 2008 3:44 pm
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.