phorce 131 Posting Whiz in Training Featured Poster

Sign :(!

Try this, change your form values so it has 0 or 1. 0 = false, 1 = true

<?php


    $option = $_POST['option'];

    if(!isset($option))
    {
        echo 'You have not submitted an option';
    }

    switch($option)
    {
        case 0:
            // FALSE
            echo 'This is false';

        break;

        case 1:
             // TRUE
             // re-direct to link 1;
            $new_link = "index.php";
            echo 'This is true';
        break;

        default:
            echo 'Invalid option';
        break;
    }


?>

E.g.

<form method="post">
        <input type="radio" name="option" value="1">True</option>
        <input tpe="radio" name="option" value="0">False</option>
        <input type="submit" name="submit" value="Go!">

Hopefully this will work, let me know!

phorce 131 Posting Whiz in Training Featured Poster

I've never done this in PHP, but, by 'Binary', i'm guessing that you're trying to parse a binary image? (I.e. black and white)?

phorce 131 Posting Whiz in Training Featured Poster

Look at the syntax, if you have to explain what the script does, then it's pretty self-explanatory.. I cannot do your work for you, that wouldn't be fair and I'm sure you actually want to learn something ;) I'll help you a bit though:

  1. Explain what PHP is
  2. Explain the code you've written (So it retrives data from a table inside a database)
  3. Explain each line of code:

    $connect=mysql_connect("localhost","root","");
    $db_selected = mysql_select_db("ong_assessment", $connect);

This code establishes a connection with the database on the server. The mysql_connect accepts three parameters. The mysql_select_db attempts to select the database that data will be retrived from. It accepts two parameters, one is the name of the database and the other is the connection variable.

...

...

...

Something like this :)

phorce 131 Posting Whiz in Training Featured Poster

Yes, but, try and solve the problems yourself :)! But, you're welcome to post here and we'll help you.

If this is solved, please mark it as solved and give rep to those who helped!

Good luck

phorce 131 Posting Whiz in Training Featured Poster
<head>
</head>
<body>
<table border='1'>
<tr>
<th>Agent_ID</th>
<th>Address</th>
<th>Bedrooms</th>
<th>Price</th>
<?php
$connect=mysql_connect("localhost","root","");
$db_selected = mysql_select_db("ong_assessment", $connect);
$query = "SELECT Agent_ID,Address,Bedrooms,Price FROM suburbs";
$result = mysql_query($query) or die(mysql_error());
if(!mysql_affected_rows() >= 1)
{
echo 'There are no entries inside the database';
}

while($row = mysql_fetch_array($result))
{
echo '<tr>';
echo '<td>'. $row['Agent_ID'].'</td>';
echo '<td>'. $row['Address'].'</td>';
echo '<td>'. $row['Bedrooms'].'</td>';
echo '<td>'. $row['Price'].'</td>';
}
echo '</table>';
?>
</body>
</html>

Better? They're no longer constants (:

phorce 131 Posting Whiz in Training Featured Poster

Yes, your script is wrong. I posted an altered version the script that fixed the errors you had.

phorce 131 Posting Whiz in Training Featured Poster

LOOK at the syntax..

<head>
</head>
<body>
<table border='1'>
<tr>
<th>Agent_ID</th>
<th>Address</th>
<th>Bedrooms</th>
<th>Price</th>
<?php
$connect=mysql_connect("localhost","root","");
$db_selected = mysql_select_db("ong_assessment", $connect);
$query = "SELECT Agent_ID,Address,Bedrooms,Price FROM suburbs";
$result = mysql_query($query) or die(mysql_error());
if(!mysql_affected_rows() >= 1)
{
echo 'There are no entries inside the database';
}

while($row = mysql_fetch_array($result))
{
echo '<tr>';
echo '<td>'. $row[Agent_ID].'</td>';
echo '<td>'. $row[Address].'</td>';
echo '<td>'. $row[Bedrooms].'</td>';
echo '<td>'. $row[Price].'</td>';
}
echo '</table>';
?>
</body>
</html>

Now, if the output is: 'There are no entries inside the database' then there are no records in the table 'suburbs'. There are NO errors now, don't create errors for yourself.

phorce 131 Posting Whiz in Training Featured Poster

Please post your script, how it looks now.. Removing any passwords etc..

phorce 131 Posting Whiz in Training Featured Poster

Now you have to insert data, for the data to be shown :) Do you use mysqladmin? If so, you can just throw some example data in just to test!

phorce 131 Posting Whiz in Training Featured Poster

Ok, try this:

