paulkd 59 Newbie Poster

Hi James,

$response[] = will create (if it doesn't exist) or append the right-hand value to the $response array. So if $html->data->identifier is a simple string, e.g. 'Price', then a new array would be ['Price'] or array(0=>'Price')

$order->get_items() appears to be a nested object not an array. I've created a copy and iterated through it below.

        $obj = (object) array(365 => (object) array('name'=>'steel wool 3', 'qty' => 1) );
        //print_r($obj);
        foreach($obj as $key => $obj2) {
            foreach($obj2 as $key => $value) {
                echo $value.'<br>';
            }
        }
negitron commented: u cant code m8 +0
cereal commented: +1 +13
paulkd 59 Newbie Poster

line 73 is missing a semi-colon

paulkd 59 Newbie Poster
  1. There are many evolving technology areas. It is difficult to decide where your focus efforts. JavaScript is a key web technology. Don't start with jQuery (or similar libraries), learn raw JavaScript first.

  2. APIs - weather, maps, paypal, amazon, stripe. Google "public apis"

best4earn commented: THANKS PAULKD +2
paulkd 59 Newbie Poster

I've not tested this but I don't think you need to iterate your selectors to add the keyup event handler. You should be able to use the following code:-

$(".txtt").keyup(function() {
    calculateSum();
});
paulkd 59 Newbie Poster

There are so many ways to play with this. I've used an array to complement the table structure and seeded the array with either text (to display) or 1 (which currently displays a hyphen and if not set increment a counter.

<?php
$rows = 14;
$columns = 5;

$ins = array(
    0 => array(
        0 => 'Driver\'s Seat',
        1 => 1,
        2 => 1,
        3 => 1,
        4 => 1
    )
);
for($i = 1; $i<13; $i++) {
    $ins[$i][2] = 1;
}

$count = 1;
?>

<table border>
<?php for($row = 0; $row<$rows; $row++): ?>
<tr>
    <?php for($col = 0; $col<$columns; $col++): ?>
    <td>
    <?php 
        if(array_key_exists($row,$ins) AND array_key_exists($col,$ins[$row])) {
            if(is_numeric($ins[$row][$col])) {
                echo '-';
            } else {
                echo $ins[$row][$col];
            }
        } else {
            echo $count;
            $count++;
        }
    ?>
    </td>
    <?php endfor; ?>
</tr>
<?php endfor; ?>
</table>

You can add css etc. yourself (you may need to move the TD inside the php block to add appropriate classes).

paulkd 59 Newbie Poster
//simulate posted field
$_POST['formfield']='Is #star contained in your #database of #hashtags?';

preg_match_all('/#\w+/',$_POST['formfield'],$matches);

if($matches[0]) {
    foreach($matches[0] as $hashtag) {
        $sql = "select hashtag from `hashtag-table` where hashtag = '".substr($hashtag,1)."'";
        $result = mysql_query($sql);
        echo mysql_num_rows($result) ? $hashtag.' found<br>' : $hashtag.' not found<br>';
    }
}

Sorry everyone it's mysql - been using CI query builder recently so haven't gotten around to the mysqli syntax, or even PDO.

paulkd 59 Newbie Poster

Hi Sabarinadh,

Did you copy and paste?
Is the error pointing to the line which I supplied?

I have tested it here and all is well.

paulkd 59 Newbie Poster

You need an ajax call that will perform a php file_exists and return json true or false.

Your form should be prevented from being submitted via the submit button (and users pressing enter in one of the input fields).

The submit button should run the ajax and display the overwrite prompt if the ajax call returns true.

The form can be submitted using JavaScript.

paulkd 59 Newbie Poster

I haven't checked your code, but there's no need to use $location

if (in_array($search_zip, $loc1))  { 
    header("Location: http://dr.gorillaadvertising.net/no-service-in-your-area/"); die;
} else { 
    header("Location: http://dr.gorillaadvertising.net/order-dry-cleaning/"); die;
}
paulkd 59 Newbie Poster

I don't have the technical words, but you essentially use a parent/container as an event handler container (what?). I've set up a jsFiddle to demo. Hope it helps.

jsFiddle

paulkd 59 Newbie Poster

You don't actually say what your problem is - are you looking for SQL code or do you have an error message?

switch($id) {
    case: 5 :
        header('location: /personal.php');die;
        break;
    case 35 :
        header('location: /admins.php');die;
        break
    }
}
paulkd 59 Newbie Poster

