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

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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