broj1 356 Humble servant Featured Poster

You have to debug ajax calls which is easier with tools like Firebug. But anyway, I think you should check the UPDATE query from the updateMemberAjx() function. You can try to display the query instead of the success message by assigning the query to a variable in each case statement like:

case 'first_name':
    $GLOBALS['MySQL']->res("UPDATE `pd_profiles` SET `first_name`='{$sVal}' WHERE `id`='{$iId}'");
    // assign the query to a temp variable
    $temp = "UPDATE `pd_profiles` SET `first_name`='{$sVal}' WHERE `id`='{$iId}'"

and changing line 098 from:

echo 'Successfully saved';

to:

echo $temp;

This way the query will be diplayed upon an update. You can copy it and test in phpmyadmin whether it contains any errors.

broj1 356 Humble servant Featured Poster

The error is in the paramaters of the mysql_query function. The first parameter should be the query (string type), and the second (optional) parameter is the link (of type resource type). You have wrong sequence ot these parameters.

And the mantra: ditch the deprecated mysql_* functions and replace them with the new PDO or at least mysqli_* functions.

broj1 356 Humble servant Featured Poster

Do you already have an upload form? If not, you can find nice tutorial here. Make sure that everything is happening within the restricted area (i.e. a user has to be logged in to upload photos), to keep things secure.

An elegant solution would be to use AJAX, so users can upload photos without leaving a page or to put checkboxes to each photo in order to enable users to load more photos at once.

Hopefuly I understood your question right. If not please clarify it.

broj1 356 Humble servant Featured Poster

And what is the actual problem? Describe where you got stuck and post possible error messages.

broj1 356 Humble servant Featured Poster

Here is what I do: echo implode(', ', (array)$topuid);, with this code, the $topuid will be cast into an array for implode.

Casting is a good idea. You also have to cater for the query to work when the $topuid is empty.

$inCondition = $topuid != "" ?  " and user_id NOT IN ($idtopuid)" : "";
$userquery = mysql_query("select * from user where user_id != '{$_SESSION['userid']}'" . $inCondition . " order by rand() limit 0,5");

Note that I embeded variables directly into the doublequoted string.

broj1 356 Humble servant Featured Poster

It seems that the $topuid variable is not an array (the implde function expects an array). Can you check it out? You can put this code just before line 3 in the above code:

die(print_r($topuid, 1));

This will display the value of the variable and stop the script. Please post the value here.

broj1 356 Humble servant Featured Poster

You are welcome. Please mark as solved if no more questions. Happy coding.

broj1 356 Humble servant Featured Poster

Your array has two main elements:

  1. settings - an array of common settings
  2. books - an array of book data (each element here contains the same book data)

Therefore you have to use an if condition and check for the main key to access other values. I tested it with this code:

$array = (parseInfo($barcode));

// this is to format the output nicely
echo "<pre>";

// print_r($array);

foreach ($array as $key => $values) {

    /*
    echo  'AUTHOR FL: ' . $author_fl  = $values['show']['showCovers'];
    echo  'BOOK_ID: ' . $book_id  = $values['books'];
    echo  'TITLE: ' . $title  = $values['settings']['title'];
    $covers = $values['settings']['covers']; // Author (last, first)
    $author_lf = $values['settings']['author_lf']; // Author (last, first)
    $author_fl = $values['settings']['author_fl'];  // Author (first, last)
    echo  'AUTHOR_CODE: ' . $author_code  = $values['amazonchoice']['author_code'];
    $ISBN  = $values['amazonchoice']['ISBN'];
    $publicationdate  = $values['amazonchoice']['publicationdate'];
    $entry_stamp = $values['amazonchoice']['entry_stamp'];
    $entry_date = $values['amazonchoice']['entry_date'];
    $copies  = $values['amazonchoice']['copies'];
    $notes = $values['amazonchoice']['notes'];
    $language_main  = $values['amazonchoice']['language_main'];
    */

    // MY TEST

    echo "--------------<br> $key <br>--------------<br>";
    echo print_r($values, 1);

    if($key == 'settings') {
        echo '*** [show][showCovers] ***<br>' . print_r($values['show']['showCovers'], 1);
        echo '*** [settings][title] ***<br>' . print_r($values['title'], 1);
    } else {
        echo '*** [books] ***<br>' . print_r($values['books'], 1);
    }
}