Sorry M/ you misunderstand. I messed up on daniweb, my attached image didn't render as anticipated amongst other things.

<M/> commented: oh, now i understand +0
paulkd 59 Newbie Poster

If I understand correctly, you are populating a select based on the value chosen from a previous select. When all 3 options are chosen you want the value of the first select and the index (rather than value) of the options chosen for the remaining selects to be submitted.

You could use a hidden form field <input name="idlist" type="hidden" value=""> which will be updated by JavaScript (jQuery) as each option is chosen. e.g. <input name="idlist" type="hidden" value="155,3,2>

paulkd 59 Newbie Poster

...was asked for some php file upload code, so I thought I would post some stripped down, barebones code that I use in admin/dashboard pages to add/change images associated with products.

Please see attached image for folder setup.

The code uses the jQuery Form plugin by Mike Alsup.

index.php has two forms; one for the image uploads and the other to show where you would have your "product add/update" form. Files are immediately uploaded to a tmp directory whenever you select an image. If you change your mind a few times you can end up with lots of images in your tmp folder, so there is a small routine to empty the tmp folder whenevery index.php is called.

<?php
//remove old tmp files
$tmpImageFolder = $_SERVER['DOCUMENT_ROOT'].'/assets/images/tmp';
$files = glob($tmpImageFolder.'/*.*');
if ($files){
    foreach($files as $filename){
        unlink($filename);
    }
}
?>
<!DOCTYPE html>
<html>
<head>
    <title>Upload File Demo</title>
    <style>
    /* hide the browse button */
    #input-file {
      display:block;
      height:0;
      width:0;
    }
   </style>
</head>
<body>
    <p><img id="display-image" src="/assets/images/placeholder.jpg"></p>
    <form id="upload" action="/ajax/uploadfile.php" method="post" enctype="multipart/form-data">
        <input id="input-file" name="file" type="file" value="" />
    </form>
    <p><button id="choose-photo" type="button">Choose Photo</button></p>

    <!-- the product form handler can be ajax or standard post -->
    <form id="product-update">
        <!-- use a hidden field to send over new filename. hidden field is updated via the js uploadFile() function -->
        <input id="product-newfilename" type="hidden" value="">
        <!-- Your actual product form data goes here -->
    </form>

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script src="/assets/js/jquery.form.min.js"></script>
    <script src="/assets/js/uploadform.js"></script>
</body>
</html>

CSS is used to remove the ugly "browse" input type="file" control …

paulkd 59 Newbie Poster

Personally, I have no problem with adding these types of flair to my pages. If some browsers cannot see/use them, it's no big deal.

Thanks for the snippet.

<M/> commented: Thanks :) +8
paulkd 59 Newbie Poster

Yes. You are loading 3 pages in vertical order.

paulkd 59 Newbie Poster

OK. I've had forms like this in the past and have wondered "do I really need the checkbox?" if the user enters a value in the text box would this be enough to say that they have selected "Gas: 200" ?

paulkd 59 Newbie Poster

You should look to setting up virtual hosts.

I've set up all my local development sites with their own local domain e.g. project1.dev, project2.dev

Then, drop the <base> :D and stick to absolute

First hit on google

Hope this helps.

Zagga commented: Virtual hosts are very handy when working on multiple sites +5
paulkd 59 Newbie Poster

You said you already have an email function - you can simply feed $message from the code below into your email function.

<?php 

$username = "root"; // Mysql username
$password = "root"; // Mysql password
$db_name = "Stock"; // Database name
$host = "somehost";

mysql_connect($host, $username, $password) or die("Failed to connect to MySQL");
mysql_select_db($db_name); //SELECT THE CORRECT DATABASE

