Jump to content

Database trouble


supermerc

Recommended Posts

Iv just added a description field for the profile of my users. But when my users register that field is empty. So I want to make it so it is `This user has not yet entered a description` By default when someone registers.

So i tried to put that in the default field

but this is what I got

SQL query:

ALTER TABLE `users` CHANGE `description` `description` TEXT CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT 'This user has not yet enetered a description'

MySQL said: Documentation
#1101 - BLOB/TEXT column 'description' can't have a default value

Then I tried to put it as varchar (500) but it said the max for varchar is 255 but thats too small for a description.
Link to comment
https://forums.phpfreaks.com/topic/31034-database-trouble/
Share on other sites

Dont store that in the database. In your display code, check for a description, if none exists, then write that. eg;

[code=php:0]
if ($result = mysql_query("SELECT description FROM profile")) {
  if (mysql_num_rows($result) > 0) {
    // display description.
  } else {
    echo "This user has not yet entered a description";
  }
}
[/code]
Link to comment
https://forums.phpfreaks.com/topic/31034-database-trouble/#findComment-143213
Share on other sites

where in my code should i put it

[code]      <?php
      require("config.php");
      require("func.php");
      //echo some styles to spice it up...
      echo "
      <style>
      body
      {
      background: #EBEBEB;
      font-family: Verdana, Arial;
      font-weight: bold;
      font-size: 9px;
      color: #000000;
      }
      .register_box
      {
      border: 1px solid #323232;
      background: #202020;
      font-family: Verdana, Arial;
      font-weight: bold;
      font-size: 9px;
      color: #FFFFFF;
      }
      </style>
      ";
      // if the variable member_id has been set, or there is a value assigned to it...
      if(isset($_GET['member_id']))
      {
      $member_id = (INT)$_GET['member_id'];
      $member_info = mysql_query("SELECT username, description, email FROM users WHERE activated = '1' AND id = '$member_id' LIMIT 1");
      if(mysql_num_rows($member_info) > 0)
      {
      // we can go ahead and assign it to an array because this user exists
      $profile_info = mysql_fetch_assoc($member_info);
      echo "
      <h1>$profile_info[username]</h1>
      <br />
  <b>Descriptions: $profile_info[description]
      <br />
      <b>Email:</b> <a href='mailto:$profile_info[email]'>$profile_info[email]</a>
      <br />
      <br />
      ";
      }
      else
      {
      echo "That member does not exist, or is not activated yet!";
      }
      }
      else
      {
      echo "There was no member ID to view a profile for!";
      }
      ?> [/code]

Im not quite sure where it goes
Link to comment
https://forums.phpfreaks.com/topic/31034-database-trouble/#findComment-143220
Share on other sites

You would need to replace this...

[code=php:0]
echo "
      <h1>$profile_info[username]</h1>
      <br />
  <b>Descriptions: $profile_info[description]
      <br />
      <b>Email:</b> <a href='mailto:$profile_info[email]'>$profile_info[email]</a>
      <br />
      <br />
      ";
[/code]

with...

[code=php:0]
if (!$profile_info['description'] == "") {
    echo "
      <h1>$profile_info[username]</h1>
      <br />
  <b>Descriptions: $profile_info[description]
      <br />
      <b>Email:</b> <a href='mailto:$profile_info[email]'>$profile_info[email]</a>
      <br />
      <br />
      ";
} else {
echo "
      <h1>$profile_info[username]</h1>
      <br />
  <b>This user has not yet enetered a description.
      <br />
      <b>Email:</b> <a href='mailto:$profile_info[email]'>$profile_info[email]</a>
      <br />
      <br />
      ";
}
[/code]

PS; A big part of learning to program is learning to think.
Link to comment
https://forums.phpfreaks.com/topic/31034-database-trouble/#findComment-143232
Share on other sites

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.