Jump to content

justsomeguy

Moderator
  • Posts

    31,575
  • Joined

  • Last visited

  • Days Won

    77

Posts posted by justsomeguy

  1. Right. In order for anything to change when someone is logged in, first you have to know if they are logged in.When someone logs in, you need to store their user ID (and maybe an encrypted password) in a cookie. Then later you can check the cookie to see if they are logged in (if there is a user ID in there), and then you can look them up in the database to see if the password is correct or if they are otherwise not allowed to log in for whatever reason.

  2. I don't have any experience with Ruby. The syntax looks fairly easy to understand, but one of the advantages to learning PHP is that it uses c-style syntax, and so other languages like javascript, perl, and C++ or C# will look familiar if you know PHP. And like you said, PHP has a lot more support than Ruby does. The website for Ruby lists a fair amount of hosts that support Ruby, but according to netcraft there are around 20 million hosts (servers) that run PHP.I guess it's up to you though. If you want to learn PHP, a good book is Programming PHP (which apparently has a second edition now), whose authors include Rasmus Lerdorf, who created PHP.

  3. I found application/jpg through Google. application/octet-stream will definately work, but it is my understanding that if the browser encounters a mime type that it does not understand, it will just prompt to save. I believe that it will just display the picture if you send image/jpg, so by changing it to application/jpg, I think that should cause a download prompt.

  4. Well, the code does work. The question is does it do what you were expecting. If you are checking for a logged in user, I don't understand why you are querying the database at all, you should be checking in the session. If you have some field in the database (status) that keeps track of people who are logged in, you will always get the welcome page whenever anyone at all is logged in, even if you aren't. You are checking for any member who has status = 1, I assume, so it will show welcome if anyone at all has status set to 1. If you want to check if someone is logged in, look in the session where you store their user ID. Then you can check the database and see if they are allowed to log in.

  5. Probably the most clear way is to have a recursive function that queries the database for each item. Like this:

    function write_menu(parent, level){  level = parseInt(level);  var sqlcon = Server.CreateObject("adodb.recordset");  sqlcon.ActiveConnection = sql_dbcon_string;    sqlcon.open("SELECT * FROM menu WHERE ParentID=" + parent + " ORDER BY name");  while (!sqlcon.eof)  {    for (i = 0; i < level; i++)      Response.Write("  "); //indent    Response.Write(sqlcon.fields.item("name").value);    write_menu(sqlcon.fields.item("id").value, level + 1);        sqlcon.movenext();  }  sqlcon.close();}write_menu(0, 0);

    I haven't tested that, but it should work. But, it will query the database a lot. If you want to avoid that, I guess you could get everything all at once and load it into an array, and then keep looping through the array to write everything out. A little more confusing in the code though. Maybe something like this:

    var menu_items = new array();var idx_id = 0;var idx_parent = 1;var idx_name = 2;var sqlcon = Server.CreateObject("adodb.recordset");sqlcon.ActiveConnection = sql_dbcon_string;  sqlcon.open("SELECT * FROM menu ORDER BY Name");while (!sqlcon.eof){  len = menu_items.push(new array());  menu_items[len - 1][idx_id] = sqlcon.fields.item("id").value;  menu_items[len - 1][idx_parent] = sqlcon.fields.item("parentid").value;  menu_items[len - 1][idx_name] = sqlcon.fields.item("name").value;  sqlcon.movenext();}sqlcon.close();for (i = 0; i < menu_items.length; i++){  if (menu_items[i][idx_parent] == 0) // root level first  {    Response.Write(menu_items[i][idx_name]);    show_children(menu_items[i][idx_id], 1);  }}function show_children(parent, level){  level = parseInt(level);  for (var i = 0; i < menu_items.length; i++)  {    if (menu_items[i][idx_parent] == parent)    {      for (var j = 0; j < level; j++)        Response.Write("  "); //indent      Response.Write(menu_items[i][idx_name]);      show_children(menu_items[i][idx_id], level + 1);    }  }}

    Again, untested. Maybe it works, who knows.

  6. You can also just add a header to instruct the browser to redirect (not through javascript):

    header("Location: index.php");

    This will only work if you haven't started the page output yet, but if you are setting a cookie then headers are still being sent, so it should work here.

  7. Try putting name in quotes. You don't need all the quotes around everything else though.

    <?//------------------------------------------------------// Require MySQL...//------------------------------------------------------require_once("MySQL.php");$sesID = $_COOKIE['xM_ID'];class user {function data ( $rowinfo ) { $rowinfo = "'$rowinfo'"; $query = "SELECT * FROM xM_members WHERE id = '$sesID'"; $result = mysql_query( $this->query ); $row = mysql_fetch_array( $this->result );  $return = $row[$rowinfo];  return $return;} //var $query = "SELECT * FROM xM_members WHERE id = "; //var $result = mysql_query( $this->query ); //var $row = mysql_fetch_array( $this->result );var $name = $this->data("name");}$user = new user;print "Logged in as: {$user->name}";print $sesID;?>

  8. You are using mysql_fetch_array. That produces an array like $row[0], $row[1], $row[2] for all of your fields. They are indexed by number, not by name. You need to use mysql_fetch_assoc to get an array like $row['status']. You also don't need the while loop, and I think extract is generally a bad idea unless you can be sure all your field names are globally unique. Try this:

    <?php$query = "SELECT * FROM members WHERE status = '$status'";$result = mysql_query($query)    or die(mysql_error());$row = mysql_fetch_assoc($result);if($row['status'] == "0") {   echo "<form action='console.php' method='post'><td class='main'><b>Username:</b> <input type='text' name='user' value='' class='form'> <b>Password:</b> <input type='password' name='pword' class='form'> <input type='submit' value='Login' class='lp'></td></form> "; }if($row['status'] == "1") {   echo "Weclome!"; }?>

    Log in

    Change the button to a normal submit button:<input type="submit" class="submit">I checked the code I have that does this and here is what I'm using:

    .standard_button {  font-family: "Verdana", sans-serif;  font-size: 10px;  font-weight: bold;  border: none;  height: 16px;  width: 100px;  background-image: url(../images/standard_button.gif);  background-position: 0% 0%;  color: #FFFFFF;  cursor: pointer;}.standard_button:hover {  background-image: url(../images/standard_button.gif);  background-position: 0% 100%;  color: #000000;}

    Maybe try changing the background-position to the percentages.Also, here's an example button. The normal state and hover states are part of the same image. Since I specify above that the button is 16px high, I made the image 32px so that it can move the image and show the other part.http://www.outpostmultimedia.com/projects/...dard_button.gif

  9. Pretty much any interactive website you can think of can be developed using PHP and MySQL as a backend. It sounds like you need something like a searchable product gallery or something like that. You can find several open source projects to do that stuff that you can get a good start with.

  10. You would need to create a PHP page or something to do the download for you, and send a different mime type. Instead of saying the content is inline, you say the content is an attachment. That should force the browser to prompt the user to save. So you need some script that takes in a filename, and opens the file to get a string of bytes. The output of the page will be some mime type headers and then the file itself. Something like this. Look up the php reference page on 'header' if you want more info.

    <?php$fname = $_GET['fname'];/* validate the file name here */$file_info = file_get_contents($fname);header('Content-type: application/jpg');header('Content-Disposition: attachment; filename="' . $fname . '"');echo $file_info;?>

    Log in

    You can style it if you want. You can use a lot of CSS properties to change the border style, background color, etc. You can also use CSS to make it look like an image, or you can just use an image without CSS. <input type="image" src="http://www.....jpg">You can also get a little tricky, and use one image for both the normal and hover states. You can make a button like this with css:

    .input_button {  background-image: url(path/to/image);  background-repeat: no-repeat;  background-position: top left;  height: 16px;  width: 80px;}.input_button:hover {  background-position: bottom left;}

    That way you make an image twice as tall as the button itself, and instead of having to load a new image on hover, it just moves the existing one.

  11. I know what you're saying, but eating with my feet doesn't make me appreciate my hands any more. It just makes me feel like a dirty ###### for eating with my feet.Edit: Please don't use bad language, we have members a young as 10 and 11 years old.Edit edit: I didn't realize the term for a son who doesn't know who his father is was considered bad language. Sorry.Edit Edit Edit: Well, it could be used that way, but then there's another application, and most young users will think of that. Plus the forum beeps it out anyway, and doesn't care how you've used the word. Thanks. ( I like edit contests :))

  12. Right - so you count the number of line breaks, and add one.This file:

    line1\nline2\nline3

    Has 2 line breaks, and there are three lines. Count the number of line breaks. You can explode the string on a newline and count the number of array elements, use substr_count to determine how many there are, or just walk through the string and count up the newlines. However you want to accomplish it, that's what you do, I'm telling you.

×
×
  • Create New...