$rs = mysql_query("select ProductID, ProductDescription from Products where ProductQuantity < 1");

if(mysql_num_rows($rs)>0) {

    $message = '<p>The following products are out of stock</p><ul>';
    while($row = mysql_fetch_assoc($rs)) {
        $message .= '<li>'.$row['ProductID'].' '.$row['ProductDescription'].'</li>';
    }
    $message .= '</ul>';

    echo $message;
    //email your $message 

} else {
    //email a message that all products have stock
}


?>
paulkd 59 Newbie Poster

You might need a <thead> and <tbody>

paulkd 59 Newbie Poster

I can send email in PHP

So the answer is Yes.

I presume there is a PHP function you call to remove an item from the database. After this function is run, you should simply run the function that returns the product quantity of the item and then send a PHP email if quantity is less than 1.

Pseudo code (PHP):

decrementProduct($productId);
$product = getProductDetails($productId);
//assumption that returned $product is an array
if($product['quantity']<1) {
    sendNoStockEmail($product);
}
paulkd 59 Newbie Poster

First off, I wouldn't store comma-delimited lists in a database field.
That said, here is some code for you to try.

<?php 

$hobbies = array(
    'Swimming',
    'Trekking',
    'Scuba Diving',
    'Birding'
);

//simulate your database field result
$dbResultHobbies = 'Swimming,Trekking,Birding';

$dbResultHobbiesArray = explode(',',$dbResultHobbies);

?>

<form>
    <?php foreach($hobbies as $hobby): ?>
        <?php if(in_array($hobby,$dbResultHobbiesArray)): ?>
            <p><input name="hobby[]" type="checkbox" value="<?php echo $hobby; ?>" checked="checked"> <?php echo $hobby; ?></p>
        <?php else: ?>
            <p><input name="hobby[]" type="checkbox" value="<?php echo $hobby; ?>"> <?php echo $hobby; ?></p>
        <?php endif; ?>
    <?php endforeach; ?>
</form>
Albert Pinto commented: Thanx Sir..... +2
paulkd 59 Newbie Poster

how can I remove something like everything except for "efg" from "abcdefghijklm" without know what anything is except for "ef"?

var alpha = 'abcdefghijklm';
var pattern = 'ef';
var re = new RegExp(pattern+".");
result = alpha.replace(re,"");
alert(result);
paulkd 59 Newbie Poster

Lines 21 & 22 Change to:-

$('.success').fadeOut(200);
$('.error').fadeIn(200);
paulkd 59 Newbie Poster

Seriously, you posted jquery.min

paulkd 59 Newbie Poster

If your checkboxes are there to purely signify that there will be content in a corresponding text field, then I would lose the checkboxes and simply check for form field content in your form handler.

You have too any forms. "There can only be one" (Highlander) :D

diafol commented: But it must be in a Caledonian accent! :) +14
paulkd 59 Newbie Poster

Sorry, I ran your code five times and every time was successful. The only thing that did error was your fclose - you need to change it to fclose($handle);

RoryGren commented: Thank you! +4
paulkd 59 Newbie Poster

Too woolly/generic.

First hit on Google "javascript os" SkyLight Project

paulkd 59 Newbie Poster

You will need to use JavaScript and ajax.
First you should create a php page that will return true or false for the values you are testing.

e.g. yourwebsite.com/ajax/checkemail.php?email=someone@somewhere.com

When you have done this your main page will use JavaScript to call the ajax page with the user input and update the main page depending on the result.

paulkd 59 Newbie Poster

Hi dhani09,

here's the final bit of jQuery code... added to the main selects page

 <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
 <script>
$(document).ready(function(){

    $("#categories").on("change",function(){
        getSubcategories( $(this).val() );
    });

});

function getSubcategories(categoryId)
{
    var request = $.ajax({
        type: "GET",
        url: 'localhost:8888/getsubcategories.php',
        dataType: "html",
        data: {action:'getSubcategories', categoryId:categoryId}
    });

    request.fail(function(jqXHR, textStatus){
        alert( "ajax request failed: " + textStatus );
    });

    request.done(function(result){
        $("#subcategories").html(result);
    });
}
</script>
paulkd 59 Newbie Poster

