paulkd 59 Newbie Poster

I've recently added The Uniform Server to my bookmarks.

But I currently used WAMP

paulkd 59 Newbie Poster

David,

Yes. I now see that your arrays are starting at 1. I created my test data with a simple array(3,10) (for weight etc) which meant that they start at 0.

Glad to help.

paulkd 59 Newbie Poster

For the largest volume, are you interested in the actual largest volume or the box's index of the largest volume or both?

paulkd 59 Newbie Poster

For lazyness I've just updated your $_GET array

$_GET['totalWeight'] = 0;
for($i=0; $i<$_GET['packageCount']; $i++) {
    $_GET['totalWeight'] += $_GET['weight'][$i];
    $_GET['volume'][$i] = $_GET['width'][$i]*$_GET['length'][$i]*$_GET['height'][$i];
}
paulkd 59 Newbie Poster

The file contents are displayed.

paulkd 59 Newbie Poster

The zip file you attached had lots of JavaScript files. But you say the app doesn't work

...because the Javascript is missing

If you simply want the icons to appear in your page then stick some non-breaking spaces instead of my debug H1 :-)

Not really sure at this point what is and what isn't working.

paulkd 59 Newbie Poster

The app doesnt do anything because the Javascript is missing.

Then pritaeas's answer is the best for your original question.

paulkd 59 Newbie Poster

Although I've not tested this..
Your ajax php page should query the database for the supplied email address and return json_encode(true) if the email address is already used and return json_encode(false) if not.

Your form will use the following (untested) jQuery:-

$(document).ready(function(){

    //default form not submitted
    $("#submit-button").data("submitted",false);    

    //prevent enter key in input field from submitting form
    $("#your-form").on("submit",function(e){
        if($("#submit-button").data("submitted")===false) {
            e.preventDefault();
        }
    });

    //trigger form submission
    $("#submit-button").on("click",function(){
        checkEmail();
    });

});


function checkEmail()
{
    $.ajax({
        type : "GET",
        url: '/path/to/your/ajax/checkemail.php',
        dataType: "json",
        data: ({
            email: $("#email").val()
        }),
        success: function(emailExists)
        {
            if(emailExists) {
                alert("email already exists");
            } else {
                $("#submit-button").data("submitted",true);
                $("#your-form").submit();
            }
        }
    });             
}

My example shows three css ids: your-form for the <form id= tag, submit-button for the <input type="submit... tag and email for your user's email input field. You will need to substitute your own.

First thing to do is create and test your ajax page without using JavaScript - simply call the page as previously mentioned and output the word true or false.

paulkd 59 Newbie Poster

There is no string company name in the code you published.

The code you published looks okay. Is the error really with the code you have published?

paulkd 59 Newbie Poster

You work at it.
Although icons didn't display in IE... the actual app you have doesn't do anything in Chrome or FireFox. Did you write the code? Do you have a proof-of-concept that draws on the canvas?

paulkd 59 Newbie Poster

Thats SOME progress I guess.....so now what?

Welcome to web development :-)

paulkd 59 Newbie Poster

I would say yes. Depends on your definition of OS and what features your OS will provide.

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

Expanding on what TonyG says... it's a matter of preference whether you use single or double but just like HTML tags they should be correctly wrapped.
I personally prefer single quotes and string concatenation. I try not to echo HTML by using the PHP alternative syntax, which keeps my editor's syntax highlighting happy also.

<?php 
$student = 'Mary';
echo '<p>Student: '.$student.' - Results</p>';
echo "<p>Student: $student - Results</p>";
echo "<p>Student: {$student} - Results</p>";
?>
<p>Student: <?php echo $student; ?> - Results</p>
paulkd 59 Newbie Poster

I made something appear in IE9 with the following insertion

<canvas id="can" width="550" height="550"></canvas>
<h1>PKD #1</h1>
<div id="botones"><h1>PKD #2</h1>
paulkd 59 Newbie Poster

Possibly and/or canvas

paulkd 59 Newbie Poster

I suspect you have a cross-browser JavaScript issue.

paulkd 59 Newbie Poster

For some purpose i need to echo it. =)

Which is why I asked why?

If you simply output HTML without echo there is no need to worry about double quotes.

paulkd 59 Newbie Poster

Just wondering why you want to echo :-)

paulkd 59 Newbie Poster

Yes. If PHP....

http://php.net/manual/en/function.mysql-insert-id.php Although deprecated, has links to alternatives.

paulkd 59 Newbie Poster
paulkd 59 Newbie Poster

Is the problematic page publicly available to view?

paulkd 59 Newbie Poster

Like Squidge said. You are already accessing the database to display product information, so it shouldn't be difficult to add another column to contain productTitle information and inject it into the <title> tag.

paulkd 59 Newbie Poster

Beware. The site has links to malware sites according to Chrome.

paulkd 59 Newbie Poster

Are you saying you have a database table with 2, possibly 3 columns?

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

Here is some code which I think is what you are trying to set up. Let me know if I've misunderstood.

<form>
    <p>Categories <select id="categories" name="category">
        <option value="">Select...</option>
                    <option value="1">Motor Cycles</option>
                    <option value="2">Computing</option>
                    <option value="3">Musical Instruments</option>
                    <option value="4">Cars</option>
                    <option value="5">Farming</option>
            </select></p>
    <p>Sub-Categories <select id="subcategories" name="subcategory"></select>
</form>
paulkd 59 Newbie Poster

Hi,

I've found the problem. I'm constantly learning too. You will be able to see the result in your browser by "view page source" Firefox displays the code fragment to the page, Chrome (and presumably other browsers) don't.

paulkd 59 Newbie Poster

can you paste the actual url here? I know it's localhost.

paulkd 59 Newbie Poster

