broj1 356 Humble servant Featured Poster

I do not exacly understand what you want to achieve. Can you describe please.

broj1 356 Humble servant Featured Poster

Also you probably meant:

define('THIS_PAGE', $pagename);

since $pagename probably comes from user's choice. I think using constans here is not appropriate since you are actualy testing for a value of a variable.

broj1 356 Humble servant Featured Poster

Define is used for defining constants and constans once defined can not be changed (by another define). You can always test if the constant has already been defined:

if(!defined('THIS_PAGE')) {define('THIS_PAGE', 'pagename')}
broj1 356 Humble servant Featured Poster

An error could also be on line 13

$upperlimit = mb_substr($datecomponentsyear,0,10);

You should propbably use $upperlimit for calculating the upper limit:

$upperlimit = mb_substr($upperlimit,0,10);
Goldfinch commented: Thanks!, this post and the one before it were very helpful +0
broj1 356 Humble servant Featured Poster

Your code contains several statements of this form

$var=bad-date;

If you intended to assign a string 'bad-date' to $var enclose it with quotes.

Before displaying image you should then test the $var if it contains valid date:

if($var != 'bad-date') {

    $imagepath="daily/$var.gif";
    ...
}
broj1 356 Humble servant Featured Poster

Just my guess since I havent seen the code of the addDetails.php page: On addDetails.php you will get the ID of the country and this is the information you want to store so you do not need a country name at all (or do you?). In case you really need it you can put it in a hidden field on the previous page and it will be sent over to addDetails.php in the $_POST array. Hope this helps.

broj1 356 Humble servant Featured Poster

It is OK. And typos happen all the time :-).

If the problem is solved please mark the thread as solved. Happy coding.

broj1 356 Humble servant Featured Poster

Sorry, disregard my last post, I see you already explained that.

Please post the addDetails.php page code too since everything is happening there.

broj1 356 Humble servant Featured Poster

You need to tell me what are the fields $countryName[$i][0] and $countryName[$i][1] in the tabče county (the first two fields).

broj1 356 Humble servant Featured Poster

The values are already in an array $countryName so just use them.

Maybe you post the whole code so I can get the picture.

broj1 356 Humble servant Featured Poster

Have an array with indexes the values and elements the words you want to represent the values:

$numbers_array = array('1' => 'one', '2' => 'two', '3' => 'three');
// wrap everything within form tags
echo '<form action="#" method="post">';

// use PHP to construct the select element
echo '<select name="numbers">';
foreach($numbers_array as $value => $text) {
    echo " <option value='$value'>$text</option>"
}
echo "</select>";
// submit button
echo "<input name="submit" value="Submit" />";
echo "</form>";

// check if submit button was pressed
if(isset($_POST['submit'])) {
    $chosen_value = $_POST['numbers'];
    // display chosen value and text
    echo $chosen_value . ' - ' . $numbers_array[$chosen_value];
}
nidhzee11 commented: thanks..plz solve this also +0
broj1 356 Humble servant Featured Poster

Yes there are errors:

  1. remove all ... from the code. They are there for your code to insert if needed.
  2. On line 25 the $ is missing (my typo)
  3. On line 26 the $ is missing (my typo)
  4. On line 44 the $ is missing (my typo)

Sory for the typos. Here is the correct code (I hope):

<?php
//$qg=$_GET["q"];
$name="Ramana Sethi";
$con = mysql_connect('localhost', 'root', '');
if (!$con)
{
    die('Could not connect: ' . mysql_error());
}
mysql_select_db("testdb", $con);
$sql="SELECT * FROM peoplegrid WHERE Employee ='$name'"; //'".$q."'";
$result = mysql_query($sql);
//provided by Daniweb.Bojoe Recko
$rows_array = array();
// index for row numbers
$row_no = 0;
// firs store all data in a multidimensional array
while($row = mysql_fetch_array($result))
{
    $rows_array[$row_no] =$row;
    $row_no++;
}

// display the table rows
foreach(rows_array as $row) {
    echo "<tr>";
    echo "<td>" . $row['Firstname'] . "</td>";
    echo "<td>" . $row['Function'] . "</td>";
    echo "<td>" . $row['City'] . "</td>";
    echo "<td>" . $row['Rank'] . "</td>";
    echo "</tr>";
}

echo "</table>";
// address the cell (Rank in row 4 if exist)
$myRank = $rows_array[3]['Rank'];
echo $myRank;
mysql_close($con);
?> 
broj1 356 Humble servant Featured Poster
broj1 356 Humble servant Featured Poster

