Jump to content

Buddski

Members
  • Posts

    1,236
  • Joined

  • Last visited

Posts posted by Buddski

  1. echo "
    
    <form action=\"config.php\" method=\"post\"><br />
    <input name=\"checkbox\" value=\"Enable music requests\" type=\"submit\" /><br /><br />
    <input name=\"checkbox2\" value=\"Disable music requests\" type=\"submit\" />
    </form>
    <form name=\"input\" action=\"process2.php\" method=\"post\">
    DJ Message:<br /> <input type=\"text\" size=\"50\" maxlength=\"200\" value=\"".file_get_contents("djmessage.txt")."\"  name=\"checkbox3\" />
    <input type=\"submit\" value=\"Update\" />";

  2. I have no idea what you are trying to do there.. Can you show the WHOLE snippet of code, not just that half line..

    It looks like you are opening php tags inside, what I presume to be, an echo statement.

     

    If you are wanting to use that text file as the value of a HTML element use file_get_contents(), but without seeing the rest of the code I cant help with implementing it.

  3. Well, to start with your counting for the replies would never have really worked, you dont need to store them in the database at all!!

    Here is a little query you can use on your main_forum.php

    SELECT `forum_question`.*, COUNT(`forum_answer`.`a_id`) as `replies` 
    FROM `forum_question` 
    Left Join `forum_answer` ON `forum_answer`.`question_id` = `forum_question`.`id` 
    GROUP BY `forum_question`.`id` 
    ORDER BY `forum_question`.`id`

  4. My guess is this part is failing and returing 1

    // Find highest answer number. 
    $sql="SELECT MAX(a_id) AS Maxa_id FROM $tbl_name WHERE question_id='$id'";
    $result=mysql_query($sql);
    $rows=mysql_fetch_array($result);
    
    // add + 1 to highest answer number and keep it in variable name "$Max_id". if there no answer yet set it = 1 
    if ($rows) {
    $Max_id = $rows['Maxa_id']+1;
    }
    else {
    $Max_id = 1;
    }

    As a suggestion, you could remove this code altogether if you set a_id to auto-incrementing, then you will never have to pass a value to a_id. Why do all the work when MySQL can do it for you.

  5. Instead of just writing ERROR write something a little more useful.

    echo "ERROR" , mysql_error();

     

    I have also notices that you are setting $tbl_name to 'forum_answer'

    Then run this query

    $sql2="INSERT INTO $tbl_name(question_id, a_id, a_name, a_answer, a_datetime)VALUES('$id', '$Max_id', '$a_name', '$a_answer', '$datetime')";

    But according to you database structure forum_answer does not contain any of those columns..

     

  6. You could also split your responseText using a \n I guess.

    For example, your AJAX would return something like

    <img src="1.jpg">
    <img src="2.jpg">

    and then using javascript to split it..

    var parts = xmlhttp.responseText.split("\n");

    part[0] would contain <img src="1.jpg"> and part[1] would contain <img src="2.jpg">

     

    Or..something (its 1:30 and I have to bee up in 6hrs for work so im a little scattered)

    The only other way would be to return a javascript object which you would more than likely have to eval() to make it usable.

  7. This is my most hated thing.. dates.

    25/10/2011 can either be read as "The 25th day of the 10th Month" (Aussie dates) or "The 10th day of the 25th Month"

    PHP has decided to choose the latter, which isnt a real date thus returning a 0 for strtotime.

  8. You COULD just do

    $_SESSION['SESS_FIRST_NAME'] = $fname; // do this for each of the posted elements that need to be reset //

    After your query has succeeded..

     

    I have also notices that you arent escaping your database inputs, you definitely should

    mysql_real_escape_string()

    The last thing you need is somebody attacking your site via SQL Injection.

  9. It doesn't mean you should always use FILTER_FLAG_NO_ENCODE_QUOTES with mysql_real_escape_string, it all depends on the application.

    How you want the data stored etc, some cases may call for the encoded quotes to be stored in the databases others maybe not.

    I always use mysql_real_escape_string on all database inputs regardless of prior filtering/cleaning methods.

  10. You will have to do some pretty complex coding to create a picture. You will almost have to write your own "browser" but instead of outputting HTML you will be outputting a picture.

     

    The hint that was given to you is probably the easiest way to do it.. create a "preview" area that cannot be clicked or used in anyway.

  11. My function didnt do anything because I missed the echo statement.

    I will explain your echos below:

    (1) => This is because $num_rows is 1 and will always be 1 as you are using a COUNT(*);

    Resource id #11 => This is because, as I already stated, $sql_pm_r contains a MySQL Resource, NOT actual results.

    USERNAME => Pretty self explanatory.

     

    thorpe is talking about your use of global $user;, instead of global you should pass in the variable into the function.

     

    function unread($user) {
    $sql_pm_r = mysql_query("SELECT `id`, COUNT(*) as `unread` FROM `messages` WHERE reciever='" . $user . "' AND recieved='0' GROUP BY `reciever`") or die(mysql_error());
    $rows = mysql_fetch_assoc($sql_pm_r);
    
    if ($rows['unread'] > 0) {
    	$pms = '<a href="inbox.php" >('.$rows['unread'].')</a>';
    } else {
    	$pms = '<a href="inbox.php" >(0)</a>';
    }
    echo $pms;
    }
    // Then to call the function use:
    unread($user);

  12. Have you checked for errors in your second query?

    And echoing $sql_pm_r will be of no use to you..

     

    Try this.

    function unread() {
    global $user;
    $sql_pm_r = mysql_query("SELECT `id`, COUNT(*) as `unread` FROM `messages` WHERE reciever='" . $user . "' AND recieved='0' GROUP BY `reciever`") or die(mysql_error());
    $rows = mysql_fetch_assoc($sql_pm_r);
    
    if ($rows['unread'] > 0) {
    	$pms = '<a href="inbox.php" >('.$rows['unread'].')</a>';
    } else {
    	$pms = '<a href="inbox.php" >(0)</a>';
    }
    }

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