Hi dhani09,

Can you copy the code into a php file and run it.

if you called it getsubcategories.php can you run it with the following at the end ?action=getSubcategories&categoryId=1

like this... getsubcategories.php?action=getSubcategories&categoryId=1

paulkd 59 Newbie Poster

First we'll get your "ajax page" working... which will display the subcategories

I've simulated a database with the following code. You will do real db queries.

<?php 
$databaseData = array(
    1 => array(1=>'Honda',2=>'Kawasaki',3=>'Suzuki',4=>'Yamaha'),
    2 => array(1=>'Desktop PCs',2=>'Games Consoles',3=>'Laptops'),
    3 => array(1=>'Drums',2=>'Woodwind',3=>'Guitars',4=>'Keyboard'),
    4 => array(1=>'Audi',2=>'BMW',3=>'Fiat',4=>'Ford',5=>'Honda'),
    5 => array(1=>'Cattle',2=>'Livestock',3=>'Chickens')
);
if( isset($_GET['categoryId']) AND array_key_exists($_GET['categoryId'],$databaseData) ) {
  $subcategories = $databaseData[$_GET['categoryId']];
  $html = '<option value="">Select...</option>';
  foreach($subcategories as $id => $subcategory) {
      $html .= '<option value="'.$id.'">'.$subcategory.'</option>';
  }
} else {
   $html = '';
}
echo $html;
?>

place this code into a file (maybe in an ajax folder) and test as you would on your localhost e.g.

http://localhost/ajax/getsubcategories.php?action=getSubcategories&categoryId=1

Let me know how you go on.

paulkd 59 Newbie Poster

Ok, I need some more information about what you are wanting to accomplish. I don't want code, just a simple a, b, c, d... of the requirements

a. You populate your select options from a database table
b. you select a value from the drop down
c. ????

paulkd 59 Newbie Poster

dhani09 are you open to using jQuery?

paulkd 59 Newbie Poster

If your CMS allows you to use JavaScript and ajax to post data, you can get away without the form tag.

paulkd 59 Newbie Poster

Simply add this after the <select>

    <option value="">Select Answer...</option>

above line 4 in my code snippet.

paulkd 59 Newbie Poster

Where is the php script executing from? Server1 or Server2?

paulkd 59 Newbie Poster

It looks like there already is a record with patientid = a67

I would expect patientid to be in your where statement (where patientid='a67') not in your update statement.

paulkd 59 Newbie Poster

sri,

As far as I could tell your original code worked, you just didnt output the result. I outputted the result to console on my line 8.

paulkd 59 Newbie Poster
<form class="form1" action="linksaddform.php" method="post" enctype="multipart/form-data" name="links_upload_form" id="links_upload_form" style="margin-bottom:0px;">
    <p><?php for($i=0; $i<9; $i++): ?>
    <b>Link</b> <input type=text name="alink[]">
    <b>Description</b> <input type=text name="aname[]"><br />
    <?php endfor; ?></p>
    <input type="submit" name="submit" value="Upload Links" />
    <input name="submitted_form" type="hidden" id="submitted_form" value="links_upload_form" />
 </form>
 <?php

// include '../inc/connect.php';
      if (isset($_POST['submit'])) {
         foreach($_POST['alink'] as $key => $notused) {
             $test = trim($_POST['alink'][$key].$_POST['aname'][$key]);
             if(!empty($test)) {
                echo "mysql_query(INSERT INTO links VALUES ('', '{$_POST['alink'][$key]}', '{$_POST['aname'][$key]}')".'<br>';
             }
         }
      }

?>

Just to confirm that this will echo the sql to the screen

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

Line 41 :-)

echo "<select name='selected_answers[]>";
paulkd 59 Newbie Poster

I use the following meta tag:-

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />

There's a MS article here

Click Here

paulkd 59 Newbie Poster

As a quick hack you could try amending

if (DIRECTORY_SEPARATOR !== '\\')

on line 1064 to

if (DIRECTORY_SEPARATOR !== '\\***')

to see if the fallback function on 1118 works

paulkd 59 Newbie Poster

What event must happen for your JavaScript to submit the form?

paulkd 59 Newbie Poster

I think you left out the display result bit....

$(document).ready(function(){

    var array = ["foo","fool","cool","god",'searchstring'];
    var src_keyword="";
    $("#search_str").click(function(){
        src_keyword=$("#str_search").val();
       result =  find(array,src_keyword);
       console.log(result);
    });
});

function find(arr,src_keyword1) {
    var result = [];
//    alert(src_keyword1);
    //src_keyword1="oo";
    for (var i in arr) {
        var search = new RegExp(src_keyword1, "gi");
        if (arr[i].match(search)) {
            result.push(arr[i]);
        }
    }
    return result;
}
paulkd 59 Newbie Poster

What's really strange, is when I load the google developer tools and refresh, it corrects itself.

paulkd 59 Newbie Poster

@joshl_1995

Sorry I phrased my last post badly. I meant to ask is that the kind of scenario you are trying to accomplish.

If not, can you do a similar list?

paulkd 59 Newbie Poster

as per pritaeas suggestion...

$char   = '3';
$string = '101131110|101131110|';

$string = str_replace('|', '', $string);

$positions = array();
$pos = -1;
while (($pos = strpos($string, $char, $pos+1)) !== false) {
    $positions[] = $pos+1;
}

$result = implode(',', $positions);
print_r($result);
paulkd 59 Newbie Poster

Did you fix your problem? Seems to work fine (on Chrome) for me.

paulkd 59 Newbie Poster

This is for a collage assignment and we are not allowed to use jquery...They are only interested in the students using the tools they cover in the course.

But you are using JavaScript. jQuery is simply a user defined JavaScript function. :)