where you have:

mysql_select_db("ong_assesment",$connect);

change it to:

$db_selected = mysql_select_db("ong_assesment", $connect);

Making sure, your database name is called "ong_assesment".

phorce 131 Posting Whiz in Training Featured Poster

Is there a database called "ong_assesment"

phorce 131 Posting Whiz in Training Featured Poster

I don't think you're understanding me.. I asked is there an error message showing, NOT what text editor you're using... Ok, try this:

<html>
<head>
</head>
<body>

<table border='1'>
<tr>
<th>Agent_ID</th>
<th>Address</th>
<th>Bedrooms</th>
<th>Price</th>
<?php
$connect=mysql_connect("localhost","root","");

mysql_select_db("ong_assesment",$connect);
$query = "SELECT Agent_ID,Address/Suburb,Bedrooms/Bathrooms,Price FROM suburbs";
$result = mysql_query($query) or die(mysql_erro());

if(!mysql_affected_rows() >= 1)
{
    echo 'There are no entries inside the database';
}
while($row = mysql_fetch_array($result))
{
    echo '<tr>';
    echo '<td>'. $row[Agent_ID].'</td>';
    echo '<td>'. $row[Address].'</td>';
    echo '<td>'. $row[Bedrooms].'</td>';
    echo '<td>'. $row[Price].'</td>';
}
    echo '</table>';

?>
</body>
</html>

Do you get the output: There are no entries inside the database? OR do you get something else?

phorce 131 Posting Whiz in Training Featured Poster

Is there an error showing? Is there anything in the table?

phorce 131 Posting Whiz in Training Featured Poster

Try this, bit different to your script.. Have a look at yours, you have many errors:

<html>
<head>
</head>
<body>

<table border='1'>
<tr>
<th>Agent_ID</th>
<th>Address</th>
<th>Bedrooms</th>
<th>Price</th>
<?php
$connect=mysql_connect("localhost","root","");

mysql_select_db("ong_assesment",$connect);
$query = "SELECT Agent_ID,Address/Suburb,Bedrooms/Bathrooms,Price FROM suburbs";
$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result))
{
    echo '<tr>';
    echo '<td>'. $row[Agent_ID].'</td>';
    echo '<td>'. $row[Address].'</td>';
    echo '<td>'. $row[Bedrooms].'</td>';
    echo '<td>'. $row[Price].'</td>';
}
    echo '</table>';

?>
</body>
</html>

e.g. in yours you have:

