rotten69 20 Posting Whiz

Thanks for that.

rotten69 20 Posting Whiz

Hey everyone,

I have just uploaded my php files onto a free hosting server and tried to access the website. I got this error " mysql_fetch_array() expects a resource in parameter 1" or something like that. By the way, the files did work on my local machine.

What is the problem? and how do I go about fixing it?

rotten69 20 Posting Whiz

To answer your question, here is an example. I hope the example I'm giving will help you.

<?php


$name = "Dani";

if($name== "Dani"){
    echo $name;         => this will output Dani
    $name .= " Web";    => this will concatenate the string " Web" to the "Dani"
}

echo $name;    => this will output "Dani Web"


?>
rotten69 20 Posting Whiz

That is an example of what I am using... Once the page is loaded, click twice on the page. you will see the footer disappear. Any idea to why this is happening?

rotten69 20 Posting Whiz

Hi everyone,

I'm making my first jQuery mobile app and using a fixed bottom navbar. But the app is acting a little weird. When I tap the background twice, the navbar disappears or moves up a little. how can I fix this problem?

rotten69 20 Posting Whiz

That works exactly the same as the if-statement that I had but it still causes the same error which is not changing the URL to index.php and users can still view the content of it.. I just took out the jQuery files out and it seems to work fine without them. I guess the problem is caused by jquery mobile or jquery..

rotten69 20 Posting Whiz

How can I determine how many lines of text to display in JS? Let's say I want to show users 3 lines of text and if they want to see more, they will toggle the div.

rotten69 20 Posting Whiz

Yeah, on the home page, I have got a session variable that checks whether users are logged in or not. What I am facing though is that once they go to the login.php and log in successfully. Then they are redirected to the home page and can view the content of it, but the url doesn't change to home.php and unfortunately stays as log_in.php which is the script being written in the first post. This is what I have got in the login.php page. Nah, I didn't do any checking for the session variables on it yet. It is wierd to have the URL changed when users log in or out. I never had this problem ever. Do you think jQuery for mobile is causing it?

<?php 

session_start();

?>
<!DOCTYPE html>

<html lang="en">

<head>

    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" >

     <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.css" />
    <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js"></script>    

</head>



<body>



<div data-role="header"> 
    <h1>Login</h1>
</div>


<div>


</div>

    <form action="log_in.php"  method="POST" >

            <label for="username"> <input type="text" name="username" id="username" placeholder="Username"> </label>
            <label for="password"> <input type="password" name="password" id="password" placeholder="Password"> </label>

    <input type="submit" value="log in">



    </form>




</body>




</html>
rotten69 20 Posting Whiz

I'm using jQuery for mobile and making the app show users a dailog box to let them enter their credentials when they want to log into the app. Ok. it redirects them to the home page but the url stays as mysite.com/login.php rather than mysite.com/index.php This removes the menu bar on the bottom but it appears if the page is refreshed which I don't want my users to do. Since I'm using a dialog box for the log in page, how would I display any errors if username/password isn't correct? If I do though, they will be redirected to the actual login.php page and dialog box disappears.

Why is that ? any help will be appreciated. Thank you.

 <?php
include('funcs/connector.php');
$port = new MySqlDatabase();
$port ->connect('root','','myDB') or die(mysql_error());
session_start();


$user = mysql_real_escape_string($_POST['username']);
$pass = mysql_real_escape_string($_POST['password']);

$query = "SELECT username, password FROM USERS WHERE `username` = '$user' AND `password`='$pass' ";
$result = mysql_query($query) or mysql_error();

$row = mysql_fetch_assoc($result);

if( $username == $row['username']){
    $_SESSION['username'] = $row['username'];
    header('Location:index.php');
}else{
    echo "this is wrong";
}
rotten69 20 Posting Whiz

Now, it redirects to the index.php but it doesn't change the url to index.php. So the url stays as login.php.

rotten69 20 Posting Whiz

Ah, I know where the problem is. Instead of compairing $user == $row['username'], I was compairing $username == $row['username'] which in this case $username is not defined.

rotten69 20 Posting Whiz

Hey everyone,

I'm having trouble to get this code to work as I wanted. My application is running on the top jQuery for mobile framework. The message I'm getting is this "undefined". I enter the right username and password but don't know what is undefined.

<?php

include('funcs/connector.php');
$port = new MySqlDatabase();
$port ->connect('root','','deco3500') or die(mysql_error());

