adam.adamski.96155 43 Junior Poster

I don't see how the hidden input can possibly be populated with the intended value because it is PHP that echoes the value and PHP won't do anything once the page is loaded. $_POST['brand'] needs to exist when the page is loaded for PHP to echo the value onto the page. Pritaeas idea to make your own submit function and use Javascript to populate the hidden element and then submit the form is what I would do. If I have misunderstood your intentions, please excuse me :)

adam.adamski.96155 43 Junior Poster

I answered the same question yesterday so I can just copy and paste :D

You need to make sure all your form elements are contained within a form declaration:

<form action="page_that_will_process_form.php" method="post">
<input type="text"... />
<input type="button"... />
</form>

Make sure each input has a unique name.
<input name="unique_name"... />

Then on the page that will process the form (it can be the same page):

<?php
if( isset($_POST['unique_name']) ){// isset() stops the undefined error.
    if(isset($_POST['button_one'])){
    // Button one was clicked, do appropriate stuff
    }
    if(isset($_POST['button_two'])){
    // Button two was clicked, do appropriate stuff
    }
}
?>

If the button was not clcked, it will not exist as a $_POST variable.

adam.adamski.96155 43 Junior Poster

vaultweller123 is exactly right.

If you declare a variable:
$variable = "value";
...and then you declare the same variable with a different value:
$variable = "another value";
...the variable holds the second value and the first value is lost.
It is the same in your loop, your variable '$url' can only hold one value at a time, so you need to process the value each time through the control loop, for example:

for($x = 0;$x <count($_FILES['image']['name']);$x++){
    //here the value of $url is echoed along with the other HTML.
    echo "<center><td><input type='text' size='50' value=\"";
    echo $url;
    echo "\"/></td><center>";
}

or you can store the value in an array and work with it afterwards:

$urls = new array();
for($x = 0;$x <count($_FILES['image']['name']);$x++){
    $urls[] = $url; //here the value of $url is saved in the $urls array. 
}

then user a foreach, for instance:

foreach($urls as $url){ //no need to count, when there are no more urls, the loop stops.
    echo "<center><td><input type='text' size='50' value=\"";
    echo $url;
    echo "\"/></td><center>";
}

Good luck :D

adam.adamski.96155 43 Junior Poster

I read through the code you posted, it was messy and I felt dirty and soiled :D
But your question is:

any idea how to pass the selected data to the backend page once i click submit ...??

...and my answer is yes, I have plenty idea, and I will explain it to you.
You need to make sure all your form elements are contained within a form declaration:

<form action="page_that_will_process_form.php" method="post">
<input type="text"... />
<input type="button"... />
</form>

Make sure each input has a unique name.
<input name="unique_name"... />

Then on the page that will process the form:

<?php
//print_r($_POST); die();
if( isset($_POST['unique_name']) ){
    //All of your form elements that had a valid name will be available:
    $form_name = $_POST['text_input_name'];
    $form_comment = $_POST['textarea_comment'];
}
?>

Uncomment //print_r($_POST); die(); this line if you want to see what the $_POST variable contains.
Good luck :D

adam.adamski.96155 43 Junior Poster

Your code was hit by a train... on line 1, you open a php code block and you do not close it before inserting standard HTML:

<?php
<tr>
<td>Location Considered </td>
<td align="left" colspan="2">
<?php 

Then you open another PHP code block on line 6 without closing the first unneccessary code block (?>).
I could rewrite the code above to acheive your goal, but what would you learn?

Have a look here for an explanation of how to access the variables in the multiple select box (line 12).
Tidy your code, debug the value of $_POST when the action page loads (print_r($_POST); die();), and post your updated code if you still have problems.

adam.adamski.96155 43 Junior Poster

$loc_considered1 = implode(', ',$loc_considered); is the problem line.
implode() expects parameter one to be a string (which it is) and parameter two to be an array, which it probably isn't. Where is the form that produces the $_POST['loc_considered'] variable?
Can you post that code?

adam.adamski.96155 43 Junior Poster

It means that Invalid arguments were passed to the implode function on line 40 of the /home/tjconsul/public_html/admin/actions/act_addcandidate1.php file.

Show your code.

adam.adamski.96155 43 Junior Poster

You are welcome, keep going :)
Can you mark this thread as solved now?

adam.adamski.96155 43 Junior Poster

Was your code hit by a truck?

#nav ul {
width: 100%;
float: left;
margin: 0 0 0 0;
padding: 0;
list-style: none;
background-color: #fff;
position: absolute;
top: 162px;
left: 550px;
}