mysql_select_db("ong_assesment',$connect);

should be:

mysql_select_db("ong_assesment",$connect);

Hope this helps

phorce 131 Posting Whiz in Training Featured Poster

Sorry for late reply.

This is working perfectly fine for me:

<?php

    $option = (bool) $_POST['option'];

    if(!isset($option))
    {
        echo 'You have not submitted an option';
    }

    switch($option)
    {
        case 1:
        // re-direct to link 1;
            $new_link = "index.php";

        break;

        case 2: 
        // re-direct to link 2:
            $new_link = "test.php";
            include($new_link);
        break;

        default:
            echo 'Invalid option';
        break;
    }


?>

Or alternatively, try this (all one file):

<?php

    if(!isset($_POST['submitted']))
    {
        // form hasn't been submitted
        echo '
        <form method="post">
        <input type="radio" name="option" value="TRUE">True</option>
        <input tpe="radio" name="option" value="FALSE">False</option>
        <input type="submit" name="submit" value="Go!">
        <input type="hidden" name="submitted" value="TRUE">
        ';

    }else{

      switch($option)
      {
            case 1:
                // re-direct to link 1;
                $new_link = "index.php";

            break;

            case 2: 
            // re-direct to link 2:
                $new_link = "test.php";
                include($new_link);
            break;

            default:
                echo 'Invalid option';
            break;
        }
    }


?>

I realised SESSIONS were a bad idea since we were recoding the data, so, it would always remember it!

phorce 131 Posting Whiz in Training Featured Poster

Also, why are these:

int one_1 = 1776;
int two_1 = 1999;
int three_1 = 2012;
int launch_1 = 138974;

not constants?

Also, if this is now solved, please mark as solved.

phorce 131 Posting Whiz in Training Featured Poster

I don't get what you mean. Ok, so, the form SHOULD display everytime the user visits this webpage? If that's the case, I don't know exactly why we're storing the value as a session. Could you give me an example of how you want the form, maybe I could create it for you? Just a suggestion. Write our your specifications etc..

phorce 131 Posting Whiz in Training Featured Poster

P.S. There are a lot of variables.. Like:

int one;
    int two;
    int three;
    int launch;
    int one_1 = 1776;
    int two_1 = 1999;
    int three_1 = 2012;
    int launch_1 = 138974;

Couldn't these be in some kind of an array?

phorce 131 Posting Whiz in Training Featured Poster

I don't get what you mean by 'resets' itself. Do you want it to remember what the option was so when the user re-visits the page, it will remember what the option was? If so, do this:

<?php
    ob_start();
    session_start();

    if(!isset($_SESSION['option']))
    {
        $a = (bool) $_POST['option'];
    }else{
        $a = $_SESSION['option'];
    }

    if($a)
    {
        $a = "index.php";
        // redirect OR include $a
        $_SESSION['option'] = true;
    }else{
      include ('test.php');
      $_SESSION['option'] = false;
    }


?>
phorce 131 Posting Whiz in Training Featured Poster

I don't get what you mean..

You can't set $a = index.php and expect true or false, only if it's a weird function and it's returning either true/false.. So I think you mean:

<?php

  $a = (bool) $_POST['option']; // this will either store true/false
  if($a)
  {
     $a = "index.php";
     // redirect OR include $a
  }else{
    include ('test.php');
  }
?>
phorce 131 Posting Whiz in Training Featured Poster

Ok - Can you tell us what else needs to be done? I'm confused!

phorce 131 Posting Whiz in Training Featured Poster

Hey @coolikedat99 - Without getting negative feedback. I would look at using a more OO (Object-Oriented) approach, for me, there's quite a lot of code in main, probably more than there needs to be. Also, your use if IF statements could be replaced with SWITCH statements if and when needed.

phorce 131 Posting Whiz in Training Featured Poster

Just a quick question.. (I'm very tired so might be missing the point)!

But if I had this code:

<?php 
global $json_news;
var_dump($json_news);
echo"<br/>=======================<hr/>";
?>

It would return NULL because although you are defining $json_news as a global, you're not setting it as anything.. Surely, your function whats to return the array and then you assign the output of the function to this global variable? In other words, your function "show_news()" might return something..

Kinda like this:

<?php 

function show_news(){
     $json_news = array(
                "id" => 0,
                "title" => ""
            );

    return $json_news;
}

global $json_news;

$json_news = show_news();
var_dump($json_news);

?>

// output
// output
array(2) {
  ["id"]=>
  int(0)
  ["title"]=>
  string(0) ""
}

I'm very tired though, might be missing the point!

phorce 131 Posting Whiz in Training Featured Poster

Is this solved now?

phorce 131 Posting Whiz in Training Featured Poster

try:

  <form method="post" action="test2.php">
    <input type="radio" name="option" value="TRUE">True</option>
    <input tpe="radio" name="option" value="FALSE">False</option>
    <input type="submit" name="submit" value="Go!">
phorce 131 Posting Whiz in Training Featured Poster

Harsh negative feedback, if I'm honest. People learn differently.

WaltP commented: And have you proven he learns better by being given the answer? +0
phorce 131 Posting Whiz in Training Featured Poster

Hey, try this:

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
    int one;
    int ran_num;

    time_t seconds;
    time (&seconds) ;
    srand((unsigned int) seconds);
    ran_num = rand();
    cout << ran_num << endl;

    cout<<"Enter this number: ";
    cin>> one;
    if (one == ran_num) {
    cout<<"\nSparta\n";
    }else{
        cout << "Not the right number:(!";
    }
}

Store the random number inside a variable, then you can compare it!

WaltP commented: Don't just fix code for someone. *Help* them fix the code themselves -3
phorce 131 Posting Whiz in Training Featured Poster

What is the error?

phorce 131 Posting Whiz in Training Featured Poster

Hey, I think I get what you mean:

Let's say your radio button had the name of "option" and a value of either true/false

<?php

  $a = $_POST['option']; // this will either store true/false
  if($a)
  {
     echo 'a is true';
     //print ("A is true");
  }else{
    include ('test.php');
  }
?>

Hopefully this makes sense :)

Also, a note to when using the operator ">" this implies you mean more-than, but, boolean cannot be more than true.. It can simply be true or false (1 or 0).

phorce 131 Posting Whiz in Training Featured Poster

Aha, please forgive me.. If everything is working fine when you access XICS.php then the problem isn't there ;) post process_login.php! Apologies :)

phorce 131 Posting Whiz in Training Featured Poster

Do you mean inheritence?

Inheriting methods from one class to another.

phorce 131 Posting Whiz in Training Featured Poster

