Jump to content

PHP Monkeh

Members
  • Posts

    409
  • Joined

  • Last visited

    Never

Posts posted by PHP Monkeh

  1. Hellow,

     

    I have an array $Data with keys and values. With a foreach I can display all the values:

    foreach($Data as $var)
    {
        echo $var;
    }

     

    but I also want to display al the keys... how can i do that?

     

    Quite easily, change your foreach() line to this:

     

    foreach($Data as $key => $var)

     

    That will allow you to use $key.

  2. Alright well you'll need to do a bit more work for the second option, but here's the rough outline:

     

    1)  Create a new 'flags' table with the fields: id, venueId, userId, reason

     

    I hope your venues table has an ID field as you'll need something to uniquely identify it.

     

    2)  Set up your page to allow visitors to flag up a venue and specify which reason

     

    3)  Do some checking once the user has submitted the flag:  do a query on the venueId, and current user's ID, and make sure that there isn't a row in the 'flags' table containing both.  If the check passes, then submit the flag to the table and you're done (this handles re-submissions from the same user for the same venue).

     

    4)  As for your CRON script, you'll probably need to use a JOIN if you want to do it pure MySQL (and I must admit I'm hopeless with JOINs).  Or if you wanted to do it with some PHP:

     

    $query = "SELECT id, COUNT(*) FROM `flags` GROUP BY `id`";

     

    Loop through that query, check whether COUNT(*) is greater than or equal to 5 and then perform another query to delete the row.

     

     

     

    Not going to write the code for you, but that should at least get you on the right track.

  3. Primary Key

    A primary key is an auto-incrementing number which is unique to each row of the database table.  It allows you to uniquely identify each row, as other values may change.

     

    )";//do I  need to remover the ; what is the purpose of that? just wondering because my book examples have them

    I didn't mean that line of code, I meant the entire variable.  It's called $slq rather than $sql, and I wondered whether you changed the name of it so that it wasn't used.

     

    $result=mysql_query ($sql, $connection)//isn't this the $result variable?

    It is, but your if() statement is looking for $results.

  4. There are two routes you can go down, either adding another field to the table you current have, or creating a new table specifically for storing 'flags'.

     

    Considering you only want to know if there are 5 flags, and not extra info like date/time submission of flag, who flagged it up, their reason etc, I'd go with the extra field option.

     

    So:

     

    1)  Add another field to your current table called 'flags'

    2)  Set up your page so that the user can add 1 to this flag field, you might want to use sessions/cookies to prevent multiple submissions - though if you're afraid of abuse you may wish to go with the 2nd option I suggested above

    3)  Create a script (which the CRON will call) that does a query on all rows which have a 'flag' value of 5 or more, and delete them

     

     

    The second option will be a bit more complex, if the above isn't what you were looking for I can go in to more detail.

  5. I'm trying to figure out whether this is a joke or not.

     

    Anyway, you'll need to show us some actual code if you want us to help.  There's no use mentioning that something is in an 'endless loop', when the code you've shown doesn't actually contain a loop.

     

    And please spell-check your posts before posting as they're hard to understand.

  6. If you want to see all your errors, remove your error supressions (@ symbol) from the beginning of function calls.

     

    I'll give you a hint though, there are quite a few.  Just to point out the ones I spotted:

     

    <?php
    $sql="CREATE database hombudget";
    $connection= @mysql_connect ("localhost","spike", "9sj7En4")
    or die (mysql_error());
    $result=@mysqlquery ($sql, $connection) or die (mysql_error());
    mysql_select_db("homebudget", $connection)
    $tbl= "CREATE TABLE 'estimate'
    (
    Category varchar (10),
    Description varchar (30),
    Budget int
    )"; // You might want a primary key
    $slq = "
    DROP DATABASE IF EXIST 'homebudget'
    CREATE  TABLE 'expenses'
    (
    Category varchar (10),
    espenseData DATE,
    expenditure INT
    )"; // Did you leave this in intentionally?
    $result=mysql_query (4sql, $connection) // 4 rather than $ sign
    or die (mysql_error());
    if ($results) { // Variable doesn't exist
    $msg  =  "</P>Database Homebudgethas been created </P>"; // Where's the beginning P tag?
    }
    ?>
    <HTML>
    <HEAD>
    <TITLE>Homebudget Database</TITLE>
    </HEAD>
    <BODY>
    <?php echo  "$msg"; // No need for quotation marks here
    ?>
    </BODY>
    </HTML>

     

    Quite frankly without trying to sound rude, it's quite a mess in there.

     

     

     

  7. Apart from encoding all your files, there's nothing stopping them.  Though if a hacker managed to 'slip a file within the apache server' they will probably just be able to open up your file anyway.

     

    If someone managed to get access to your server, your database config details are the last thing you really need to worry about :)

  8. I'm struggling to understand your question as well.  Do you want to keep the same structure but just change the sprite image?

     

    <style type="text/css">
    #pagtop_info {
            background-image: url('result.png');
    }
    </style>

     

    That would replace the image of #pagtop_info while keeping the other values in place.  You would then need to give your new DIV an ID of 'pagtop_info'

  9. $_POST['events'] is an array because you have multiple checkboxes.  So you'll need to loop through each of the checkboxes when doing your insert:

     

    for($i=0; $i<count($_POST['events']); $i++)
    {
    mysql_query("INSERT INTO user (events) VALUES ('" . $_POST['events'][$i] . "')", $connection);
    }

  10. You coud do an not-so-elegant str_replace() on commas in $FreeSpace I guess - it would be better though if you did this when you were initialising the $FreeSpace variable.  Or if it's being pulled from a database, removing the comma before inserting the value to the DB.

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