echo "</pre>";

And as I said, some values are emty so nothing gets displayed.

matrixdevuk commented: You could simply do `echo "<pre>" . print_r($array, true) . "</pre>";` -1
broj1 356 Humble servant Featured Poster

So where did you get stuck? I managed to access any element of the above array.

broj1 356 Humble servant Featured Poster

The values you are trying to display have no values so you see nothing. To prove that add some static texts to the echo statement, like this:

foreach ($array as  $values) {

    echo  'AUTHOR FL: ' . $author_fl  = $values['show']['showCovers'];
    echo  'BOOK_ID: ' . $book_id  = $values['books'];
    echo  'TITLE: ' . $title  = $values['settings']['title'];
    $covers = $values['settings']['covers']; // Author (last, first)
    $author_lf = $values['settings']['author_lf']; // Author (last, first)
    $author_fl = $values['settings']['author_fl'];  // Author (first, last)
    echo  'AUTHOR_CODE: ' . $author_code  = $values['amazonchoice']['author_code'];
    $ISBN  = $values['amazonchoice']['ISBN'];
    $publicationdate  = $values['amazonchoice']['publicationdate'];
    $entry_stamp = $values['amazonchoice']['entry_stamp'];
    $entry_date = $values['amazonchoice']['entry_date'];
    $copies  = $values['amazonchoice']['copies'];
    $notes = $values['amazonchoice']['notes'];
    $language_main  = $values['amazonchoice']['language_main'];
}

You can always test json/arrays or other php functions online on Functions online, e.g. this is the link for json_decode.

broj1 356 Humble servant Featured Poster

Your text contains an apostrophe (') which is also used in mysql as a string delimiter. In order to store an apostrophe into the DB you have to escape it usually using a database escape function (mysql_real_escape_string in your example):

$insert = mysql_query("insert into offer(
descr
)
values(
'".mysql_real_escape_string($descrr)."'
)")
or die(mysql_error($con));

All in all using deprecated mysql_* functions is a bad idea. Switch to PDO.

broj1 356 Humble servant Featured Poster

You are welcome. Please mark the thread as solved if no more questions. Happy coding :-)

broj1 356 Humble servant Featured Poster

Sorry, my typo. Line 22 of my code should be:

