Jump to content

[SOLVED] what's wrong with echo "disabled";


robert_gsfame

Recommended Posts

i have a form and wish to disable users to change their username if they've posted something on the site let say news still being posted on the screen

 

This is my code in short

 

$array=mysql_fetch_array($mysql); <-- i don't put all code this just the connection of database and get data in array using mysql_fetch_array

 

$value=$array['username'];<--let assume that username is the column name taken from the database

 

$newsstatus=$array['newsstatus'];<--let assume that newsstatus is the column name taken from the database, and what value could be inserted is only yes or no...yes means active while no means no news yet

 

if($newsstatus==yes){

$disable="disabled";}else{

$disable=" ";}

 

<input type = "text" name=textbox1 value=<?php echo $value;?> <?php echo $disable;?> >

 

Then let say once submit then it will update the newsstatus....the problem is that it always return NULL value, what is the problem with echo $disable???

Link to comment
https://forums.phpfreaks.com/topic/175577-solved-whats-wrong-with-echo-disabled/
Share on other sites

what about this is it close to what you want try....

 

 

not tested at all......

 


<?php

$db=mysql_connect_db("localhost","username","password");
$res=mysql_query_db($db)or die("database had a hart attack".mysql_error());

$mysql1="CREATE DATABASE test";
$res1=mysql_query($mysql1)or die("database was not created".mysql_error());

$use="USE test";
$res2=mysql_query($use)or die("database error USE".mysql_error());

$mysql2="CREATE TABLE newsstatus{
         id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
     newsstatus emum('yes','no') NOT NULL default 'no'
         }";

$res3=mysql_query($mysql2)or die("database error creating table newsstatus".mysql_error());

if($res3){

$msql_select="SELECT * FROM newsstatus";
$mysql_return=mysql_query($mysql_select)or die("my god you blown this up error newsstatus".mysql_error());

while($data=mysql_fetch_assoc($mysql_return)){

	if($data['newsstatus']==yes){
         

		$disable="disabled";

	}else{

			$disable="not disabled";}


			echo $disabled;
}

}else{};

?>

yes and no is inserted in my example, default no, and $disable is a set variable with the name disable or not disable echoed to the page....

 

 

because the enum was set to no mean the printed statement is.

 

not disabled

 

if the enum default was set to yes the printed statement is

 

disabled

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.