FilipKrstic Posted January 4, 2009 Share Posted January 4, 2009 I need to update table "profs", fiels "cssstil" in some value which is readed from form type select. But, at same time, row username must be == value $_SESSION[username] (I use this to msql recognize row in table) // Izvrsi CSS promenu $usr == $_SESSION[username]; include"../config.php"; $query = mysql_query("UPDATE profs SET cssstil where username=$usr VALUES ('$_POST[selectcss]')") or die (mysql_error()); echo "Dodato<META http-equiv='refresh' content='0;URL=index.php"; exit(); I have tried like this, but I have problems with mysql sintax Can someone help me? Thanks a lot... Link to comment https://forums.phpfreaks.com/topic/139438-need-a-help-with-updating-table-in-mysql/ Share on other sites More sharing options...
jonsjava Posted January 4, 2009 Share Posted January 4, 2009 I need to update table "profs", fiels "cssstil" in some value which is readed from form type select. But, at same time, row username must be == value $_SESSION[username] (I use this to msql recognize row in table) // Izvrsi CSS promenu $usr == $_SESSION[username]; include"../config.php"; $query = mysql_query("UPDATE profs SET cssstil where `username`='$usr' VALUES ('$_POST[selectcss]')") or die (mysql_error()); echo "Dodato<META http-equiv='refresh' content='0;URL=index.php"; exit(); I have tried like this, but I have problems with mysql sintax Can someone help me? Thanks a lot... you use "=" instead of "==" when you are defining something. "==" is used to compare. Also, your sql was incorrect, but I corrected it. One last thing: you didn't execute the sql. You set a variable that would equal the execution, but if you don't evaluate/run that variable, it won't run. I have it so it just runs (not assigned to a variable) <?php $usr = $_SESSION[username]; include"../config.php"; $css = mysql_real_escape_string($_POST['selectcss']); mysql_query("UPDATE profs SET `cssstil`='$css' where `username`='$usr' LIMIT 1;") or die (mysql_error()); echo "Dodato<META http-equiv='refresh' content='0;URL=index.php"; exit(); Link to comment https://forums.phpfreaks.com/topic/139438-need-a-help-with-updating-table-in-mysql/#findComment-729384 Share on other sites More sharing options...
revraz Posted January 4, 2009 Share Posted January 4, 2009 This code will run the query $query = mysql_query("UPDATE profs SET cssstil where username=$usr VALUES ('$_POST[selectcss]')") or die (mysql_error()); One last thing: you didn't execute the sql. You set a variable that would equal the execution, but if you don't evaluate/run that variable, it won't run. I have it so it just runs (not assigned to a variable) Link to comment https://forums.phpfreaks.com/topic/139438-need-a-help-with-updating-table-in-mysql/#findComment-729390 Share on other sites More sharing options...
FilipKrstic Posted January 4, 2009 Author Share Posted January 4, 2009 Thanks you, I`m php starter, as you see, thanks of lot.... Link to comment https://forums.phpfreaks.com/topic/139438-need-a-help-with-updating-table-in-mysql/#findComment-729391 Share on other sites More sharing options...
FilipKrstic Posted January 5, 2009 Author Share Posted January 5, 2009 One more question... I have putted text in mysql table, and when I want to select table from mysql table I use: $usrnm = $_SESSION[username]; include"../config.php"; $query = mysql_query("select * from profs where `username`='$usrnm' LIMIT 1;") or die (mysql_error()); if($data = mysql_fetch_array($query)) { $boja = $data[cssstil]; } //$data[cssstil] can be only Plava,Crvena,Zelena,Braon,Magneta, that are words from select form After that I want to do something with selected text: $plava = "Plava"; $crvena = "Crvena"; $braon = "Braon"; $zelena = "Zelena"; $magneta = "Magneta"; if($boja == $plava) { $boja = str_replace("<link rel='stylesheet' type='text/css' href='../css/prof-blue.css' />"); print'$boja'; } if($boja == $crvena) { $boja = str_replace("<link rel='stylesheet' type='text/css' href='../css/prof-red.css' />"); print'$boja'; } if($boja == $zelena) { $boja = str_replace("<link rel='stylesheet' type='text/css' href='../css/prof-green.css' />"); print'$boja'; } if($boja == $braon) { $boja = str_replace("<link rel='stylesheet' type='text/css' href='../css/prof-brown.css' />"); print'$boja'; } if($boja == $magneta) { $boja = str_replace("<link rel='stylesheet' type='text/css' href='../css/prof-mag.css' />"); print'$boja'; } But I have error: "Warning: Wrong parameter count for str_replace() in /home/w0500004/public_html/pages/template.php on line 18" ??? Link to comment https://forums.phpfreaks.com/topic/139438-need-a-help-with-updating-table-in-mysql/#findComment-729593 Share on other sites More sharing options...
premiso Posted January 5, 2009 Share Posted January 5, 2009 str_replace Read the manual. You need the str_replace(replace, replacewith, replacein) for it to work. Not just the what to replace. Link to comment https://forums.phpfreaks.com/topic/139438-need-a-help-with-updating-table-in-mysql/#findComment-729595 Share on other sites More sharing options...
FilipKrstic Posted January 5, 2009 Author Share Posted January 5, 2009 my fall, what I want, can`t working on this way... tnx... Link to comment https://forums.phpfreaks.com/topic/139438-need-a-help-with-updating-table-in-mysql/#findComment-729596 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.