IP of the machine browsing your script: $_SERVER[REMOTE_ADDR]

If behind proxy (does not work always): $_SERVER['HTTP_X_FORWARDED_FOR']

broj1 356 Humble servant Featured Poster

You can store the rows in question in an array (could impact performance if the fieldset is large).

$rows_array = array();
// index for row numbers
$row_no = 0;

// firs store all data in a multidimensional array
while($row = mysql_fetch_array($result))
{
    $rows_array[row_no] =$row;
    row_no++;
}

...

// display the table rows
foreach(rows_array as $row) {

    echo "<tr>";
    echo "<td>" . $row['Firstname'] . "</td>";
    echo "<td>" . $row['Function'] . "</td>";
    echo "<td>" . $row['City'] . "</td>";
    echo "<td>" . $row['Rank'] . "</td>";
    ...
    echo "</tr>";
}

...

// address the cell (Rank in row 4)

$myRank = rows_array[3]['Rank'];

But as I said it would be preferrable if you had another column for row numbers in your database table which would be the primary key and would help you updating particular fields. That field would replace the $row_no variable.

Just a note: spreadsheet table and database table are not exactly the same though the concept is similar.

broj1 356 Humble servant Featured Poster

More user friendly solution would be to offer movie IDs in a drop down list (html select element). In that case user can not select an invalid ID and they also do not have to remember all IDs (you can display movie names in the select element). Of course if there are too many IDs (say hundreds) this option would not be appropriate.

broj1 356 Humble servant Featured Poster

Check whether the query returns any records. Insert the following code between lines 7 and 8 and copy the output query in phpmyadmin:

die("SELECT * FROM messages WHERE to_user = '$to_user' AND deleted = 'no'");

It could be that the variable $to_user has no value yet.

broj1 356 Humble servant Featured Poster

To access fields of a row use associative index that mysql_fetch_array function returns:

echo $row['Firstname']." - ".$row['Rank'];

To address particular rows (using SELECT, UPDATE or DELETE queries) you have to use WHERE condition(s) that return just one row. In your case it would be a good thing to have another unique field for each row (e.g. id) which would be also a primary key. It enables you to address particular row and also improves performance.

broj1 356 Humble servant Featured Poster

Have you tried to count the actual records that the query returns as I suggested in my next post? Or have you tried to test the query in phpmyadmin?

broj1 356 Humble servant Featured Poster

