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

Is the problematic page publicly available to view?

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

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

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

@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

Can you change this scenario

  • form displays - has a value of "1" in field
  • user changes "1" to "2"
  • submits form
  • form displays - has a value of "2" in field
  • user changes "2" to "3"
  • submits form
  • form displays - has a value of "3" in field

etc..

paulkd 59 Newbie Poster

Hi,

They look very similar to me in all but IE7.

But, may I make some suggestions about the layout?

Remove the "Store Number" line, and if you are not too fussed about the numbers lining up vertically put them to the right of the city e.g. Alabama (205)567-7843.

Remove the "By" and just list Phone: (nnn)nnn-nnnn, Email: xxx@xxx.xxx.

Remove the "By search engine" and just link the search engine name in your list e.g. 1. Google, 2 Bing.

paulkd 59 Newbie Poster

Hi,

I'm not understanding what your goal is, so wondering if it can be achieved without looping.
Can you explain some more scenarios of the makeup of your strings (haystacks) and chars (needles)?

paulkd 59 Newbie Poster

Are you looking to store a "history" of the value changes or to simply continue to overwrite them with each form submission?

paulkd 59 Newbie Poster

justzamir, pixelsoul's question was

What exactly is it that is supposed to happen when you hover the image

Do you want a different image to appear instead of the panda?

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

Are you able to provide the HTML code?

paulkd 59 Newbie Poster

Your sendmail_from should be in quotes.

paulkd 59 Newbie Poster

Your logic is a little off.
If your input box is 100 and your subtract that value from itself - that will be zero.
There needs to be a Balance field as well as a field that is containing the value to subtract from the Balance.

paulkd 59 Newbie Poster

Do you have existing code that you can show?

paulkd 59 Newbie Poster

At line 6 (just before the error) add

if(!$result) {
    echo mysql_error();
    die;
}

to see what error is being reported

paulkd 59 Newbie Poster

Again, untested.

<?php
$conn=mysql_connect("localhost","root","1");
mysql_select_db("society",$conn);

$query = sprintf("
    select id, title, content, pic, date
    from news where id = %d
    ",
    mysql_real_escape_string($_GET['id'])
);
$rs = mysql_query($query,$conn);
//echo mysql_error(); die;

$row = mysql_fetch_assoc($rs);
?>
<a style="color: red;" href="newspage.php?id=<?php echo $row['id']?>"><?php echo $row['title']?></a>
paulkd 59 Newbie Poster

What are the database column names that you are displaying from your database? I'm guessing the first column is "id" what is the name of the second column?

paulkd 59 Newbie Poster

Hmm,

$conn=mysql_connect("localhost","root","1");
mysql_select_db("society",$conn);
$strSQL = "SELECT * FROM news WHERE id=" . $_GET["id"];
$result = mysql_query($strSQL,$conn);
$row = mysql_fetch_array($result);

<a style="color: red;" href="newspage.php?id=<?php echo $row[0]?>"><?php echo $row[1]?></a>
paulkd 59 Newbie Poster

Hi,

You also specificed $rows in your output instead of $row

$conn=mysql_connect("localhost","root","1"); mysql_select_db("society",$conn); $strSQL = "SELECT * FROM news WHERE id=" . $_GET["id"]; $result = mysql_query($strSQL,$conn); $row = mysql_fetch_array($result);

and

<a style="color: red;" href="newspage.php?id=<?php echo $row[0]?>"><?php echo $row[1]?></a>

I haven't done any proper testing. I also prefer mysql_fetch_assoc with $row['fieldname'] and good practice suggests not using select *

:-)

paulkd 59 Newbie Poster

Hi,

How do you know which option should be selected for each page load?

paulkd 59 Newbie Poster

Hi,

Without looking at your code in detail I can see that you haven't executed the query.

e.g. $result = mysql_query($strSQL,$conn);

before your mysql_fetch_array line.

paulkd 59 Newbie Poster
paulkd 59 Newbie Poster

Hi,

Syntax error :-)

setTimeout(function(){alert("my message");location.replace("/new-page.php");},1000);

paulkd 59 Newbie Poster

Hi,

How many names are there?

paulkd 59 Newbie Poster