if($result->num_rows != 0) {
...

(no parentheses after the num_rows).

Also change the action of the form to the same script:

<form method="post" action="#">
broj1 356 Humble servant Featured Poster

You are mixing mysql_* and mysqli_* functions as well as object oriented and procedural style. The code below is mysqli_* OOP style, and is not tested, just to give you an idea. See the comments.

// check if form submitted and if code field is not empty
if(isset($_POST['submit']) && $_POST['code'] != '') {

    // only now connect to the DB since you know you need it
    $db=new mysqli('localhost','root','','shop');
    if(mysqli_connect_errno()){
        echo 'Could not connect to database:Plz try After Some time..';
        exit();
    }

    // clean the user input (see the correct code for the clean function below)
    $code = clean($_POST['code'], $db);

    // after cleaning (trim) the code could be empty so check for this
    if($code != "") {

        // use a WHERE clause
        $qry="SELECT code FROM code WHERE code='$code'";
        $result = $db->query($qry);

        // check if you got any rows (code was found)
        if($result->num_rows() != 0) {
            echo "sucess,discount granted";
        } else {
            // code was entered but not found in the database
            echo "fail (code is not valid)";
        }

        // Free result set
        $result->close();

    } else {
        echo "fail (no code entered)";
    }

    // close the connection
    $db->close();
}

The clean function also has to be corrected in order to use the $db object:

//Function to sanitize values received from the form. Prevents SQL injection
// you have to pass the DB object to the function to use it
function clean($str, $db) {
    $str = @trim($str);
    if(get_magic_quotes_gpc()) {
        $str = stripslashes($str);
    }
    return $db->real_escape_string($str);
}

Please note this post has …

broj1 356 Humble servant Featured Poster

I am not sure if I understood you right, but I'll give it a go.

Firstly I think you do not need a $count variable since you have $i for counting. Then you just check the value of $i whether the remainder of the integer division with 10 is 0. If yes, display the banner:

<?php if($i % 10 == 0): ?>
    <div id="banner">
        <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
            <!-- SecoundAd -->
            <ins class="adsbygoogle"
            style="display:inline-block;width:710px;height:100px"
            data-ad-client="ca-pub-5699416235054188"
            data-ad-slot="7054710957"></ins>
            <script>
            (adsbygoogle = window.adsbygoogle || []).push({});
        </script>
    </div>
<?php endif;
broj1 356 Humble servant Featured Poster

Your for loop gets repeated only two times. Did you mean you want to display an ad every 10th match?

broj1 356 Humble servant Featured Poster

You could make it simpler by using file_exists instead of using all the scandir stuff:

$p = $_GET['p']; // WARNING: sanitize this before using it in production app

if (file_exists($dir.'/'.$p.'.htm')){
    include($dir.'/'.$p.'.htm');
} else {
    echo 'Sorry, page introuvable';
}

And sanitize user input (such as limiting it to certain path, whitelisting etc).

broj1 356 Humble servant Featured Poster

This is insecure. You have to sanitize the user input before using it in a select statement.

// suppose the ID is an integer
$id = intval($_GET['id']);
$order = "SELECT * FROM comanda where $id=<some condition here>";
broj1 356 Humble servant Featured Poster

Also a concern about security on line 8. Instead of:

<input type="hidden" name="id" value="<?php echo $_GET['id'];?>

it should be:

<input type="hidden" name="id" value="<?php echo htmlspecialchars($_GET['id']);?>

to escape possible bad script injection into html.

broj1 356 Humble servant Featured Poster

OK, I gave one line of code as an example and this is the whole snippet:

<?php
  include "db.php";//database connection
   $order = "SELECT * FROM comanda where ['id']=''";
  $result = mysql_query($order);
  $row = mysql_fetch_array($result);
  ?>
  <form method="post" action="edit_reper.php">
  <input type="hidden" name="id" value="<?php echo $_GET['id'];?>
    <tr>        
      <td>Cod</td>
      <td>
        <input type="text" name="cod" 
    size="20" value="<?php echo $row['cod'];?>
      </td>
    </tr>
    <tr>        
      <td>Denumire Material</td>
      <td>
        <input type="text" name="den_material" 
    size="20" value="<?php echo $row['den_material'];?>
      </td>
    </tr>
    <tr>        
      <td>Greutate Totala</td>
      <td>
        <input type="text" name="greutate_totala" 
    size="20" value="<?php echo $row['greutate_totala'];?>
      </td>
    </tr>
    <tr>        
      <td>Name</td>
      <td>
        <input type="text" name="cant_reper" 
    size="20" value="<?php echo $row['cant_reper'];?>
      </td>
    </tr>
    <tr>
      <td>Address</td>
      <td>
        <input type="text" name="lg" size="40" 
      value="<?php echo $row['lg'];?>
      </td>
    </tr>
    <tr>
      <td align="right">
        <input type="submit" 
      name="submit value" value="Edit">

There is still something not OK in the select query on line 3. Something is missing at the where condition, maybe the $_GET (I don't know only you could). Maybe this way:

$order = "SELECT * FROM comanda where {$_GET['id']}=''";
broj1 356 Humble servant Featured Poster

You are almost there. Just remove quotes arround the row elements, add quotes arround row element names, add semicolon at the end and use <?php start tags:

<?php echo $row['den_material'];?>

You might also want to check for errors:

 if($result = mysql_query($order)) {
     // do the stuff...
     ...
 } else {
     // handle error..
 }

Same with the $row = mysql_fetch_array($result) code.

broj1 356 Humble servant Featured Poster

You can check your server side sript if it works OK. Try to input the URL with the parameters into your browser directly e.g.:

php-includes/news_letter_send.php?name=somename&email_address=justme@example.com

You will have to change the global array to $_GET temporarily:

if(isset($_GET['name']) && isset($_GET['email_address'])) {
    $name = $_GET['name'];
    $email = $_GET['email_address'];
        ...
} else {
    die 'failed';
}

You can use different parameters in the query string: the ones that exist in the databse and the ones that don't. The script should echo either duplicate, sent or failed. If this is true your backend script works OK. In this case go and check the jquery ajax code, i.e if the msg gets alerted OK.

Errors could be also in the include file or in the success element.

And one more important thing: you should sanitize the user supplied data (and check for existence of $_POST elements earlier):

if(isset($_POST['name']) && isset($_POST['email_address'])) {
    $name = mysql_real_escape_string($_POST['name']);
    $email = mysql_real_escape_string($_POST['email_address']);
    $sql = "SELECT tbl_news_letters.emailaddress WHERE tbl_news_letters.emailaddress=$email";
    ...

} else {
    die 'failed';
}.

And: drop the mysql database extension and switch to PDO.

broj1 356 Humble servant Featured Poster

JSFIDDLE shows no code. Anyway, since this is more a CSS question, I suggest you start a new thread in the Web Design, HTML and CSS Discussion part of DW. This way you will have other people looking at it (I guess not many people look at threads with so many posts).

Once this thread is finished, please mark it as solved.

broj1 356 Humble servant Featured Poster

It could be that the kladilnica table is not matched to the field types. Can you post the structure of the table (use SHOW CREATE TABLE kladilnica in phpmyadmin).

And please note: you should sanitize user supplied variables before inserting them into the database.

broj1 356 Humble servant Featured Poster

It is much easier to check the query if you do not use all the concatenation. You can do it this way:

$sql = "INSERT INTO `kladilnica` VALUES ('', '$getUsername', '$betAmouth', '$gain', '$date', '$match1', '$match2', '$match3', '$match4', '$match5','$match6', '$match7', '$match8', '$match9', '$match10', '$match11', '$match12', '$match13', '$match14', '$match15', '$match16', '$odd')";

You have to make sure all the variables are set otherwise you will get an error. It is wise to test the query. Put this code after it:

die($sql);

It will display the query and stop the script. Now you can inspect the query if it is OK and copy it into phpmyadmin to test it.

And a question: are $match1, $match2, $match3... actual fields (columns) in the kladilnica table? Maybe your database design is not scalable.

broj1 356 Humble servant Featured Poster

Haven't studied your code closely but the number 2147483647 is exactly the max integer value on 32 bit systems. Why do you not handle your phone number as a string?

broj1 356 Humble servant Featured Poster

You are welcome. If there are no more questions please mark the thread as solved. Happy coding in 2015.

broj1 356 Humble servant Featured Poster

The following is a function that will create links to pages. In addition to the First and Last buttons I also added the Next and Prev buttons which might be useful. I avoided mixing html and php code so html statemens are being echoed. The links are wrapped in a div so you can style the elements. Also links are wrapped in span elements, again for styling. The separator between links is customizable but you could get even better look using CSS.

This function works but not everything might be meeting your expectations. It is to show the concept, you fine tune it yourself.

function displayLinks($totalPages, $displayedLinks = 6, $currenttPage = 1) {

    // customizable link separator
    $separator = " | ";

    // when number of pages is less than 6 (or whatever you set it to be)
    if($totalPages < $displayedLinks) {
        $displayedLinks = $totalPages;
    }

    // calculate the first and last page links
    $startPageLink = $currenttPage <= floor($displayedLinks / 2) ? 1 : $currenttPage - floor($displayedLinks / 2);
    $endPageLink = ($currenttPage + $displayedLinks) < $totalPages ? $startPageLink + $displayedLinks : $totalPages;

    if(($totalPages - $endPageLink) < (floor($displayedLinks / 2))) {
        $startPageLink = $totalPages - $displayedLinks;
    }

    // enclose the links in a div so you can style everything
    echo '<div class="pagination-links">';

    // add the 'First' and the 'Prev' buttons if links do not start with 1
    if($startPageLink > 1) {
        echo '<a href="'. $_SERVER["SCRIPT_NAME"] . '?page=1">First</a>';
        echo $separator;
        echo '<a href="'. $_SERVER["SCRIPT_NAME"] . "?page=" . ($currenttPage - 1) . '">Prev</a>'; …
broj1 356 Humble servant Featured Poster

Maybe this is not an answer to your question but I was just wondering why you do not use any of the ready made solutions for pagination. You can find some examples on phpclasses.org (they will want you to sign-up to download the code but I think it is worth it). The advantages are: you have a uniform class that handles pagination (in uniform way) on all pages with many database results, when you change the look of the pagination links the changes will reflect everywhere, you can add customization options through various methods etc. The bad side is that by using some else's solution you do not learn that much.

broj1 356 Humble servant Featured Poster

@imti32: sorry, I meant method (as noted in the text of the post). Correct code is:

<form method="post" id="nl-form" class="nl-form" action="../EMAIL.php">

Thanx for spotting, mate :-).

<M/> commented: Thanks :) +10
broj1 356 Humble servant Featured Poster

I had a quick look at the code and the main error is that you are missing a method attribute in the form, so it defaults to GET, but you are using POST parameters. So change the form line to:

<form action="post" id="nl-form" class="nl-form" action="../EMAIL.php">

There are other errors too, like:

  • if your document is of html5 type then you do not need to use / for closing tags of elements
  • you can not use em tag within the input element, you can style the placeholder using css as shown here
  • the starting div for the container is missing
  • some other missing variables but this might be due to some missing code in your post
<M/> commented: Thanks :) +0
broj1 356 Humble servant Featured Poster

No worries, mate .-) Please mark this as solved. Happy coding in 2015.