session_start();


    $user  = mysql_real_escape_string($_POST['username']);
    $pass  = mysql_real_escape_string($_POST['password']);
    $query = "SELECT username, password FROM USERS WHERE `username` = '$user' AND `password`='$pass' ";
    $result = mysql_query($query) or mysql_error();

    $row = mysql_fetch_assoc($result);


    if( $username == $row['username']){
        $_SESSION['username'] = $row['username'];

        header('Location:index.php');

    }else{

        echo "this is wrong";
    }

?>

rotten69 20 Posting Whiz

I get it to work and display the date when the selection 3 or 4 is active then I can't hide it when they aren't active.

rotten69 20 Posting Whiz

Hey there,

I'm just having a tiny problem with this function. the toggle function works fine but what I want to do is to display the date whenever particular buttons are clicked or active.

        function showDate(element){
            if(element == "#selection3" || element == "#selection4"){
                document.getElementById("dateinput").style.visibility = "visible";
            }else{
                document.getElementById("dateinput").style.visibility = "hidden";
            }
        }


        function toggle_element(element){s
                    $(element).toggle();    
        }



                <input id="toggle_button" type="button" value="Number of players per game" onclick="toggle_element('#selection1');">
            <div id="selection1" style="display:none;">
                 <div id="container1" style="width: 75%; height: 400px; margin-left: 1%; margin-right:10%; "></div>
                 <p></p>
            </div>

                <input id="toggle_button" type="button" value="Score vs Age" onclick="toggle_element('#selection2');">
            <div id="selection2" style="display:none;">
                 <div id="container2" style="width:75%; height: 400px; margin-left: 1%; margin-right:10%; "></div>
                 <p></p>
            </div>



                <input id="toggle_button" type="button" value="Number of games played per day" onclick="toggle_element('#selection3');">
            <div id="selection3" style="display:none;">
                 <div id="container3" style="width: 75%; height: 400px; margin-left: 1%; margin-right:10%; "></div>
            <p></p>
            </div>


            <div id = "dateinput"  >
            Start Date:<input type="text" onfocus="showCalendarControl(this);" id = "start_date" name = "start_date" value = "2012-10-01" onchange= "">
            End Date:<input type="text" onfocus="showCalendarControl(this);" id = "end_date" name = "end_date" value = "2012-10-25" onchange= "">

            <input type="submit" value="Update" onClick= "graph_chosen()">
        </div>

I want to display the date whenever selection 3 is active only. I'd appreciate quick help with this

rotten69 20 Posting Whiz

Even though it is an easy task, we still need to have a look at your work you've done. I will get you started on that one. Next time, do post your code that you have trouble with.

for( int i=0; i<150; i++){
    System.out.println("the output is  " + i);
}

Try playing around with this snippet until you get your head around it. To explain it, the variable i starts at 0 and increases by one every time it enters the loop.

I hope that helps.

rotten69 20 Posting Whiz

The problem was that no data was being passed to the stuff in the for-each loop.This thread is solved.

rotten69 20 Posting Whiz

any idea on how to resolve the issue in the code?

rotten69 20 Posting Whiz

hey guys,

I don't seem to understand why this code is throwing a type error at me. It is saying the variable is undefined. The error I'm getting is this

TypeError: datasplits is undefined
datasplit2s = datasplits.split(":");

