robert_gsfame Posted September 26, 2009 Share Posted September 26, 2009 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 More sharing options...
redarrow Posted September 26, 2009 Share Posted September 26, 2009 Set a default for that database field tell me what happens. i bet you didn't even think of defaults in a database? Link to comment https://forums.phpfreaks.com/topic/175577-solved-whats-wrong-with-echo-disabled/#findComment-925203 Share on other sites More sharing options...
robert_gsfame Posted September 26, 2009 Author Share Posted September 26, 2009 if i don't put $disabled then it will return $value which is what i want either although $disabled was written down Link to comment https://forums.phpfreaks.com/topic/175577-solved-whats-wrong-with-echo-disabled/#findComment-925204 Share on other sites More sharing options...
redarrow Posted September 26, 2009 Share Posted September 26, 2009 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{}; ?> Link to comment https://forums.phpfreaks.com/topic/175577-solved-whats-wrong-with-echo-disabled/#findComment-925211 Share on other sites More sharing options...
robert_gsfame Posted September 26, 2009 Author Share Posted September 26, 2009 disabled can not be inserted into database so i think it's better to use "readonly"; ;D ;D ;D Link to comment https://forums.phpfreaks.com/topic/175577-solved-whats-wrong-with-echo-disabled/#findComment-925213 Share on other sites More sharing options...
redarrow Posted September 26, 2009 Share Posted September 26, 2009 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 Link to comment https://forums.phpfreaks.com/topic/175577-solved-whats-wrong-with-echo-disabled/#findComment-925214 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.