You have 100% width AND absolute positioning, I guess the unecessary whitespace is 550 pixels.

adam.adamski.96155 43 Junior Poster

Ok, understood.
Presumably you want the input validated before the form is submitted and only alllowed to continue if the input passes the validation test.
You need to capture the submission of the form and take control which you almost do:
<form onsubmit='checkform();'>
This may not be the correct way, but I have always added return false; at this point to stop the form submitting, it has always worked as intended for me:
<form id="myform" onsubmit='checkform(); return false;'>
Now the function has control of the form input and can decide if the submission is to be refused and a reason given to the user, or allow the form to continue.

If it is decided that the form is okay and can procede the following command will acheive it:
document.getElementById('myForm').submit();

for reference:

<SCRIPT type "text/JavaScript">
function checkform(){
    var user_value = document.getElementById('user').value;
    var error_div = document.getElementById('error_div');
    if (user_value.length < 5){
        error_div.innerHTML = "Please enter a valid Username (5chars+)";
    } else {
        document.getElementById('myForm').submit();
    }
}
</SCRIPT>

and the html:

<form id="myForm" onsubmit='checkform(); return false;'>
<input type="text" id="user" />
<input type="submit" value="submit"/>
<div id="error_div">initial data</div></form>
adam.adamski.96155 43 Junior Poster

You say the code is dead.
What does that mean?
What do you think the code should do?

adam.adamski.96155 43 Junior Poster

if (user.lenght<5) <-- typo of the word length. There may be other things, but your code is so messy I need to format your nested loops to make any sense of them.
There is a great article here regarding the format of your code and loops:
http://phpmaster.com/practical-refactoring-1/

adam.adamski.96155 43 Junior Poster

Hey that's great :)
Can you mark this thread as solved?
Thanks!

adam.adamski.96155 43 Junior Poster

Both of your functions have the same name, so presumably the second version is overwriting the first one, meaning that really there is only one function - the second one. Did you try to name the two functions differently and add both functions to the onclick event of the button?

function OnButtonA(){
//send form to location one.
}
function OnButtonB(){
//send form to location two.
}
onclick="OnButtonA(); OnButtonB();"

If this doesn't work, I would try to use Ajax to achevieve the desired result.

adam.adamski.96155 43 Junior Poster

That JS line that produces the radio group has gone horribly wrong :D
The best way forward is to look at the exact syntax of a static radio group:

<input type="radio" name="overall" value="0">0

then escape the double quotes:

<input type=\"radio\" name=\"overall\" value=\"0\">0

then put it inside the document.write function:

document.write("<input type=\"radio\" name=\"overall\" value=\"0\">0");

That would produce the static radio button, but we need to make allowance for the changing values (1-10) -

value=\"" + i + "\">" +i

...and altogether:

document.write("<input type=\"radio\" name=\"overall\" value=\"" + i + "\">"+i);

Wrap the for loop inside a function and call it to the page when needed:

<script type="text/javascript">
function makeRadio(){
    for(i = 1; i < 11; i++) {// produce values 1-10, using '0' can be problematic for validation.
        document.write("<input type=\"radio\" name=\"overall\" value=\"" + i + "\">"+i);
    }
}
</script>

This will produce 10 radio buttons, all of the same name, 'overall'. You want to make a link that will alert the currently selected radio button? You tried to use the getElementsByName() function inside a link, and then echo it out... but there are many elements with that name, how can this work without looping through the radio buttons?

We need another function to loop through relevant elements and discover which one is selected:

