Jump to content

justsomeguy

Moderator
  • Posts

    31,575
  • Joined

  • Last visited

  • Days Won

    77

Posts posted by justsomeguy

  1. First, about when you write the output. It's probably better to either use single quotes, or escape the $ sign so as not to confuse the parser:

    $output = '$db = array(); ' . $newentry;foreach ($db as $key => $value) {    $output .= ' $db[\''.$key.'\'] = "'.$value.'";';}

    Also, I'm confused about the first 2 lines of code you have. It looks like you are writing PHP code to a file, and the code creates and sets up an array. So these are the first 2 lines:

    include('db.php');$db = array();

    It looks like you include the file that builds the array, but the next line is the array construct which assigns a new blank array to $db. Take out the second line and see what happens, I think that will probably fix it. Or you can also replace it with this, to make sure that the first time this runs $db is created, but won't be replaced:

    if (!isset($db))  $db = array();

    With the image issue, if you can get to the file directly then it's not a permissions problem. One thing to do is to make sure you wrap all your variables inside strings in curly brackets. You have one variable called $images and one called $imagesource, so when the engine sees echo "...$imagesource..." I'm not sure if it reads that as "...{$imagesource}..." or "...{$images}ource...". Also, in the link you shouldn't have & separate variables, only &. Saying remove.php?key=xxx&value=xxx makes a variable called key and a variable called amp;value. & is only for displaying the ampersand in text. Anyway, I've just cleaned up the code a little, see if it works:

    foreach ($db as $key2 => $value2) {     $imagesource = $images.$value2;    echo "<img src=\"{$imagesource}\" alt=\"{$value2}\"/><br/>image: {$value2}<br/>uploaded: {$key2}<br/><a href=\"remove.php?key={$key2}&value={$value2}\" title=\"remove this image\">remove this image</a><br/><br/>";}

  2. About the tutorial:

    At W3Schools you will find complete references of all PHP functions:
    That's not entirely true. Compare the list of function categories at w3schools here (there are 12 categories) with the list at php.net (there are 177 categories).
  3. 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.

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

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

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

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

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

  9. 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;?>

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

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

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

×
×
  • Create New...