Jump to content

Need a help with updating table in mysql


FilipKrstic

Recommended Posts

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...

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(); 

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)

 

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"  ???

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.