var urlphp = 'ajaxgamesperday.php?&start_date=' + startDate + '&end_date=' + endDate;
                $.ajax({
                    url: urlphp,
                    success: function(data) {
                        // Original format "2000-00-00"
                        var formatted_startDate = startDate.replace(/-/g, ",");
                        var formatted_endDate = endDate.replace(/-/g, ",");
                        var startdatearray = formatted_startDate.split(",");
                        var enddatearray = formatted_endDate.split(",");
                        //Format now is "2000,00,00"
                        var sy = parseInt(startdatearray[0]);
                        var sm = parseInt(startdatearray[1],10) - 1;
                        var sd = parseInt(startdatearray[2]);
                        var ey = parseInt(enddatearray[0]);
                        var em = parseInt(enddatearray[1],10) - 1;
                        var ed = parseInt(enddatearray[2]);

                        options = {
                            chart: {
                                renderTo: 'container3',
                                type: 'bar'
                            },
                            xAxis: {
                                type: "datetime"
                            },
                            yAxis: [{
                                min: 0,
                                allowDecimals: false,
                                title: {
                                    align: 'high'
                                },
                                labels: {
                                    overflow: 'justify'
                                }
                            }],
                            tooltip: {
                                formatter: function() {
                                    return ''+
                                    Highcharts.dateFormat('%e. %b', this.x)+ ': '+ this.y + ' games played';
                                }
                            },
                            plotOptions: {
                                bar: {
                                    dataLabels: {
                                        enabled: true
                                    }
                                }
                            },
                                legend: {
                                },
                                 credits: {
                                    enabled: false
                                },
                                series: [{
                                        name: 'Complete games',
                                        data: [],
                                    },
                                    {
                                        name : 'Incomplete games',
                                        data: []
                                }]
                        };

                        dataremovebrackets = data.slice(1,-1);
                        dtsplit = dataremovebrackets.split(",");
                        $.each(dtsplit, function(date,value) {
                            var datasplit = value.split("'");
                            var datasplits = datasplit[0].slice(1);
                            var datasplit2s = datasplits.split(":");
                            var formatted_date = datasplit2s[0].replace(/-/g, ",");
                            var xval = formatted_date.split(",");
                            var x = Date.UTC(xval[0], xval[1] - 1, xval[2]);

                            if (datasplit2s[1] != 0) {
                                options.series[0].data.push([x,parseFloat(datasplit2s[1])]);
                            }

                            datasplits = datasplit[1];
                            datasplit2s = datasplits.split(":");
                            formatted_date = datasplit2s[0].replace(/-/g, …
rotten69 20 Posting Whiz

WOOOT, What is that? A question, answer or an intro about yourself?

rotten69 20 Posting Whiz

it is a text file format (.txt). Primarily, I need to integrate all the file formats mentioned in the first post.

Cheers,

rotten69 20 Posting Whiz

@sss93... Does that make sense?

rotten69 20 Posting Whiz

the file format is as mentioned in the first post. if that's what you're asking?

rotten69 20 Posting Whiz

I previously thought you were defining a custom method. I'd go with the following code.

if(isset($_SESSION['username']) ){
    do something;
}
rotten69 20 Posting Whiz

OK. Since the code isn't posted to see how things are structured, I can give a hint how you can achieve this.

I'm assuming you've set up your database tables and the script to retrieve the data from the tables. Store the data retrieved from the database in an associate array inside a function so it will be easy to call it in your other files. Then, access the indexed data that was stored in the array.

In your html code, you'd have something like this.

<select>

<option> <?php echo $arrayOfData['q1'] ?> </option>
<option> <?php echo $arrayOfData['q2'] ?></option>
<option> <?php echo $arrayOfData['q3'] ?></option>
</select>

that all depends on how many q's you've got. if they're more than 5, you're better off using a for-loop. Just a thought.

rotten69 20 Posting Whiz

Apparently, you don't have a function called session_is_registered.In the case that it is defined in another file in the same directory, then add this line in the top of the page

include("YourFileName.php");

I hope this helps.

rotten69 20 Posting Whiz

Thank you for the replies.

One of the files contains about 3000 records or more. What is a possible way of importing them all into the database using SQL command line? Because it is time-consuming to go through each record and add this line "INSERT INTO table_name ........" to it.

rotten69 20 Posting Whiz

Can anyone post links to online tutorials or something that I can read on? cheers

rotten69 20 Posting Whiz

Hi there,

I'm supposed to integrate different sources of data into one database. I am given these types of sources:

  • .txt
  • .csv
  • .html
  • .xls
  • access file as well.

what attributes should I be looking at to construct a global schema because all of them have different attributes? But I can say there are a few things in common between them like name, DOB, Country, CountryName.

A few hints on how to approach it will be good. Any useful website that illustrates or explains well the concepts would be awesome.

Thank you.

rotten69 20 Posting Whiz

I get the second step. For the first one though, how could you determine the number of lines to display? is there an example you can refer me to?

rotten69 20 Posting Whiz

Is that an easy job? I mean a function or two in jquery becuase I'm designing the app for smart devices.

rotten69 20 Posting Whiz

Hey everyone,

I'm just wondering how the read more feature is achieved in PHP. It is like facebook where it displays a couple of lines then if you're interested in reading more about the status or article click 'read more link' which expands the box.

Cheers,

rotten69 20 Posting Whiz

I wanted to call a function from the xxx.php which let's assume has these functions:

function check_user($username, $password){
}

function delete(){
}

function log_out(){
}

None of these functions includes the header function to redirect users. So in my login.php after the valdiation is successful, users will be redirected to index.php

inside my login.php, I have something not simple like this though :)

<?php
include("xxx.php");

 if(isset($username, $password){
     check_user($username,$password);
     header("Location:index.php");
     die();
 }
?>

<form action="" method="POST">
   username
   password
</form>

make sense?

The problem is that it concatnates the url from header function to the current url. So you're on login.php, it will add #index.php => login.php?#index.php

rotten69 20 Posting Whiz

maybe unauthorised user finding an url like delete.php?id=3 in the browser history and changing IDs by hand or programatically

How could they do that? They don't have access to my files on the server.I guess if they try accessing delete.php?id=3, they will be rejected because a session is not set which means they need to log in.

@iamthwee... PHPacademy is my favourite youtube channel.

rotten69 20 Posting Whiz

@blocblue.. Thanks for the reply. My answer is precise to the question. PHP code will NEVER run in HTML file unless technology has evolved ?? Just to be sure, I tested putting PHP code in HTML file that is living on web server. It didn't work.

rotten69 20 Posting Whiz

@broj1.. Thanks for the suggestion. Tell me more about the security side. More on how to secure the app. Or even referring me to websites that you think useful..

rotten69 20 Posting Whiz

@blocblue Thanks for the help anyway.

rotten69 20 Posting Whiz

You were checking if the username was equal to the boolean returned by isset(),

No way. This can't be true. Well, actually I was echoing a variable that was supposed to store the username value. But, it was giving 1 instead of the name of the user logged in.

rotten69 20 Posting Whiz

Yeah, you're correct. I have included the file containing the functions.But in the form attribute 'action', I left it empty. I've just realised the first post wasn't so sensible. OK. I worte it really fast because I was in a hurry.

rotten69 20 Posting Whiz

Hello everyone,

I'm just wondering if there is another of calling functions in a different php file without making the app run strangley. So what I have got are a few forms without specifying their action.

<?php
   1- checking for the fields 
   2-  if they are not empty and so on, a function in functions.php will be called then users will be redirected from this page not  from  the functions.php because I am using some functions in different ways.
?>


<form action="" method="post">

fields stuff
</form>

when I redirect users from login.php to index.php, it adds a hash at the end of the url. E.g localhost/login.php#index.php or something like this.

Is there a way I can solve this easily without specifying action for forms? or specify action to trigger the right function maybe?

rotten69 20 Posting Whiz

Woot woot. That is ridiculous. Am I missing that simple logic? LOL at myself. BTW, I don't see so much difference between what I have done and what you've tweaked up there.

they sound pretty much the same. In my solution, if the user is set then do a little more checking to see if the username is equal to the username in the database.

rotten69 20 Posting Whiz

Like simplypixie said, You won't be able to run PHP code within HTML files (e.g index.html) so the files have to be with the extension of .php (e.g index.php). The reason being is that you're telling the browser to interpert PHP code within HTML which doesn't make sense to the borswer. It will render it as a simple text. However, if you do it the other way around, it will render html code within your php file without any issue.

I hope this helps you a little. If you post your code here so we can have a look and tell you if it is broken or not.

@blocblue: why is that incorrect?

simplypixie commented: Much better explanation than mine :-) +7
rotten69 20 Posting Whiz

With my script, I could call the decode_json function in php which basically takes an array and converts to JSON format. I was able to get the data passed to AJAX function in my JS. Although, the series object in highcharts didn't make sense so I didn't know how to pass the data to it.

rotten69 20 Posting Whiz

That didn't work for me. I try checking if the username in a session is equal to the name in the database table, then they'll get the edit/delete buttons.

 if($user_session = isset($_SESSION['username'])){
                        if ( $post['username'] == $user_session){
                            echo "<a href='delete.php?id=" .$post['id'] ."'> Delete</a>";
                            echo "<a href='edit.php?id="   .$post['id'] ."'>  Edit</a>";
                        }
                    }

That didn't work for me. Any idea why?

rotten69 20 Posting Whiz

Cheers for the suggestion, blocblue.

rotten69 20 Posting Whiz

is that how it's normally configured? I thought you'd have a for-loop in the JavaScript code to loop through the data you're getting from the DB.

rotten69 20 Posting Whiz

Excellent. I will see if that works well. Thank-you.

rotten69 20 Posting Whiz

For some reason, the mail function isn't working.

rotten69 20 Posting Whiz

At the moment, I'm using google jquery online files.

rotten69 20 Posting Whiz

Cheers for taking the time to explain this to me and others.

rotten69 20 Posting Whiz

Can anyone help with the charts? I'm so desparate.