Jump to content

joel24

Members
  • Posts

    760
  • Joined

  • Last visited

Posts posted by joel24

  1. It looks like your mysql queries are failing, for the meantime put or die(mysql_error()) after the mysql_queries to see if they are executing correctly. You'll want to remove this line when the site is ready for publishing.

    
    mysql_query ("INSERT INTO profiles (username, first, last, email, phone)
         VALUES ('$username','$first','$last','$email','$phone')") OR die("1" . mysql_error());
             
    mysql_query ("INSERT INTO users (user, password)
         VALUES ('$username','$encrypt_password')") OR die("2" . mysql_error());
       
    
    mysql_close($connect);
    
    header("location:complete.php");
    

     

    Or you could have something like the following

    $sql1 =  "INSERT INTO profiles (username, first, last, email, phone)
         VALUES ('$username','$first','$last','$email','$phone')";
             
    $sql2 = "INSERT INTO users (user, password)
         VALUES ('$username','$encrypt_password')";
    
    if (@mysql_query($sql1) && @mysql_query($sql2))
    {
    mysql_close($connect);
    
    header("location:complete.php");
    }
    else
    {
    //error with mysql query. Change this to a nice neat error when production site is live
    exit(mysql_error());
    }
    
    
    

  2. you're wiping the content of the column variable in the line:

    $column = '';

     

    and also you're just executing the MYSQL query but not storing the results in a variable, you need to have @variable = mysql_query("select * from rararara");

     

    and your returning nothing from the function.

     

    if you want to return an array of the db content instead of echoing it, you can just have

    return mysql_fetch_array($sql)

    instead of the while loop.

    try

     

    function listQuery($table,$column) {
    
    
    
    
    
    
    //1. Create DB connection
    
    
    
    
    
    
    $connection = mysql_connect("localhost", "user", "password"); 
    
    
    
    if (!$connection) {
    
    
    
    
    
    die("Database connection failed: " .mysql_error());
    
    
    
    }
    
    
    
    //2. Select a DB to use
    
    
    
    $db_select = mysql_select_db("sitetest",$connection);
    
    
    
    if (!$db_select) {
    
    
    
    
    
    die("Database selection failed: " .mysql_error());
    
    
    
    }
    
    
    
    $sql = @mysql_query("SELECT * FROM $table", $connection);
    
    
    
    if (!$sql) {
    
    
    
    
    
    die("Database query failed: " .mysql_error());
    
    
    
    } 
    
    
    
    
    
    
    while ($row = mysql_fetch_array($sql)) { 
    
    
    
    
    
    
    
    
    echo $row['$column'];
    }
    }
    

  3. have the users fill choose their timezone, i.e. have a select box with +1 +2 etc, or the list of timezones, Sydney/Australia New York/USA etc.

    then have their information/timezone stored in a database, and when they login you can have a code liek

    //timezone php
    putenv('TZ=Australia/Sydney');
    

     

    and if you want to change the mysql timezone also,

    //get offset, including daylight savings because mysql won't!
    $currentOffset = "+".(date("Z") / 60 / 60).":00";
    
    //timezone mysql
    $update_tz = @mysql_query("SET time_zone = '$currentOffset'") or die(mysql_error());
    

     

    so for that use the timezone would be australia/sydney and it would be stored in the database with their user details, and then when they log in that information would be retrieved from the database and the line

    //timezone php
    $sql = @mysql_query("SELECT timezone FROM users WHERE userid = 'whatever'");
    $userDetails = mysql_fetch_array($sql);
    $timezone = $userDetails['timezone'];
    putenv("TZ=$timezone");
    

     

  4. well in short, you have to have a third table.

    table 1: categories

    table 2: patients

     

    table 3: patient_categories

    then you can have a list or checkboxes etc in the form, and send it as an ARRAY, i.e. make the checkboxes all with the same name with [] after it. i.e.

    <input type='checkbox' name="patient_categories[]">category name</input>

    then have a php loop to get all the categories from the database and echo them.

     

    then when the checkboxes are posted in the form, you can get the array like

    $_POST['patient_categories'] will be an array

    so you can use

     foreach ($_POST['patient_categories'] AS $pc)

     

     

    you might be best googling one to many relationships mysql etc, this explanation is a bit brief and it will help a lot if you get a comprehensive understanding of it

     

  5. create a relationship table in your database to create the one to many relationship,

    i.e.

    persons_categories

    which would have person_id (foreign key) and then another column with category_id (foreign key) and you'd have a unique key (combination of category_id and person_id) so that the row was never duplicated

    and then the person could be listed multiple times, once for each category they are in.

     

    and then to update those relationships, or create a new relationship, you'd use something like

    INSERT INTO table (a,b,c) VALUES (1,2,3)
      ON DUPLICATE KEY UPDATE c=c+1;
    
    UPDATE table SET c=c+1 WHERE a=1;

    to avoid creating duplicate rows etc

    http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html

  6. Is there a way without using mysql database ? I will simply need to echo it on the page, I don't  need to insert it in database.

     

    any help pls.

     

    yes, you can just use either of these two

     

    //timezone php
    putenv('TZ=Australia/Sydney');
    

     

    //timezone php
    date_default_timezone_set('Australia/Sydney');
    

  7. I was havin troubles on my server a while ago too, assuming because of the server's security limitations.

    either way I now use this little script i made up

    Note- the script sets both the MYSQL and the PHP to use the australia/sydney timezone.

    <?php
    //timezone php
    putenv('TZ=Australia/Sydney');
    
    //get offset, including daylight savings because mysql won't!
    $currentOffset = "+".(date("Z") / 60 / 60).":00";
    
    //timezone mysql
    $update_tz = @mysql_query("SET time_zone = '$currentOffset'") or die(mysql_error());
    ?>
    

  8. what is "$guest = $row['guest_number'] + $a" for? Its going to add the amount of the current table to every other table. If you're trying to add up the total amount of guests for that day you should use something like

    $query = "SELECT SUM(guest_number) AS total_bookings FROM booking WHERE year = $f" //you'll have to add in the code to check the date, i.e. where booking_date = $b 

     

    Then you'll be able to use

     $result = mysql_fetch_array($query)
    $guest_numbers = $result['total_bookings']

  9. wheres the script to log the user in?

    when they log in you should put their user id in a session value

     

    or to get said value later on, you could do something like

    $sql = @mysql_query("SELECT user_id FROM users WHERE username = '{$_SESSION["authenticatedUser"]}'");
    $userID = mysql_fetch_array($sql);
    $userID = $userID['user_id'];
    

  10. try doin

    print_r($_POST);
    

    to see what information is being posted to the page.

     

    also with your array indexes you need to quote them if they're not integers

    i.e.

    $_SESSION[comment_owner]
    

    should be

    $_SESSION['comment_owner']
    

     

    ... another thing, are you sure you want to be pulling these values (comment_owner etc) from the session? You have name and email fields in your form named "comment_owner" etc...

  11. everything beneath it is getting hidden because the check_email function is using die() when an error occurs, which terminates the script.

    you can change die to echo, depending on how you've got it all set up.

    also you'll want to check that the emails being passed to the check_mail function correctly, i tried typing in a legit email and it came back saying "Oops! Email is not valid."

     

  12. read my post.

    you'll need to put in a threadViews table

    userID

    forumID

    viewTime (datetime)

    where userID and forumID are both primary & foreign keys.

     

    each time a user views a page have this sql statement run

    INSERT INTO threadViews (userID, forumID, viewTime) VALUES (userID, forumID, NOW())
      ON DUPLICATE KEY UPDATE viewTime = NOW();
    

    obviously change userID and forumID to $_SESSION['id'] or however you store those values.

     

    then to check for threads with new posts

    not exactly sure how your tables are set up... but say you have threadViews monitoring when a user views a thread, forumPosts which stores all the posts and forumTopics which stores all the topics

    SELECT forumID, forumName, etc FROM threadViews t
    JOIN forumPosts f ON t.forumID = f.forumID
    JOIN forumTopics ft ON t.forumID = ft.forumID
    WHERE last_post_reply > viewTime 
    ORDER BY last_post_reply DESC
    

     

    ... thats assuming last_post_reply is a datetime field?

    if not put in a datetime field for each thread which is updated everytime a reply etc is made to it.

  13. you'd have to have a table called say threadViews like so

    userID

    forumID

    viewTime

     

    and then each time a user views a thread, it updates that field.. or creates it if its non-existant... then to see if a thread has new posts you'd use a join like

    SELECT forumID FROM threadViews t JOIN forumPosts f ON t.forumID = f.forumID WHERE last_post_reply > viewTime

     

  14. thats because you're not checking to see if the query returns a row, you're just checking if the query works

     

    $last = @mysql_query("SELECT * FROM users WHERE username='{$_POST['username']}' AND last < NOW() - INTERVAL 1 HOUR");
    
    if (mysql_num_rows($last)) {
    upload photo
    } else {
    don't upload
    }
    

  15. mysql has built in time functions, at the moment your trying to compare a timestamp int to a TIME field... you can use mysql to convert the TIMESTAMP to a time format or you can put the time in the mysql format HH:MM:SS, or you can do it all in mysql as follows.

    $last = ("SELECT * FROM users WHERE username='{$_POST['username']}' AND last < NOW() - INTERVAL 1 HOUR");
    

     

    also you should probably change the "last" field to DATETIME... and then when you upload set "last = NOW()", otherwise the user could upload a photo on the 14th of the month at 9am then go to upload on the 15th at 9.30am and it would say it hasn't been an hour yet.

     

  16. you'd have it so when a user uploads an image it goes liek

    $userid = //whatever.. $_SESSION['id'] etc
    $checklast = @mysql_query("SELECT * FROM users WHERE userid = $userid AND last < NOW() - INTERVAL 1 HOUR");
    if (mysql_num_rows($checklast)) {
    //upload photo
    } else {
    //error! you've uploaded a photo in the last hour
    }
    

  17. you could do something like

    $product = "Product XYZ";
    $price = 1004;
    $total = 100; //100 chars for select
    $dots = $total - strlen($product) - strlen($price);
    $select = '';
    
    for ($i = 0; $i < $dots; $i++)
    {
    $select .= '.';
    }
    
    $select = $product.$select.$price;
    

     

    but then you have the problem with different characters taking up different amounts of space, i think you might need to look into using javascript or jquery etc?

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