<script type="text/javascript">
function getSelectedRadio(){
    var radioArray = document.getElementsByName("overall"); //make an array with all radio buttons of name 'overall'
    var total = radioArray.length; //how many are there? …
adam.adamski.96155 43 Junior Poster

Hey that's great :)
mysql() is dead, long live mysqli and pdo
Can you mark this thread as solved?

adam.adamski.96155 43 Junior Poster

I'm not familiar with this syntax:
$f1=mysql_result($result,$i,"field1");
I would do it a bit differently:

<!--use a table class rather than repeat font face declaration every line-->
<table class="table" border="1" cellspacing="2" cellpadding="2">
<tr><td>Name</td>
<td>Correct</td>
<td>Wrong</td>
<td>Percent</td>
<td>Level</td>
<td>Date</td></tr>

<?php 
// You don't need to run a while loop depending on num_results,
// just use while(mysql_fetch_array), will stop when no more results.

$sql = "SELECT * FROM tablename";
if(!$result = mysql_query($sql)){// put all DB operations inside error check loop
    die('Invalid query: ' . mysql_error());
}
if(!mysql_num_rows($result) > 0){// using num_rows to make sure there are results to display.
    die("no results, aborting...");
    } 

while($row = mysql_fetch_assoc($result)){
    echo "<tr><td>".$row['name']."</td>"; //<tr> on the first row
    echo "<td>".$row['correct']."</td>";
    echo "<td>".$row['wrong']."</td>";
    echo "<td>".$row['percentage']."</td>";
    echo "<td>".$row['level']."</td>";
    echo "<td>".$row['date']."</td></tr>"; //close </tr> on last row.
}
?>
adam.adamski.96155 43 Junior Poster

Yes, you still need to assign the num_rows to a variable:
$num=mysql_num_rows($result)
Did you assign it to $num? What happened?

adam.adamski.96155 43 Junior Poster

$num=mysql_numrows($result) is wrong, it should be:
mysql_num_rows($result);

How strange that the script tests that $query exists (which is a string that is defined the previous line), then sends the query to the DB without any error checking:
$result=mysql_query($query);

adam.adamski.96155 43 Junior Poster

I ran your code and the $_POST var was empty.
I removed the 'enctype' declaration and the$ _POST var was not empty.
<form name="featuredartistapp" enctype="text/plain" method="post"
print_r() is a function that dispays the contents of an array, when the array is empty, print_r returns 'Array()'
I've never used that enctype declaration and I don't know why it is a problem here.
Your PHP code on the action page assumes $_POST will be defined, this is either lazy or a mistake:

<?php
$field_name = $_POST['fa_name'];
$field_age = $_POST['fa_age'];

I recommend wrapping the whole page in an if statement:

if (isset($_POST['submit'])){ // $_POST has data...
    $field_name = $_POST['fa_name']; //assign variables
    mail(); // send mail
} else { // $_POST is not set
    die("form not submitted aborting...");
}

So I posted Adam's code into the top of my PHP document and now the address just simply stops on the PHP document and displays only "Array ()" on the page and the email no longer sends.

Of course the command 'die()' will stop your script running, what's the point in sending an empty mail? Get the variables into the $_POST var and then move on to the mail sending.

I feel like adding that caused the values already in the array to be lost.

Haha, probably best not to :D

Use error checking, always, for everything!

adam.adamski.96155 43 Junior Poster

There is a point in this operation where the page reloads.
You need to check that your variables hold their intended value after the page has loaded.
It looks like the $_POST['check'] doesn't exist, or it is empty.
You can put:

if (isset($_POST)) {
    print_r($_POST); 
    die();
    }

at the top of your page and it will show you the value of the form variables when the page is reloaded.

adam.adamski.96155 43 Junior Poster

The [...] after the variable is not necessary with PHP, so it's foreach($_POST['check'])

adam.adamski.96155 43 Junior Poster

There could be a problem with your UPDATE statement.
I recommend using error checking with all database transactions, for a great guide look here: mysqli with error checking
If your variables are of string type, your update should look like this:
"UPDATE tablename SET column='value' WHERE id='value'"
I know you are inserting integers, and they don't need to be quoted, but it is possible that $visitid is of string type as we can't see the MySQL column type that supplies the value.
You can try quoting your variables to see if it helps as it is a minimal overhead for the database server to convert variable type with such a small and simple query.

adam.adamski.96155 43 Junior Poster

I copied your situation and tested the code on my own wamp server and it worked fine. I moved the include file above the document root and it still worked okay. This wamp server is so sensitive it throws an error if I look at the screen funny.

adam.adamski.96155 43 Junior Poster

@MWEB, you are drowning in confusion, lets go over it step by step.

Make a form, set the action to the page you want to process the details and the method(get).

Collect form variable/s ready for database search:
$res = $_GET['res'];

Make connection using error checking:

if(!$con = mysqli_connect($host, $user, $pass)){
    echo mysqli_error(); die();
    }

Select database using error checking:

if(!mysqli_select_db("db")) {
    echo mysqli_error(); die();
    }

Build database query:
$sql = "SELECT id, price FROM edit WHERE id='$res' ORDER BY id ")

Send query using error checking:

if(!$res = mysqli_query($sql)){ //error, kill script and tell me what is wrong.
    echo mysqli_error(); die();
} else { //no error continue...
    if(mysqli_num_rows($res)){//no error, but are there any matches?
        while($row = mysqli_fetch_assoc($res)){//there are matches, do the thing...  
            $id = $row['id'];//this step not essential, 
            $price = $row['price'];// but keeps code clean and easy to read.
            echo "$id: The price is $price,<br />"// <--see? clean, easy to read :D
        }
    } else {//no matches, say so
        echo "There were no matches to the search.";
    }
}

