Forum Moderators: coopster

Message Too Old, No Replies

Cant seem to update...

Cant seem to update my database altho the vars are being passed over...

         

PSWorx

9:33 am on Nov 9, 2003 (gmt 0)

10+ Year Member



This is the update function for an admin system im writing, basically the variables are retreived from the $GLOBALS array, the variables are set and i can print the new contents of the variables but i seem to be getting a syntax error, heres the code:

function updatedb($pagename){
global$PHP_SELF;
$dbuser="xx";
$dbpass="xx";
$db="gdon_contents";
$link=mysql_connect("localhost",$dbuser,$dbpass);
mysql_select_db($db,$link);
$dbresult=mysql_query("SELECT * FROM page$pagename");
$finalrow=mysql_num_rows($dbresult);
$field=mysql_fetch_array($dbresult);
for($z="1";$z<=$finalrow;$z++){
$vid1="content$z";
$vid2="show$z";
$query="UPDATE page$pagename SET content='$GLOBALS[$vid1]',name='',show='$GLOBALS[$vid2]',id='$z' WHERE id=$z";
if(!mysql_query($query,$link)){$dberror=mysql_error();echo $dberror;return false;}else{return true;}
echo "$GLOBALS[$vid1]<br>\n";
echo "Show: $GLOBALS[$vid2]<br>\n";
echo "Z: $z<br><br>";
}
}

This is the error returned:

You have an error in your SQL syntax near 'show='1',id='1' WHERE id=1' at line 1

Tried all sorts with it and it just wont ave it, dont think its anything to do with the actual content of the vars used to update, infact im just not sure, any help would be great...

dreamcatcher

11:59 am on Nov 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi PSWorx,

What exactly is being updated where name=", is specified? Looks like you are missing some syntax. If your name field in your database is NOT NULL, maybe thats the problem? Try adding some information in between the tags for name.

Just a thought!

PSWorx

12:24 pm on Nov 9, 2003 (gmt 0)

10+ Year Member



Ive managed to get it working to some extent but it wont let me update more than one area so having to loop around to update qyuerys to get all the content updated (that being $content and $show)

Bit of a daft way around it but never the less, it works, im happy n with the final intended output the user should be happy but thanks anyways, let me know if u want a live view of what im doing

PSWorx

12:41 pm on Nov 9, 2003 (gmt 0)

10+ Year Member



Right, heres the code that works (only tp update the content field of the row):

function updatedb($pagename){
global$PHP_SELF;
$dbuser="****";
$dbpass="xxx";
$db="gdon_contents";
$link=mysql_connect("localhost",$dbuser,$dbpass);
mysql_select_db($db,$link);
$dbresult=mysql_query("SELECT * FROM page$pagename");
$finalrow=mysql_num_rows($dbresult);
$field=mysql_fetch_array($dbresult);
for($z=1;$z<=$finalrow;$z++){
$udcontent="content$z";
$udshow="show$z";
$query="UPDATE page$pagename SET content='$GLOBALS[$udcontent]' WHERE id=$z";
if(!mysql_query($query,$link)){$dberror=mysql_error();echo $dberror;return false;};
}}

(Sorry my formatting is bad i know)

Everytime i add another field to update i.e:

$query="UPDATE page$pagename SET content='$GLOBALS[$udcontent]' show='$GLOBALS[$udshow]' WHERE id=$z";

I get the error on the output refering to the synatx:

You have an error in your SQL syntax near 'show='1' WHERE id=1' at line 1

Now it doesnt matter if i run a second query just to update the show field of the database as it returns the same... Any ideas

charlier

2:54 pm on Nov 9, 2003 (gmt 0)

10+ Year Member



Hmm just a thought on Sunday morning before coffee, but is 'show' a reserved word in mysql?

Cheers
Charlie

PSWorx

2:56 pm on Nov 9, 2003 (gmt 0)

10+ Year Member



Hmm then perhaps that might answer the reason as to why it will only let me update the contents field...

bye golly gosh watson i think youve cracked it...

(Will be back in ten with an updated)

Thanks!

Thanking you with the grace of a thousand camels my fellow brain, thats the wee hint ive been searching for, now my quest can continue, enjoy your coffee while i enjoy my efforts:

for the sake of, well i dont know but you can see the output here:

<snip>

The area in question was the edit page contents, if u select a page from the following list and make some changes ull see what the intention was for (remember to check the site view of the page you edited)

Thanks again with a thousand camels...

[edited by: jatar_k at 6:05 pm (utc) on Nov. 10, 2003]
[edit reason] no personal urls thanks [/edit]