Please re-post XICS.php again, with the fixes, exactly how it is with the error :)

phorce 131 Posting Whiz in Training Featured Poster

Are you re-delcaring the function and including "functions.php"?

Please post the script in which you get this problem on.. I don't see the problem in the script you've just posted above..

phorce 131 Posting Whiz in Training Featured Poster

Pardon?

Ok, to me you have included the "functions.php" file and initalised the sessions in the wrong place.. It needs to be delcared at the top of the script, before anything else.. So, the code I posted, should now work?

vishalonne commented: 3 +2
phorce 131 Posting Whiz in Training Featured Poster
<?php
include "functions.php";
sec_session_start();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    <title>cbse cs n ip - Anything regarding CBSE XI and XII Computer Subjects</title>
        <meta name="description" content="Latest IP NOTES,SAMPLE PAPERS,PRACTICAL & Project FILE OF IP" />
        <meta name="keywords" content="cbse cs and ip,11 cbse,11 cbse sample papers," />

        <link href="css/other.css" rel="stylesheet" type="text/css" />  
        <link href="css/other2.css" rel="stylesheet" type="text/css" />
        <link rel="stylesheet" type="text/css" href="csshorizontalmenu.css" />
        <script type="text/javascript" src="csshorizontalmenu.js"></script>
        <script type="text/javascript">
            var _gaq = _gaq || [];
            _gaq.push(['_setAccount', 'UA-34001071-1']);
            _gaq.push(['_trackPageview']);
            (function() {
                var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
                ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
                var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
            })();
        </script>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
     /*$(document).ready(function() {
      $('#ul1 li a').click(function(e) {
       e.preventDefault();
       $('#content').load($(this).attr('href'));
      });
     });*/
     $(function(){
        $('#ul1 li a').on('click', function(e){
            e.preventDefault();
            var page_url=$(this).prop('href');
            $('#content').load(page_url);
        });
    });
    </script>
    <body>
        <div id="main_container">
            <div id="container">
                <div id="banner_container">
                    <div id="login_container">
                        <span class="style1" >Email or Phonee</span>                                    <span class="style1" >Password</span>  <br />                    <input type="text" id="Text1" class="box" />                    <input type="password" id="Password1" class="box" />                    <input id="Submit1" type="submit" value="Log In" /><br />                    <span class="style1" >Forgot your password?</span>                </div>
                <div class="horizontalcssmenu">                <ul id="cssmenu1">                    <li style="border-left: 1px solid #202020;"><a href="http://www.cbsecsnip.in">Home</a></li>                    <li><a href="#">Computer Science</a>                        
    <ul>                            
    <li><a href="http://www.cbsecsnip.in/csnip/XICS.php">XI</a></li>                            
    <li><a href="http://www.cbsecsnip.in/csnip/XIICS.php">XII</a></li>                        
    </ul>                    
    </li>                    
    <li><a href="#">Informatics Practices</a>                        
    <ul>                            
    <li><a href="http://www.cbsecsnip.in/csnip/XIIP.php">XI</a></li>                            
    <li><a href="http://www.cbsecsnip.in/csnip/XIIIP.php">XII</a></li>                        
    </ul>                    
    </li>                    
    <li><a href="http://www.cbsecsnip.in">Take Test</a></li>                    
    <li><a href="http://www.cbsecsnip.in">Software</a></li>                    
    <li><a href="http://www.cbsecsnip.in">Register</a></li>                    
    <li><a href="http://www.cbsecsnip.in">Get Together</a></li>
                    </ul> …
phorce 131 Posting Whiz in Training Featured Poster

@vishalonne

In that file, are you including/requring where the function is? For example, you use the function in XICS.php but I can't see where you include "functions.php". Is the function inside dbconnect.php OR a reference to the function?

phorce 131 Posting Whiz in Training Featured Poster

On the first line of XICS.php you have this line:

<?php
  $mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
  sec_session_start(); 
 ?>

Well, you're defining the constant "HOST", "USER", "PASSWORD", "DATABASE" in the file, process_login.php - So it looks, from looking at the code it doesn't know where it is.. So in that case, you need to include CICS.php in the process_login.php..

Alternatively, why not have just a file that connects to the database itself, and, everytime you want to connect to the database, just include/require this file?

You could have a file that JUST has the DATABASE CONNECTION details in and then require it.. Either way, you need a way of making sure the server knows where HOST and other credentials is.

phorce 131 Posting Whiz in Training Featured Poster

Hello,

Look at this example:

#include <iostream>
#include <string>
using namespace std;