Pritaeas has written an excellent guide: http://www.daniweb.com/web-development/php/code/434480/using-phpmysqli-with-error-checking
If there are no DB errors and still no results, try running your query in PHPMyAdmin. You can echo your query to the screen:

$sql = "SELECT id, price FROM edit WHERE id='$res' ORDER BY id ");
echo $sql; die();

...and paste it directly into PHPMyAdmin to see if there is any difference.
Good luck! :D

adam.adamski.96155 43 Junior Poster

@Vingklippt, we were all new once, nothing to be ashamed of :D

@urtrivedi - I'm sure you are just trying to be helpful, but will you also change his nappy after you fed him? At the top of the PHP forum there is a post by the world renown Pritaeas "read this before posting" and one of the points made:

"Do not ask for code. We are not a coding service. We will help you fix your code. If anyone posts a complete working solution for you, they are enabling cheaters. If you use that code you are a cheater."

adam.adamski.96155 43 Junior Poster

@Vingklippt - Exactly, the variables are empty and you are trying to insert little packets of nothingness into your database :D

When you specified method="post" in your form declaration, what does that mean?

It means that the variables you are collecting in your form ($titel, $ingrediens and $pris), will be available to your script on update-success.php (the action of your form declaration) in the 'post' array -
$_POST['titel'], $_POST['ingrediens'] etc...

You could have put method="get" into your form, and then the collected data would be available in the $_GET array.

This is the very basics of PHP/Mysql, you need to be able to do this in your sleep :)

adam.adamski.96155 43 Junior Poster

Your update-success.php page has the statement -

$sql="UPDATE pizza_menu SET titel='$titel', ingrediens='$ingrediens', pris='$pris' WHERE id='$id'";

...but what is the value of $titel, $ingrediens and $pris when the page loads?
at the top of your update-success.php page, put this:

echo "titel = $titel, ingrediens = $ingrediens, pris = $pris"; die();

The value of the variables will be shown on your screen, what are the values?

adam.adamski.96155 43 Junior Poster

I am trying to create a form that updates mySQL-database.

Where is the form?

adam.adamski.96155 43 Junior Poster
$query = mysqli_query($con, "SELECT id,price FROM edit WHERE id=$res");

...this was correct, but lacked the 'ORDER BY' clause, so :

$query = mysqli_query($con, "SELECT id, price FROM edit WHERE id=$res ORDER BY id");

...is all that needed changing, but when urtrivedi changed it to:

WHERE id='{$_GET['res]}'

...it went horribly wrong because it should be '{$_GET['res']}' (utrivedi missed a single quote after the s). I prefer to keep the MySQL statement clean and easy to read as Andreret demonstrated.
This is the bread and butter of PHP/MySQL web development, you should read a thousand tutorials until you can do this in your sleep.

AndreRet commented: Thanx +12
adam.adamski.96155 43 Junior Poster

It may already be, but your CSS src needs to be relative to your index - include paths
You can also try an absolute path as a debug test.

adam.adamski.96155 43 Junior Poster

Pritesh, I replicated your pages and your database on my local machine.
form.php is all good.
save.php had a few problems on my machine:

//I wrapped the next part in an isset() to stop the undefined index error.
if(isset($_POST['prenom'])){
    $prenom=$_POST['prenom'];
    $nom=$_POST['nom'];
    $humeur=$_POST['humeur'];
}

As for the date comparison, I had problems with my machine caching the date and giving false information, so I changed the column type to int and stored a timestamp instead of a date.

$now = date("U"); //num seconds since jan1 1970
$one_day = ($now -(60*60*24));//minus 1 day (60secs * 60mins * 24hrs)
$query = "SELECT * FROM `Humeur_log` WHERE `nom`='$nom' AND `prenom`='$prenom' AND (`datelog` > $one_day)";

Now it will return all rows that were posted in the last 24hrs. There is certainly a better way to acheive this, but this is how I worked it out.

//The updated insert statement.
$sql="INSERT INTO `Humeur_log` (`prenom`, `nom`, `datelog`) VALUES ('$prenom','$nom', $now)";

I tested on name AND surname (prenom && nom) as it made more sense to me like that.
Do you not want to store the mood also in the database?

Questions:
Where is it writing twice?
Which column needs dynamically sorting and when?
Which name should be unique?

adam.adamski.96155 43 Junior Poster

Hey :)
There are no database calls that I can see in your code, can you repost your whole code and re-tell exactly what you want to acheive?

adam.adamski.96155 43 Junior Poster