broj1 356 Humble servant Featured Poster

The problem is in the name of the References field (column) which is a Mysql reserved word and should not be used as a field name. If you still wish to use it as a field name you should enclose it in backticks. I would recommend you change it so you avoid possible errors in future.

$sqls = "INSERT INTO saveproposal (ID, PI, Email, RTitle, Coauthors, ExSummary, LReview, Objective, Methodology, EOutput, `References`, RDuration) VALUES (NULL, '$peru', '$email', '$title', '$auth', '$eta', '$pta', '$ota', '$mta','$eota','$rta','$rdt');";

Se the list of mysql reserved words here.

broj1 356 Humble servant Featured Poster

The error is in the generateOrderedArray function which returns resource ID (a special PHP type) instead of an array of student ID numbers. Below is the code that should work (see the coments within).

function generateOrderedArray()
{
    // initialize the return array
    $retArray = array();

    // do the connection stuf
    $db = mysql_connect("localhost", "root", "");
    mysql_select_db("dbehomebooking",$db);

    // query for student ID numbers database
    $query = "SELECT studentid FROM approval";

    // result of querying (resource ID)
    $res = mysql_query($query) or die ('<p>' . mysql_error());

    // put the ID numbers from the database into the return array
    while ($row = mysql_fetch_array($res))
    {
        $retArray[] = $row['studentid'];

        // you can also echo it for testing
        echo '<br>',$row['studentid'];
    }

    // return the array of ID numbers
    return $retArray;
}

The binarySearch function seem to work OK.

Also the html tag on line 3 should be before the form tag.

broj1 356 Humble servant Featured Poster

If you do not have image ID then $data array is not set. You should check for it before using it, especially in these two lines:

if(isset($data['image']) && isset( $data['newfilename'])) {
    echo $data['image'];
    echo '<div id="updateimage"><img src="images/'.$data['newfilename'].'"  height="250px"></div>';
}
broj1 356 Humble servant Featured Poster

OK. Please mark it solved.

broj1 356 Humble servant Featured Poster

You are missing the ; at the end of line 14

broj1 356 Humble servant Featured Poster
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

Can you post the last version of the code.

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

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

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

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...).