Sometimes these things are easier to spot when using the alternate PHP syntax - as your IDE is more likely to highlight better.

<?php foreach($qas as $v): ?>
    <p><input id="text_disabled" style="width:40%" type="text" value="<?php echo $v['question']; ?>" name="questions[]" disabled />
    <select name="selected_answers[]">
        <?php foreach($v['answers'] as $answer): ?>
            <option value="<?php echo $answer; ?>"><?php echo $answer; ?></option>
        <?php endforeach; ?>
    </select></p>
<?php endforeach; ?>
<p><input type="submit" value="Submit Answers">  <input type="reset" value ="Clear Answers"></p>
paulkd 59 Newbie Poster

Have you thought about using a GUI - e.g toad or workbench ?

http://www.toadworld.com/Default.aspx

http://www.mysql.com/products/workbench/

and just run the script from within.

savedlema commented: Thanks. What would the script for use on Workbench look like? Same as this? I hope not. But, I actually need the working script because I want to put it in the application that I'm developing with VB.NET. So I need the script so much to take with me. +2
paulkd 59 Newbie Poster

This HTML looks like Click Here

<!DOCTYPE html>
<html>
<head>
<script>
function displayResult()
{
var table=document.getElementById("myTable");
var row=table.insertRow(0);
var cell1=row.insertCell(0);
var cell2=row.insertCell(1);
cell1.innerHTML='<input name="myinput" type="input">';
cell2.innerHTML="New";
}
</script>
</head>
<body>

<table id="myTable" border="1">
  <tr>
    <td>cell 1</td>
    <td>cell 2</td>
  </tr>
  <tr>
    <td>cell 3</td>
    <td>cell 4</td>
  </tr>
</table>
<br>
<button type="button" onclick="displayResult()">Insert new row</button>

</body>
</html>

Code updated with an input in the table cell

paulkd 59 Newbie Poster

@broj1 No worries. I haven't made the move yet.

ibn sumal's SQL is still incorrect.

From the docs...
Procedural style: string mysqli_real_escape_string ( mysqli $link , string $escapestr )
presumably the cause of the warning.

paulkd 59 Newbie Poster

All the things I said before are still relevant.

Here is some more untested "test" code.

<?php
//create the connection between the form and the server
include('connectFileProject.php');

//test vars
$username = 'paulkd';
$_POST['warranty'] = '1';
$_POST['delivery'] = 'second';
$_POST['price'] = '10';

$sql = sprintf("
    INSERT INTO order (
        username, warranty, delivery, price
    ) values (
        '%s', '%s', '%s', %.2f
    )
    ",
    mysql_real_escape_string($username),
    mysql_real_escape_string($_POST['warranty']),
    mysql_real_escape_string($_POST['delivery']),
    mysql_real_escape_string($_POST['price'])
);
$result = mysql_query($sql);  //perform the action
?>
<html>
    <head><title>Test</head>
    <body>
        <p>Did a record get inserted?</p>
    </body>
</html>

I think you are also misunderstanding what constitutes a value in your Price field, and possibly the other fields also.

paulkd 59 Newbie Poster

In your form your price field does not contain an actual numeric - only the string "price"
Your sql is not sure whether it is an insert (INSERT) or an update (SET)
You need to add validation

Here is some untested code to try and help you along. You will probably have to change $_SESSION['username'] to whatever a logged in username variable looks like.

$sql = sprintf("
    INSERT INTO order (
        username, warranty, delivery, price
    ) values (
        '%s', '%s', '%s', %.2f
    )
    ",
    mysql_real_escape_string($_SESSION['username']),
    mysql_real_escape_string($_POST['warranty']),
    mysql_real_escape_string($_POST['delivery']),
    mysql_real_escape_string($_POST['price'])
);
broj1 commented: True +9
paulkd 59 Newbie Poster

Your sendmail_from should be in quotes.

paulkd 59 Newbie Poster