Can you post all your latest code, and re-tell what you want to acheive?

adam.adamski.96155 43 Junior Poster
adam.adamski.96155 43 Junior Poster
adam.adamski.96155 43 Junior Poster

You have two options -
1. Use Javascript to verify that both passwords match (and the rest of the form is completed correctly) before the form is submitted. Your script appears to be configured that way looking at this line:
<form name="registration_form" method="post" action="register.php" onsubmit="return Validate();">
2.Use PHP to check both passwords once the form has been sent and echo a relevant message to the user if there is a problem with the data submitted.

adam.adamski.96155 43 Junior Poster

a tablename that consists only of digits may need to be encapsulated with `backtick`s - look here

adam.adamski.96155 43 Junior Poster
adam.adamski.96155 43 Junior Poster

I see no reference to "%i" in the manual.

adam.adamski.96155 43 Junior Poster

if($_POST['var']){if there is no post[var] defined, I get the undefined index error.
if(isset($_POST['var'])){I get no error.

Also in this case I think the ternary if syntax would be useful:
<?php echo (isset($_POST['email']) && empty($success)) ? $_POST['email'] : "";?>

adam.adamski.96155 43 Junior Poster

I will spend some time with those links, thanks again :D

adam.adamski.96155 43 Junior Poster

It's perfect thank you Pritaeas. I find it so difficult to visualise the table joins and relationships, I really need to spend some time on it to get my head around it.

adam.adamski.96155 43 Junior Poster

I have two tables, author and quote:
author: AID, Name, YOB, YOD.
quote: ID, AuthID, Content.
I currently get all the authors with one query and as I loop through them, I run a second query to get the count of quotes that have the current AID:

$sql = "SELECT AID, Name FROM author order by Name";
        if (!$res = $this->conn->query($sql)){
            echo $this->conn->error; die();
        } else {
            while($row = $res->fetch_assoc()){
                $count_sql = "select count(*) as count from quote where AuthID='".$row['AID']."'";
                if (!$count_res = $this->conn->query($count_sql)){
                echo $this->conn->error; die();
                } else {
                    $count_row = $count_res->fetch_assoc();
                    $row['count'] = $count_row['count'];
                }

Is it possible to collect the counts in a single query?
"SELECT AID, Name from author and count(AuthID=AID from quotes)"
I have seen talk of 'HAVING', 'IN' and other keywords, but can't find a comprehensible answer.

adam.adamski.96155 43 Junior Poster

Post your code, what do you have so far?

adam.adamski.96155 43 Junior Poster

file_get_contents() to get the whole csv file into a string.
explode() the string on new line character giving many single $line strings.
foreach loop through all $lines:
explode() the $line on ',' into $pieces
foreach loop through $pieces.
if first $piece of line, check value:
if holds value like "Product A", store in $variable.
if holds value like "", change value to $variable.
implode() $pieces to $line using "," as glue.
add "\n" to each $line.
store $line in $newLines array.
foreach loop through $newLines array adding to DB, outputting to excel format...

adam.adamski.96155 43 Junior Poster

@Will Gresham

echo is a language construct, and can take multiple arguments. If you want to get down to micro seconds, it is also slower to use concatenation in an echo instead of comma separated values...

Point noted and thanks for the correction :D

adam.adamski.96155 43 Junior Poster

Is this a JQuery issue? I noticed in JQuery mobile that pages are not truly loaded, and any GET vars are lost because the pages are loaded by ajax. Also this is a JQuery dialog that he is trying to pass the ID to I think.
It seems the OP already knows how to pass the variable in the URL : href="#?id='.$row['id'].'
Maybe it would be better to store the variable in a hidden input and access on the dialog page using Javascript?

adam.adamski.96155 43 Junior Poster

Line 8: (mysql_fetch_row($result)>0) is this intended? do you mean (mysql_num_rows($result)>0) ?
All your database interactions should be ready for errors:
if (!$var = mysql_query()) die(mysql_error())
Line 16: the string $sql is wrong, look here to see why: http://www.daniweb.com/web-development/databases/mysql/threads/437020/php-mysql-wont-post#post1877407
Lines 24+27: You don't use a comma to concatenate a string.
Line 24: $_POST["prenom "] <- the key has whitespace.

As for the double entry into the database and the text file, is this ALL the code? I can't see where it is happeneing twice, or even how this script is running with the comma's for concatenation.

adam.adamski.96155 43 Junior Poster

Can't you just use two different files? Is there a reason that two types of data (plain text and PHP code) must be in the same file? From your questions I think you have gone off track and need to think about this again. What exactly do you want to acheive?