Or put a counter within a while loop and see how many rows you get (you might use PDO's number of rows function):

public function headLoad()
{

    // debug ceounter
    $i = 0;

    $cxn = $this->connection()->prepare("SELECT scriptCode FROM head_scrips WHERE active = '0'");
    $cxn->execute();
    $cxn->setFetchMode(PDO::FETCH_ASSOC);
    print "<script>";
    while($row = $cxn->fetch())
    {
        print $row['scriptCode'];

        // increase the counter
        $i++;
    }
    print "</script>";

    // print the counter
    echo "Number of rows: $i";
}
broj1 356 Humble servant Featured Poster

Just a dumb question: if you want to get active scripts why is the condition WHERE active = '0'? Shouldn't it be WHERE active != '0'?

broj1 356 Humble servant Featured Poster

From the error message one could conclude that the query returns 0 rows and therefore 1st row (index 0) can not be accessed. Please test the query with the actual parameters by inserting this code right after line 14:

die("SELECT `logs_id` FROM `school_logs` WHERE `school_user` = '$school_user' AND `school_id` = '$school_id'");

Copy the output into phpmyadmin or mysql client and see if the query returns any rows. Maybe the WHERE condition returns no rows.

broj1 356 Humble servant Featured Poster

If page two is included in page one you can use variables from page one in page two straight away. If they are different variables they should have different names.

broj1 356 Humble servant Featured Poster
broj1 356 Humble servant Featured Poster

OK, but as I stated in my previous post please send the contents of the $_SESSION before the for loop (see above). Even better if you send the contents of the $_SESSION both before and after the foor loop so we can compare. Use the following code:

else if(isset($_REQUEST['command'])=='update'){

    // this will display the contents of the $_SESSION['cart'] before the update
    print_r($_SESSION['cart']);

    $max=count($_SESSION['cart']);
    for($i=0;$i<$max;$i++){
        $pid=(isset($_SESSION['cart'][$i]['productid']));
        $q=intval($_REQUEST['product'.$pid]);
        if($q>0 && $q<=999){
        $_SESSION['cart'][$i]['qty'] = $q;
    }

    // this will display the contents of the $_SESSION['cart'] after the update
    // and end the script
    die(print_r($_SESSION['cart'], 1));

    else{
        $msg='Some proudcts not updated!, quantity must be a number between 1 and 999';
    }
}
weirdCreature7 commented: thank you so much! :) +0
broj1 356 Humble servant Featured Poster

Can you post the contents of the $_SESSION['cart'] before updating? Put this code between lines 12 and 13:

die(print_r($_SESSION['cart'], 1));
broj1 356 Humble servant Featured Poster

You should put a test in the for loop to see whether the displayed number is the number of the current page; if yes then you have to have a code for displaying that number (and no link), otherwise you display a link. It is hard to give a snippet of the code since you do not use very descriptive names for variables. I would use names like $current_page, $total_pages, etc and then it would be a bit easier.

I also suggest you use CSS styles for stylink links and current page number. It is more flexible and does not clutter the code.

There is a PEAR class called Pager that does all this for you neatly. Have alook at it:

http://pear.php.net/package/Pager/
http://www.alberton.info/pear_pager_tutorials.html

Maybe you can use it or have a look at the code.

broj1 356 Humble servant Featured Poster

Your test should be within a loop where $i is defined:

for($i=0;$i<$max;$i++)

Otherwise you can not test for $_SESSION['cart'][$i]

weirdCreature7 commented: It is still not working I really dont understand it anymore :( please help me how will I do it! Thank you so much for the reply :) +0
broj1 356 Humble servant Featured Poster

Check also whether it is not empty:

if(is_array($_SESSION['cart']) and !empty($_SESSION['cart']))

or check for elements one level below:

if(is_array($_SESSION['cart'][$i]) and !empty($_SESSION['cart'][$i]))

or check for elements two levels below:

if(isset($_SESSION['cart'][$i]['productid'])) {

    $pid=$_SESSION['cart'][$i]['productid'];

} else {

    echo 'No product ID!';
}
broj1 356 Humble servant Featured Poster

The links above are referring to the named anchors (1, 2...) on the same page (hence #).

The links above are constructed this way if they are on the page picture.php:

<a href="#1">Picture 1</a>
<a href="#2">Picture 2</a>

or if they are on some other page:

<a href="picture.php#1">Picture 1</a>
<a href="picture.php#2">Picture 2</a>

On the page picture.php you have a named anchor at every img tag:

<a name="1"><img href="picture1.jpg"></a>
<a name="2"><img href="picture2.jpg"></a>

Now users are scrolled directly to the chosen picture.

broj1 356 Humble servant Featured Poster

Sory for jumping in, I just have too much time right now :-). You can not use a function within double quoted string (you can use variables though). Do a concatenation:

$sql = "INSERT INTO `db` (profile image) VALUES " . mysql_real_escape_string($grav_url) . " WHERE id='{$_SESSION['sessid']}'";

This should work provided that the {$_SESSION['sessid']} exists and has expected vaslue.

broj1 356 Humble servant Featured Poster

You are welcome. If you have no more questions regarding this problem, please mark the thread as solved, otherwise we are welcome to leave it open and ask at your own pace. Happy coding.

broj1 356 Humble servant Featured Poster

OK so you want to drag the rows of displayed html table. This is a Javascript job. Have you checked the link pritaeas sent in above post? I think this is the answer for you (have a look at the code in the browser - you will find the css and javascript you need).

confstu commented: thanks once again, i will see pritaeas link and try it +0
broj1 356 Humble servant Featured Poster

I use PEAR now and then. Mostly I use MDB2 package for abstraction of access to a database which I thimk is a pretty good collection of code and (hopefully) enable you to switch to another supported database without much changes to your code. Another package I use is Pager which is excellent for pagging database results. Periodically there might be some issues with packages not following tightly the changes in PHP.

broj1 356 Humble servant Featured Poster

mysql_fetch_array returns a row of the table in a form of an array. You actually are processing row by row already in the code:

while($row = mysql_fetch_array($result))

Within the above while loop you can do anything with the row or the fields of the row.

Can you please explain more in detail what you want to achieve (I hope I did not missunderstand your question).

broj1 356 Humble servant Featured Poster

Maybe you post the last version of the code since so many suggestions came in.

broj1 356 Humble servant Featured Poster

Let's debug the query first. Put this on line 17 and post the output:

die("select Username, Password from registration where Username='$Username' and Password='$Password'");

broj1 356 Humble servant Featured Poster

The trouble could be in your query on line 16 where you should use the variables (but you probably only forgot the $ sign). The correct query would be:

$checkUsername=mysql_query("select Username, Password from registration where Username='$Username' and Password='$Password'");
broj1 356 Humble servant Featured Poster

Just my guess since I am not using Ubuntu but Fedora. I think scripts and web pages should be in a directory that is defined in a webserver configuration (in Fedora and some other distros the config file is /etc/httpd/conf/httpd.conf and the web pages are in /var/www/html). The directories and files should be owned by either a webserver user (apache in Fedora) or just the normal user that created them. The directories on my webserver have permissions rwxr-xr-x and the files are rw-r--r-- and everything works OK. So check your Apache config file and the permissions.

broj1 356 Humble servant Featured Poster

When you click Register button it will bring you to login.php page which I assume is the code from your second post. Does that answer your question?

broj1 356 Humble servant Featured Poster

Maybe (but just maybe) you have a problem since your HTML code has errors. The <table> tag has no matching </table> tag, the last <td> tag has no matching </td> tag, the last <tr> tag has no matching </tr> tag and all this shoukd be properly nested withing <form> tags. The browser might have problems rendering the select element. Just a guess.

broj1 356 Humble servant Featured Poster

Please disregard my previous post since it was wrong. I tested your code now and the code seems to be OK. I get this if I fill in the form and do not select any time value:

INSERT INTO Reminder (Email, Message, Time) VALUES ('myemail@doodle.com','Test message','1')

In my browser the first option is automatically selected and also put into query correctly.

What browser and OS do you use? I have tested your code in Firefox and Chrome on Linux and IE8 on Windows and works OK.

broj1 356 Humble servant Featured Poster

You probably haven't selected any value for hour and that is why the $_POST['hour'] and $time are empty strings. You must decide what to do in such situations: either supply a default value or warn the user that he forgot to select the time.

broj1 356 Humble servant Featured Poster

Or inspect the query and test it in phpadmin (and maybe post it here). Put this on line 13:

die($query);
broj1 356 Humble servant Featured Poster

The $time might be undefined if the user does not chose any value. Make a default value (or set the selected attribute) or warn the user that the time has not been selected.

if(isset($_POST['hour']) and $_POST['hour'] > 0 and $_POST['hour'] <= 24) {

    $time = $_POST['hour'];

} else {

    // set default value
    $time = 0;

    // or warn the user
    echo 'Please select time...';
}
broj1 356 Humble servant Featured Poster

In the php file first check whether the form was submitted:

<?php
// assumming you use method=post
if(isset($_POST['submit'])) {

    // do the insert

    // display thankyou message

    // end the script
    die();
}

// if the form was not submitted, display it
// ...
?>

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

Many developers (including myself) use Eclipse (http://www.eclipse.org/downloads/packages/eclipse-php-developers/heliossr2). Maybe a bit complicted to install and configure but powerful. Quite many also use Netbeans (http://netbeans.org/). I use it now and then at home and find it very good also.

Many text editors also provide syntax checking like Notepad++, KWrite, gedit (both Linux) etc. All the software I mentioned is free.

LastMitch commented: Thanks for the link & suggestion! +2
broj1 356 Humble servant Featured Poster

Change line 13 to:

echo "$pt, ";

mysql_fetch_assoc returns an array (with only one element in above case) and implode returns a string (P1, P2, P3 etc on each iterration).

broj1 356 Humble servant Featured Poster

Most common approach is to store the data from each submitted form in a database table and then create an excel file upon a request (e.g. the administrator can download the excel file by clicking a link).

I hope you have database connection already set and script made to save te data to the database. To export database data to excel search Daniweb or Web by 'php export to excel' or similar term. You should find tons of examples. This is the first one I found on DW: http://www.daniweb.com/web-development/php/threads/124300/how-to-php-export-to-excel

A note on your form: I don't think textareas are the proper form field types for the data you collect. I guess for Name the input type="text" is more appropriate and for numeric values maybe select elements (drop down lists) are better. Textarea is suitable for free text of usually some lenght.

Also it is good to post the code you already have.

broj1 356 Humble servant Featured Poster

Your first input field is:

<input name="textfield" type="text" size="30" />

and the code to process it should be:

<?php $textfield = $_POST['textfield'];?>

But unfortunately I do not know what textfield is for. If it is for example for the email it should have meaningful name like:

<input name="email" type="text" size="30" />

<?php $email = $_POST['email'];?>

And the name attributes for all fields and the associative indexes for the $_POST array should match.

Blindly copying code without understanding it might be unproductive and sometimes dangerous. You might want to seach Daniweb or google for PHP form processing.

Pleasenote: I will not be available until Monday. If you require more help and do not get it before I will be happy to help when I am back.