string* returnString(const char* filename) {
 string* names = new string[3];
 names[0] = "Hello";
 names[1] = "World";
 names[2] = "huuhaa"; 

 return names;
}
int main(int argc, char *argv[]) {

    string* names = returnString("file.txt");

    for(unsigned i=0; (i < 3); i++)
    {
        cout << names[i] << endl;

    }
}

Or use a vector :) You've included it! Hope this helps though

phorce 131 Posting Whiz in Training Featured Poster
<?php
ob_start();
session_start();
include('./config.php');

//protect SQL injection
$username = $_POST['username'];
$password = $_POST['password'];
$username = stripslashes($username);

$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$password=hash('sha256',$password);


//SQL query that sent login info to database


$result = mysql_query ("SELECT * FROM admin WHERE Login ='$username' AND Password ='$password'",$con);
$check = mysql_num_rows ($result);

if ($check == 1){
    while($rows = mysql_fetch_array($result)){
    $_SESSION['adminID'] = $rows['ID'];
    $_SESSION['username'] = $username;
        header('Location: ../home.php');
}
}

else {
    header('Location: ../index.php');

}


?>

Username will work, however, are you sure that 'ID' actually exists in the database?

phorce 131 Posting Whiz in Training Featured Poster

Can you not just take some code, then go onto different forums (Java, C++) etc.. and ask what the code is, if you don't know what the code does, or, even what language it is in; why are you using it?

It looks like Perl, or, some other scripting language..

phorce 131 Posting Whiz in Training Featured Poster

What is the error?

phorce 131 Posting Whiz in Training Featured Poster

You've got more chance of finding a blonde virgin than finding a two worded domain ;-)

phorce 131 Posting Whiz in Training Featured Poster

Don't think I quite understand, or, if I do, why would you want to do such a thing..

Ok, have a form that asks the user if (s)he is a user or a re-seller. Then, create a database that stores this information. Everytime you want to check, you can check to see if the IP address matches the re-sellers/users IP stored within the database. What if the user's IP address changes? What if they access a different computer? Is this therefore a really efficent way to identifying someone?

phorce 131 Posting Whiz in Training Featured Poster

Try including the "session.php" before "connecting.php" :)

phorce 131 Posting Whiz in Training Featured Poster

Okay,

Me personally, I would do this:

Take the ASP course to get to grips with some web programming and get to grisps with the language.

Either take the C++ or Java course. I would personally take the C++ over Java but then again I enjoy coding C++. If you can take Java in the spring, brilliant! Go ahead and do it.

Taking this path, to me will give you an insight in to what you want to do in your future. But, remember, you don't have to decide what you want to do now, it's all about learning experiences. I wanted to be a lawyer during school, I'm now programming? Someone I know did their degree in medicine and now runs a design company. Don't assume you "want to know everything there is about programming" because the chances are, even if you spent from now until you were 50 - you would not have grasped the full concepts as this is an ever changing enviroment.

phorce 131 Posting Whiz in Training Featured Poster

Stick to the C++ aspect of the course, it'll come in handly later on. Take a web course (ASP/PHP) as these two languages are really useful as well, especially in todays market where things are moving towards web programming. I learnt PHP then C++ then I moved into Java and by learning PHP I was able to pick up on C++ and by learning C++ I was able to pick up on Java..

P.S. By learning ASP (especailly ASP.NET) it may open you up to learning languages such as C# which can the easily be adapted and work with each other.

phorce 131 Posting Whiz in Training Featured Poster

ll concerned abo

@Helianthus - In my opinion, learning C++/C will open you up to learning other languages, it will give you that foundation or stepping stone and other languages syntax will become more familiar. Obviously, if you want such jobs as a C++ programming, then, you have to be really good at what you do and understand the concepts. REMEMBER, it's not about what language you can code in, it's about learning the logic. YOU SHOULD be able to take a particular problem, find out the best solution and in the best language and then go from there.

Hope this helps

phorce 131 Posting Whiz in Training Featured Poster

You forgot to mark the thread as solved, too busy talking to yourself ;)

phorce 131 Posting Whiz in Training Featured Poster

Sorry, my last comment was invalid. Can you tell me what $var actually does? Is it something on the form? If so, couldn't you just have it as an hidden field and then post it across? The aother alternative might be to decide what your form does by using $_GET.

phorce 131 Posting Whiz in Training Featured Poster

Just a suggestion..

The $var will be stored in temp memory, and, when you re-load the page, the $var value will therefore be cleared. Why not store it as a session?