broj1 356 Humble servant Featured Poster
  1. You put function definitions within the if block which might be OK but is not very clean. If you need to call the functions from outside the if block and the if condition is false, the functions will be undefined (you will get the fatal error). So put the function definitions outside the if block, maybe at the end of the code.
  2. Errors are in both functions. They are not syntactical errors but more semantical errors. The generateOrderedArray() is expected to return an array but in your case it returns a resource type. In the binarySearch function you address an element of an array $element = $array[$mid] but $element is not an array.

This is how I think the generateOrderedArray should look like:

function generateOrderedArray()
{
    $res = mysql_query("Select location from houserent");
    $row = mysql_fetch_array($res);
    print_r($row);
    return $row;
}

In the binarySearch function check for the type first

while ($low <= $high)
{
    $mid = floor(($low + $high) / 2);
    if(isset($element) && !empty($element)) {
        $element = $array[$mid];
        ...

    } else {
        return false;
    }
broj1 356 Humble servant Featured Poster

The code looks OK. You just have to make sure there is no any character before the <?php tag, not even a single space (or a !DOCTYPE tag). Also if you include other files make sure that they do not contain any output before the header function.

If you still get an error please describe it (error message, expected output, what you really get...).

broj1 356 Humble servant Featured Poster

You should run the above code only when the form was submitted so you have to do a check first:

// suppose your form has a submit button named submit
if(isset($_POST['submit'])) {
    // now you do your usual stuff
    $con = mysql_connect("localhost","root","nano");
    $selected = mysql_select_db("airline");

    // do not forget to sanitize/validate the user input
    $username=$_POST['uname'];
    $password=$_POST['ptxt'];

    // you would normaly do stripslashes only when magic_quotes_gpc is on (i.e. prior to PHP 5.3)
    // I doubt it's needed here
    $username = stripslashes($username);
    $password = stripslashes($password);

    $query = "select * from user where username='$username' AND password='$password'";
    $result = mysql_query($query);
    $row = mysql_num_rows($result);
    if($row ==1){
        echo "It works!";
    }
}
broj1 356 Humble servant Featured Poster

Can you post the last version of the code.

broj1 356 Humble servant Featured Poster

You shall not send any HTML output before the header function. It won't work. So rearrange your code. Something like:

<?php
if($username=="" && $password=="") {
    header('location:admin.php');
    exit(); // add this for security
} else if($username=="hijran" && $password=="khan") {
    header('refresh:5; user.php');
} else {
    header('location:error.php');
    exit(); // add this for security
}
?>
<!DOCTYPE HTML>
<html>
<body>
<p>Redirecting...</p>
<?php
session_start();
$user=$_POST['uname'];
$_SESSION['username']=$user;
$con=mysql_connect("localhost","root","nano");
mysql_select_db("airline")or die("Db error");
$username=$_POST['uname'];
$password=$_POST['ptxt'];
$query = mysql_query("select * from user where password='$password' AND name='$username'");
</body>
</html>

Please note: the above example is just to show the concept. I am not sure if the functionality is still what you wanted.

broj1 356 Humble servant Featured Poster

Fatal error means that the script encountered an error and can not continue. In your case the searchform2.php script can not find the generateOrderedArray() function. It either is not declared within the script or is misspelled. Can you post the whole searchform2.php script please.

broj1 356 Humble servant Featured Poster

As I said: no HTML can be output before the header function so put the <!DOCTYPE html> part after the first php block.

<?php
if(isset($_POST['login'])){
$uname = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_SPECIAL_CHARS);
$pword = filter_input(INPUT_POST, 'password', FILTER_SANITIZE_SPECIAL_CHARS);
if ($uname=="nitcoadmin" && $pword=="nitco@bahrain"){
//$_SESSION['user']=$uname;
//$_SESSION['passw']=$pword;
// $_SESSION['login']='1';
header('location:enqrep.php');
}
...
?>
<!DOCTYPE html>
...

And the second part of the else block will have to be changed, too. You will have to store the error message into a variable and display it later on on the page.

broj1 356 Humble servant Featured Poster

You can not send headers after you have sent HTML output. Move the following block of PHP code to the top of the script and you'll be fine:

if(isset($_POST['login'])) {
    $uname = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_SPECIAL_CHARS);
    $pword = filter_input(INPUT_POST, 'password', FILTER_SANITIZE_SPECIAL_CHARS);
    if ($uname=="nitcoadmin" && $pword=="nitco@bahrain"){
        //$_SESSION['user']=$uname;
        //$_SESSION['passw']=$pword;
        // $_SESSION['login']='1';
        header('location:enqrep.php');
    }
}
broj1 356 Humble servant Featured Poster

