I have added this to my page, but all I get is an empty array ()
This means that the $_SESSION array is empty. Do you have the session_start() function on top of your script? What is the logic to set up the session (populate the $_SESSION array)?
I have added this to my page, but all I get is an empty array ()
This means that the $_SESSION array is empty. Do you have the session_start() function on top of your script? What is the logic to set up the session (populate the $_SESSION array)?
Can you put this code before the code above:
die(print_r($_POST, 1));
It will display the contents of the $_POST array. Please post it here.
What is the error message? Does $_SESSION['clubsId'][0]
have any value? Have you tried to display the query and test it in phpmyadmin:
die("SELECT * FROM cards2 WHERE cardid NOT LIKE '{$_SESSION['clubsId'][0]}'");
It is usually a good practice to test for variable values before using them in queries:
if(isset($_SESSION['clubsId'][0])) {
mysql_query("SELECT * FROM cards2 WHERE cardid NOT LIKE '{$_SESSION['clubsId'][0]}'");
} else {
die('Value does not exist!');
}
You are missing a semicolon at the end of line 5, hence the T_IF error (if statement is not expected there if no semicolon):
session_start()
Same on line 17:
mysql_error($handle)
Studying this plugin code might take some time. I am not sure if I can do it right now. Not promissing anything.
No problem, happy coding :-)
It seems Ajax would be appropriate for this. So on selecting a dropdown the room number would be changed in database but the page would still display the table and the URLs with user IDs. Is this correct?
Just to make things more clear: does each row contain information for different user (user id) or are all rows for the same user?
And info on cookies and session from PHP's point of view:
Is it only that you do not want to to have a submit button or do you not want to reload the page?
In first case you can use onchange event of the select (dropdown).
echo '<select name="room" id ="rooms" onChange="this.submit()">';
The form wil get submitted once you select an option and you do not need a submit button.
In you do not want to reload the page then use Ajax as AHarrisGsy suggested. Ajax is simple to use if you use jQuery. See this link.
You are welcome. Please mark as solved. Happy coding :-)
Sory to come back so late, I was away. The trouble was that the select element (dropdown) was not constructed correctly. Correct code on line 58 is:
<option value="<?php echo $category ?>"> <?php echo $category ?> </option>
You missed double quotes for the value attribute and forgot to echo the category.
Post the whole script, please.
My code was just an example. You should adapt it to your particular script.
You can also insert multiple sets of values in one query:
INSERT INTO table_name
(column1, column2, column3)
VALUES
(value1, value2, value3),
(value4, value5, value6),
(value7, value8, value9)
You should have defined action attribute in the <form> tag which is the name of the script that will process the data. The script should go something like this:
<?php
// if submited the value will be in the $_POST['expenses'] element of the $_POST array
// (provided that the method is POST, otherwise change it to $_GET).
// so check for the existence of $_POST['expenses'] (or $_POST['submit']) and use the value
if(isset($_POST['expenses'])) {
$expenses = $_POST['expenses'];
}
?>
You use the Database class for handling DB. Does this class have a method for displaying errors? You should use it to figure out what is wrong.
Can you change the query this way and post what gets displayed by the die() statement:
echo '<option value="' . $rows['cat_id'] . '">' . $rows['category'] . '</option>';
What is cPath?
Run this query in phpmyadmin and post the output here:
SHOW CREATE TABLE categories
If the category ID is the first field in the database then change the value part of the select code:
echo '<option value="'.$rows[0].'">'.$rows[1].'</option>';
If does not work post the structure of the categories table here.
Have tried to copy the displayed query into phpmyadmin (after removing quotes arround curdate)?
One of the reasons for not inserting could be in the fact that you are missing spaces after the database name and after the VALUES keyword. And surround the array elements in the query with curly braces. Try to change the query this way:
$database->ExecuteQuery("insert into posts (post_id,title,description,post_by,cat_id,post_date) values ('$post_id','{$_POST[title]}','{$_POST[question]}','{$_SESSION[login_name]}','{$_POST[category]}','curdate()')");
Post the query here.
It works in my improvised environment. Can you please put this line of code on the line 126 in your code above:
die("insert into posts(post_id,title,description,post_by,cat_id,post_date) values('$post_id','$_POST[title]','$_POST[question]','$_SESSION[login_name]','$_POST[category]','curdate()')");
It will print out the query and stop the script. Please post the output here. You can also copy the query into phpmyadmin and test it there.
Yes, only for the page with the select element (drop down). I will try it in my environment.
OK, so you have three select elements (drop down boxes): cPath, select_model and select_year. When user selects the data, you send over only cPath. Is that correct?
Now, if you want to store other two values into session, you have to send them over, too. Which means you have to add them to the query string:
$.ajax({
type: 'POST',
url:baseDirectory+"modellist.php",
data:"cPath="+cPath+"&my=1&select_model=" + select_model + "&select_year=" + select_year,
success: function(data){
...
In modelist.php script you first store these values into session and then do de rest of the code:
<?php
session_start();
$_SESSION['cPath'] = isset($_POST[cPath]) ? $_POST[cPath] : '';
$_SESSION['select_model'] = isset($_POST[select_model]) ? $_POST[select_model] : '';
$_SESSION['select_year'] = isset($_POST[select_year]) ? $_POST[select_year] : '';
require('includes/application_top.php');
$manufacturers_id=$_REQUEST['cPath'];
...
If my assumptions about your code are wrong, please correct me. And it is recommended to avoid using $_REQUEST. It is safer to use $_POST.
Can you post the code for the whole script.
Add a value attribute to each option tag:
echo '<option value="' . $rows[1] . '">'.$rows[1].'</option>';
And make sure you enclose the select element in <form> </form> tags?
Can you specify which data exactly would you like to store in session, please.
You pass the selected values to modellist.php by ajax for some processing, using $_POST
array, if I got the code correctly. So the modellist.php script would be good candidate to save values to the session. IN modellist.php just assign the values to the $_SESSION
array using their names for associative keys.
<?php
session_start();
$_SESSION['cPath'] = $_POST[cPath];
$_SESSION['select_model'] = $_POST[select_model];
$_SESSION['select_year'] = $_POST[select_year];
It is even better if you check for existence of $_POST
elements first:
$_SESSION['cPath'] = isset($_POST[cPath]) ? $_POST[cPath] : '';
$_SESSION['select_model'] = isset($_POST[select_model]) ? $_POST[select_model] : '';
$_SESSION['select_year'] = isset($_POST[select_year]) ? $_POST[select_year] : '';
I hope I got the code right :-)
Depends on what your unique key(s) is (are) in the database. You use unique key(s) to construct the input fields in the form and then to use input data to update targeted rows in the database (using WHERE clause).
Main problem in your code is, in my opinion, the fact that you use different names for database fields, form element names (which are used also in the $_POST as indexes) and variable names. And the names are not very descriptive. The result is that I do not understand the code and you have troubles spotting errors.
$count is not supposed to increment. It is the total count (length) of the $_POST['text1'] array:
$count = count($_POST['text1']);
OK. Is this what you wanted?
is it posible to handle or control the loop, i mean to display only a one record from loop
Yes, if there is any value that you can compare it to the counter $i.
for($i = 1; $i < $count; $i++) {
...
// compare the counter to something and break out of loop if true
if($i == somecondition) {
break;
}
}
The queries look OK. There could be two reasons for the error (as far as I can see):
The code looks nice and clean. The only question I have is what is the purpose of code on line 52:
if($i <= $url_count - 1) {
$query = 'INSERT INTO `ASX_PRICES` (`ASX_CODE`, `ASX_PRICE`, `DATE`) VALUES ';
}
The original purpose was to add comma between each set of values (but not at the last set of values, so you do not get an sql error). In your case it should throw an error in sql.
WHere do you keep the list of URL's? If it is a file or an array then do a while or foreach or for loop reading the urls, getting the value and add values to the insert query:
// your URLs (in an array in this example)
$url_list = array(
'http://asx.com.au/asx/markets/priceLookup.do?by=asxCodes&asxCodes=ONT',
'http://...',
'http://...',
);
// count of URLs
$url_count = count($url_list);
// temporary counter
$i = 0;
// start the query
$query = 'INSERT INTO ASX_PRICES (ASX_CODE, ASX_PRICE, DATE) VALUES ';
foreach($url_list as $url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$var = curl_exec($ch);
curl_close($ch);
$first = stripos($var, '<th scope="row" class="row"><a href="' . $url . '"', 0) ;
$second = stripos($var,'<td class="change indicator" nowrap>', 0);
echo substr($var, $first, $second - $first);
echo "<br />";
// get the ASX_CODE and ASX_PRICE from the substring above (maybe using a regex)
// and add to insert query
$ASX_CODE = ...
$ASX_PRICE = ...
// get the date (wherever it comes from)
$date = ...
// add to the query
$query .= "('$ASX_CODE', '$ASX_PRICE', $date)";
// increase the counter
$i++;
// if it is not the last value, add the comma
if($i < $count - 1) {
$query = ', ';
}
}
Not sure if I got what is your intention but I hope it helps.
I am not sure if I understand the question. Which particular data do you want to update and with what data? You probably know how do do the update query:
$query = "UPDATE election SET nomine_id='$nomineeid', vote_gain='$voted', vote_gain_p='$p_vote', casted_d_t=NOW() WHERE invst_id_ar='$nd'";
This is again just an example since I do not know what you want to do. It would help if you explain what is on the screen and what is used supposed to do.
My opinion: if you develop a complex site start using it soon since it will help you keep your code organized and under control. But it might take some time to learn it and it is probably not a good idea to learn on a real project. Well, I am not sure if I was helpful at all with this answer.
Message: Cannot modify header information - headers already sent
I am not sure if this is related to your previous problem but this particular one is due to sending some HTML output before sending all the HTTP headers. So if you use header()
php function in your admin.php script you should not send any html before this function (not even a space), or try to use output buffering as suggested by szabizs in his post.
The query does not change. The code above is just for constructing the table and getting posted values into input boxes. Or have I understood your question incorrectly?
Provided that $result has one element less than $productItems:
foreach($productItems as $key => $item) {
if(isset($result[$key])) {
$productItems[$key]['price'] = $result[$key];
}
}
It is a HTTP 500 error which is a very general and not telling details. Is this on your server or hosted? It would help if you could have a look at the server logs.
If it is the code of the script that causes the error you could use this very simple debugging technique: put something like a die('**************')
statement on the very first line of the script and see if it gets displayed. Move this statement line down and see if it gets displayed. Repeat this process until you get the error 500 displayed. That is how you can identify the line of code where things go wrong. But it is not guaranted this method of debugging will work.
Check also your setting for the display_errors directive, as szabizs suggested. If it is set to false (prior to php 5.2.4) the errors won't get displayed.
In this case you better construct the html code for table rows programatically with php. The current entered values are stored in $_POST. So you can set each field's value attribute to corresponding $_POST element if exists (you have to check if exists using isset()).
<?php
echo '<table>';
// I do not know how many rows do you have, I'll do it by your example of three rows
for($i = 0; $i < 3; $i++) {
// row number
$rowNo = $i + 1;
echo '<tr>';
echo "<td id=\"a$rowNo\"":
echo 'class="box190">» <input type="hidden" name="nd[]" value="';
// check if value exists in $_POST and if yes asign it to the attribute
// otherwise assign row number (judging from your code)
echo isset($_POST['nd'][$i]) ? $_POST['nd'][$i] : $rowNo;
echo '" /></td>';
...
}
echo '<table>';
?>
Again this is just an example of principle. I am not sure how the logic in your code works so please adapt it.
Wrap the button group in a div and make that div hidden:
<div id="button-group">
...
</div>
The CSS:
#button-group {
visibility:hidden;
}
Code for the last button:
<div class="buyOrSellBox">
<input id="memberRoleIntlBoth" value="both"
onclick="document.getElementById('userrole-error').style.display='none';changesubmitbtnname('yes');"
name="userrole" style="border: 0px none ;" type="radio"
<?
// the condition is:
// if $_REQUEST['userrole'] is not set (none of the radio buttons have been chosen)
// or the 'both' radio button has been chosen
// then make it checked
if(!isset($_REQUEST['userrole']) || (isset($_REQUEST['userrole']) && $_REQUEST['userrole']=="both")){
echo 'checked="checked"';
}
?>
/>
I want to make this field "Hidden"
Which field do you want to make hidden - one button all the whole button group?
The manual for empty says:
Returns FALSE if var exists and has a non-empty, non-zero value. Otherwise returns TRUE.
The following things are considered to be empty:
"" (an empty string)
0 (0 as an integer)
0.0 (0 as a float)
"0" (0 as a string)
NULL
FALSE
array() (an empty array)
$var; (a variable declared, but without a value)
So 0 is empty (sounds a bit strange to me, we need to be careful with this function).
A few notes here:
szabizs correctly spotted the error and suggested solution to existing code. I usually have to add my raving about security since this is my field of work :-) (and I had to learn it a hard way).