What does the error message say apart from Fatal error (post the whole text of the error message)?

Also, the mysql_query function returns a resouce (a special php type). Are you sure you want the generateOrderedArray() function to return an array of resource? You might wanna look at the manual to see how querying should be done. And please note that the mysql extension is out of date and should be replaced with PDO or at least mysqli.

cereal commented: answer is correct, no reason for downvote! +13
broj1 356 Humble servant Featured Poster

Can you please post the table structure and some data so I (or anyone else) can do a test. Post the CREATE TABLE mm_goats ... statement and some INSERT INTO mm_goats ... statements so anyone willing to help does not have to make up all the test data.

broj1 356 Humble servant Featured Poster

Can you post the code you've done so far. And then more precisely describe what you want but were not able to do.

broj1 356 Humble servant Featured Poster

Something like:

$rawString = 'aamu.edu: Alabama A&M University';
$temp = explode(': ', $rawString);
// $temp[0] -> college_email
// $temp[1] -> college_name

$query = "INSERT INTO tableName (college_email, college_name) VALUES ('{$temp[0]}', '{$temp[1]}')";

And do not forget to sanitize strings first.

broj1 356 Humble servant Featured Poster

It shouldn't matter as long as you use correct syntax. The following is a working example using mysql:

<html>
<head>
<style>
div.gallery {
    display: inline-block;
}
</style>
</head>
<body>
<?php
// $mysqli = new mysqli('localhost', 'test', '', 'test');
$con = mysql_connect('localhost', 'test', '');
mysql_select_db('test');

// temporary array for reading data into
$tempArray = array();
// $result = $mysqli->query("SELECT * FROM portraits ORDER BY category");
$result = mysql_query("SELECT * FROM portraits ORDER BY category");
// while ($row = $result->fetch_assoc()) {
while ($row = mysql_fetch_assoc($result)) {
    $category = $row['category'];
    // changed to an array
    $tempArray[$category][] = array($row['collection_id'], $row['collection_name']);
}
// process the temp array
foreach($tempArray as $cat => $galeryArray) {
    echo "$cat: ";
    foreach($galeryArray as $gal) {
        echo "<div class='gallery'><a href='select_portrait.php?id={$gal[0]}&gallery={$gal[1]}'>{$gal[1]}</a></div>&nbsp;";
    }
    echo '<br>';
}
?>  
</body>
</html>

Anyway, you better switch to mysqli or PDO (it is actually highly recommended, since mysql extension is deprecated, unmaintained and can be dropped anytime).

broj1 356 Humble servant Featured Poster

I tested my code and it displays exactly what you wanted:

Cartoon Faces: Gallery 1 Gallery 2
Flags: Gallery 1

Here is the test code:

<html>
<head>
<style>
div.gallery {
    display: inline-block;
}
</style>
</head>
<body>
<?php
$mysqli = new mysqli('localhost', 'test', '', 'test');

// temporary array for reading data into
$tempArray = array();
$result = $mysqli->query("SELECT * FROM portraits ORDER BY category");
while ($row = $result->fetch_assoc()) {
    $category = $row['category'];
    // changed to an array
    $tempArray[$category][] = array($row['collection_id'], $row['collection_name']);
}
// process the temp array
foreach($tempArray as $cat => $galeryArray) {
    echo "$cat: ";
    foreach($galeryArray as $gal) {
        echo "<div class='gallery'><a href='select_portrait.php?id={$gal[0]}&gallery={$gal[1]}'>{$gal[1]}</a></div>&nbsp;";
    }
    echo '<br>';
}
?>  
</body>
</html>
broj1 356 Humble servant Featured Poster

Not tested:

// temporary array for reading data into
$tempArray = array();
$result = $mysqli->query("SELECT * FROM portraits ORDER BY category");
while ($row = $result->fetch_row()) {
    $category = $row['category'];
    // changed to an array
    $tempArray[$category][] = array($row['collection_id'], $row['collection_name']);
}
// process the temp array
foreach($tempArray as $cat => $galeryArray) {
    echo "$cat: ";
    foreach($galeryArray as $gal) {
        echo "<div class='gallery'><a href='select_portrait.php?id={$gal[0]}&gallery={$gal[1]}'>{$gal[1]}</a></div>";
    }
    echo '<br>';
}

Didi you mean each galery is in own div? You have to style them display:inline-block then or something similar.

broj1 356 Humble servant Featured Poster

This is a rough code (might need some tuning):

// temporary array for reading data into
$tempArray = array();
$result = $mysqli->query("SELECT * FROM portraits ORDER BY category");
while ($row = $result->fetch_row()) {
    $category = $row['category'];
    $tempArray[$category][] = $row['collection_name'];
}
// process the temp array
foreach($tempArray as $cat => $galeryArray) {
    echo "$cat: " . implode(' ', $galeryArray) . '<br>';
}

The idea is to read all the data inot a temp associative array where the associative indexes are category names and values are array of galeries. You will have to do some fiddling to construct links. I used mysqli in OO mode. Adapt if you use something else.

broj1 356 Humble servant Featured Poster

I am not sure if I understand the question. Can you post some data from the table, it may help me understanding (i.e. SELECT * FROM portraits LIMIT 10).

broj1 356 Humble servant Featured Poster

To follow good design practices you should keep categories in a separate table. But anyway:

  • put a select element (a dropdown) or checkboxes on page to let people chose a category/ctagories
  • create a select statement using a chosen category/categories construct a SQL statement to query the database:

    $query = "SELECT * FROM portraits WHERE catgory = $chosenCategory";

Then just display resulting rows in a form you think is appropriate (i.e. looping through a resultset using a while loop).

broj1 356 Humble servant Featured Poster

In 2.php you should have details enclosed within an html eement (such as div) with an ID so that you can access it using jquery text() or html() or similar method.

<div id="my-content">
This is the body of the email.
</div>

var emailBody = $("#my-content").text();
broj1 356 Humble servant Featured Poster

If solved, please mark thread as solved. Happy coding.

broj1 356 Humble servant Featured Poster

Not sure if I understood the question but this recursive function will traverse the object, search for a property and display it:

function displayElement($obj, $el) {
    foreach($obj as $key => $val) {
        if(is_object($val)) {
            displayElement($val, $el);
        } else {
            if($key == $el) {
                echo "Found $key: $val<br>";
                die();
            } else {
                echo "Searching $key<br>";
            }
        } 
    }
}

So if you have an object like this:

$object1->id = 'evt_151H4qEfYJJpTpgqdg5eQvIK';
$object1->created = 1416575036;
$object1->livemode = '';
$object1->type = 'coupon.created';
$object1->data->id = '5D';
$object1->data->created = 1416575036;
$object1->data->percent_off = 5;
$object1->data->amount_off = '5D';
$object1->data->currency = '';
$object1->data->object = 'coupon';
$object1->data->duration = 'once';
$object1->data->redeem_by = '';
$object1->data->max_redemptions = '';
...

use the function this way:

displayElement($object1, 'percent_off');

It displays the first element found (might be not good for you since you have some repeating properties down the tree)

broj1 356 Humble servant Featured Poster

The $_GET array contents is OK. You are getting the email address through. After filtering/sanitizing it the email should not change. It should be writen OK into the database.

Ups, only now I have spotted it. You are missing quotes arround the $mail in your query, like this:

$sqlu="UPDATE atab
SET
email='$mail',
$answer=$answer+1
WHERE Qid=$hid";
broj1 356 Humble servant Featured Poster

Stick this code on line 3 just after the if(isset($_GET['submit']) && isset($_GET['q']) && isset($_GET['email'])){ line:

die(print_r($_GET, 1));

That will print out the values sent from the form and stop the script. Post the output here.

broj1 356 Humble servant Featured Poster

The $mail doesn't even come from the form. Should you code it something like:

if(isset($_GET['submit']) && isset($_GET['q']) && isset($_GET['email']) {
    $mail=$_GET['email']; // sanitize this first
    ...

Then the question is what type the email field is.

And a side note: vlidate and sanitize the data from the form before you save it into the database.

broj1 356 Humble servant Featured Poster

If no more questions please mark thread as solved. Happy coding in PHP :-)

broj1 356 Humble servant Featured Poster

Cool. If this answers your question please mark the thread as solved. Happy coding.

broj1 356 Humble servant Featured Poster

First store the username in the session variable.

// sanitize/validate first
//...
$_SESSION[$uname] = $uname;

On other pages (within the same session) it will be available to your scripts:

$uname = $_SESSION[$uname];

provided that you used the session_start() (always put it on top of your script).

And sanitize the user input first using appropriate method depending on where are you using the data (database, email, html, url, javascript...).

broj1 356 Humble servant Featured Poster

So you have to make sure the database collation is the right one and also that the DB connection collation is OK (in mysql utf8_unicode_ci is pretty safe). Also you can use this query upon connecting:

SET NAMES utf8

In HTML it is good idea also to set a meta tag:

<meta charset="UTF-8">
broj1 356 Humble servant Featured Poster

Where is the name comming from? The database or is it just a part of plain HTML? And what editor are you usinh?

broj1 356 Humble servant Featured Poster

Seems to be possible doing this using Javascript. And use PHP to pepare the HTML part. See http://msdn.microsoft.com/en-us/library/office/fp161148%28v=office.15%29.aspx

broj1 356 Humble servant Featured Poster

Seems to be possible doing this using Javascript. See http://msdn.microsoft.com/en-us/library/office/fp161148%28v=office.15%29.aspx. And use PHP to pepare the HTML part.

broj1 356 Humble servant Featured Poster

It should not be a problem if you use UTF-8 I guess. But anyway, the character code for ö is &ouml; or &#246;.

<p>Sch&ouml;nefeld</p>
broj1 356 Humble servant Featured Poster

If you replace the following code:

list($ip, $netmask) = split("/", $ipNetmask );
$ip_elements_decimal = split("[.]", $ip );

with this one (for IPv4 addresses):

list($ip, $netmask) = explode("/", $ipNetmask );
$ip_elements_decimal = explode(".", $ip );

you should not get the depreciated notice. In fact I think you do not need regular expressions (with their overhead) for this.

broj1 356 Humble servant Featured Poster

Something like:

$rs2 = mysql_query($sql2);
// array of months to get the index
$months = array('Jan' => 1,'Feb' => 2,'Mar' => 3,'Apr' => 4, 'May' => 5, 'Jun' => 6, 'Jul' => 7, 'Aug' => 8, 'Sep' => 9, 'Oct' => 10, 'Nov' => 11, 'Dis' => 12);
// the month we selected and its index
$selectedMonth = 'Nov';
$selectedMonthIndex = $months[$selectedMonth];
// the query will return three rows
// let's put them in a temporary associative array containing only grand total for selected month and above
$tempArr = array();
while($row = mysql_fetch_assoc($rs2)) {
    // temp key for the associative array
    $tempKey = $row['element'];
    // construct a temporary array
    foreach($row as $key => $val) {
        // skip the element field and fields below the selected month
        if($months[$key] == 'element' || $months[$key] < $selectedMonthIndex) {
            continue;
        } 
        $tempArr[$tempKey] = isset($tempArr[$tempKey]) ? $tempArr[$tempKey] + $val : $val;
    }
}
// number of months for calculating average
$numberOfMonths = 12 - $selectedMonthIndex + 1;
// calculated averages
$averageA =  $tempArr['A'] / $numberOfMonths;
$averageB =  $tempArr['B'] / $numberOfMonths;
$averageC =  $tempArr['C'] / $numberOfMonths;
// display the averages
echo "Selected month: $selectedMonth<br>";
echo "Averages: A: $averageA, B: $averageB, C: $averageC";
broj1 356 Humble servant Featured Poster

If I got your question right you want to know whether a special character is required in PHP to write a statement on multiple lines. The code in PHP would be:

$query = "INSERT INTO table(field1," .
"field2)VALUES(value1," .
"Value2)";

or

$query  = "INSERT INTO table(field1,";
$query .= "field2)VALUES(value1,";
$query .= "Value2)";

or simply

$query = "INSERT INTO table(field1,
field2)VALUES(value1,
Value2)";

You use a dot (.) to concatenate strings or use any whitespace (line break, spaces) within a string to format the code.

diafol commented: That was my take as well +15
broj1 356 Humble servant Featured Poster

If you know the structure will be exactly like the above:

function convertDate($oldDate) {
    $months = array('Jan' => 1,'Feb' => 2,'Mar' => 3,'Apr' => 4, 'May' => 5, 'Jun' => 6, 'Jul' => 7, 'Aug' => 8, 'Sep' => 9, 'Oct' => 10, 'Nov' => 11, 'Dec' => 12);
    $temp = explode('/', $oldDate);
    return $temp[2] . '-' . $months[$temp[1]] . '-' . $temp[0];
}
arafath077 commented: thanks.itz worked +0
broj1 356 Humble servant Featured Poster

The main error was in the fact that you should not send any output to the browser before the header function. In your second alternative coding example above you broke this requirement. In the first example you actualy made a redirection before outputting the script code so the script code never run I suppose.

broj1 356 Humble servant Featured Poster

Do you mean the outline around the active link? You can remove it in your css:

a {
    outline: 0;
    border: 0;
}
broj1 356 Humble servant Featured Poster

Welcome to php and hopefully you will get plenty of joy in programming. If this question is answered please mark the thread as solved.

broj1 356 Humble servant Featured Poster

You can do it this way (without a login class):

<input type="submit" name="submit" value=""><img src="../images/login.jpg" alt="Submit"></input>

or with the login class (but you must specify the image dimensions):

.login {
    width: 200px;
    height: 80px;
    background:url("../images/login.jpg");
}
<input type="submit" class="login" name="submit" value="">
broj1 356 Humble servant Featured Poster

Your script seems to be OK. Check your configuration (php.ini -> [mail function] section) which depends on your environment. In my Windows XAMP on localhost all mail is written to the C:\xampp\mailoutput directory (not really sent out).

broj1 356 Humble servant Featured Poster

As I said in my post above: try with the stripped down version of the form. Here is your code with bare form:

<html>
<title></title>
<head>
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen">
<link rel="stylesheet" href="css/styleT.css"> <!-- Resource style <script src="js/modernizr.js"></script> <!-- Modernizr --> 
</head>
<body>

<div id="container">
<image src="images/logo.jpg">

<div id="navigation"><!-- <img src="images/navigation bar.jpg" alt="nav bar"> --></div> 

<div id="navcontainerbar">
<ul>

<li><a href="index.php">Home</a></li>
<li><a href="http://202.93.143.203/SIP_Ricci">SIP</a></li>  
<li><a href="#">LMS</a></li>
<li><a href="#">Library</a></li>
<li><a href="http://www.roomplus.co.id/roomplus/">Roomplus</a></li>

</ul>
</div>

<image src="images/nav.jpg">

<div id="banner-background">


 <!-- stripped down form -->
 <form action="login.php" method="POST">
<input type="text" name="email"><br>
<input type="password" name="password"><br>
<input type="submit" name="submit" value="Submit"><br>
<a href="#">Create an Account</a><br>
<a href="#">Forgot Password</a><br>
<input type="checkbox" name="keeplogin" value="Keep me logged in">Keep me logged in<br>
</form>



</div>
<!--<image src="images/banner.jpg">-->

<center><image src="images/educational_portal.jpg"></center>
<image src="images/tab.jpg">

<br><br>
<div style="margin: -30px 0 0 0; width: 1100px; height: 400px; background-color: #eee6ca;">

<!--  TAB -->



<div class="cd-tabs">
    <nav>
        <ul class="cd-tabs-navigation">
            <li><a data-content="inbox" class="selected" href="#0">Inbox</a></li>
            <li><a data-content="new" href="#0">New</a></li>
            <li><a data-content="gallery" href="#0">Gallery</a></li>

        </ul> <!-- cd-tabs-navigation -->
    </nav>

    <ul class="cd-tabs-content">
        <li data-content="inbox" class="selected">
            <!--
            <p>Inbox Lorem ipsum dolor sit amet, consectetur adipisicing elit. Earum recusandae rem animi accusamus quisquam reprehenderit sed voluptates, numquam, quibusdam velit dolores repellendus tempora corrupti accusantium obcaecati voluptate totam eveniet laboriosam?</p>

            <p>Inbox Lorem ipsum dolor sit amet, consectetur adipisicing elit. Earum recusandae rem animi accusamus quisquam reprehenderit sed voluptates, numquam, quibusdam velit dolores repellendus tempora corrupti accusantium obcaecati voluptate totam eveniet laboriosam?</p>
        </li>

        <li data-content="new">
            <p>New Lorem ipsum dolor sit amet, consectetur adipisicing elit. Non a voluptatibus, ex odit totam cumque nihil eos asperiores ea, labore …
broj1 356 Humble servant Featured Poster

I copied the code above on my server, changed the input type to submit and it submits the form without any problems. Maybe you try to disable javascript and see if it works or test without any css (maybe without negative margins and z-index).

This is the same form stripped down to bare bones:

<form action="login.php" method="POST">
<input type="text" name="email"><br>
<input type="password" name="password"><br>
<input type="submit" name="submit" value="Submit"><br>
<a href="#">Create an Account</a><br>
<a href="#">Forgot Password</a><br>
<input type="checkbox" name="keeplogin" value="Keep me logged in">Keep me logged in<br>
</form>

Try if this works.

broj1 356 Humble servant Featured Poster

See OWASP Top Ten especially the A1 - Injection. Probably all the web developer needs to know about the security. It is a lot of stuff to read and you do not have to digest it all at once. But make sure you bookmark it.

broj1 356 Humble servant Featured Poster

Do you have any javascript bound to the form / button? If yes, post it. Or maybe there is something in the style sheet?

broj1 356 Humble servant Featured Poster

I wonder why after I press the button, nothing happens! Normally, if I press the button - the form suppose to be processed by carrying me to login.php

<input type="button" name="submit">

The type should be submit not button unless you use some javascript code to submit the form.

Also an input element does not need a closing </input> tag.

broj1 356 Humble servant Featured Poster

Kool. Solved?

broj1 356 Humble servant Featured Poster

Is the server running IIS or XAMP? IIS has different document root path from XAMP as far as I know. XAMP is really only ment for local development.

broj1 356 Humble servant Featured Poster

What is the server OS? If it is one of the Linux distros the path for html documents would not be the same as in Windows. A couple of examples:

/var/www/html
/var/www
/srv

So you might want to reference the web path which is not suppose to change and hardcode the rest or check for the OS: for the later you could use some info from the $_SERVER superglobal variable, maybe $_SERVER['SCRIPT_FILENAME'] or $_SERVER['SERVER_SOFTWARE'] but I don't know how reliable this is. Example:

// use this in Windows
define('BASE_PATH', 'c://xampp/htdocs/');
// use this in Ubuntu
define('BASE_PATH', '/var/www/html/')

define('DESTINATION_FOLDER', BASE_PATH . 'squprime/administrator/admin/materialstorage/');
broj1 356 Humble servant Featured Poster
// execute the code below only if there is a patron_ID saved in the session variable
// this is probably a check if the user is logged in
if(isset($_SESSION['patron_ID']))
{
    // this function sets max execution time of the script
    // in your case (0) it sets no time limit 
    // see http://php.net/manual/en/function.set-time-limit.php
    set_time_limit(0);
    // here you include the file, probably to connect to the database
    // it is usually separate file so you can use it in many scripts
    include 'dbconnect.php';
    // what follows is an assignment from the session variable
    // this is one way of carying values over from script to script
    $studylevel1 = $_POST['studylevel'];
    // here you check (I presume) whether the form was submitted
    // only if it was, execute the code that folows
    if(isset($_POST['submit']))
    // probably part of a do/while loop
    { do
        {
            $senderid = $_SESSION['patron_ID']; $studylevel1 = $_POST['studylevel'];}}}

Hopefully this was clear enough :-)