x404.co.uk
http://www.x404.co.uk/forum/

PHP help
http://www.x404.co.uk/forum/viewtopic.php?f=4&t=8125
Page 1 of 1

Author:  tombolt [ Fri May 07, 2010 3:40 pm ]
Post subject:  PHP help

I'm wondering if some kind soul could give me some help with my PHP.

I'm trying to submit an entry to a new row in a database table. The data in the text areas seems to get entered no problem. However, the values from the dropdown menu don't seem to be submitted. The dropdown menu is being populated from another table in the database. I'm using the code below:

Code:
   <form action="insertJob.php" method="POST">
      
      <?php
      //Script to retrieve clients and populate drop down
      $mysqli = mysqli_connect("localhost", "root", "root", "Job_list");
      $sql = "SELECT Client FROM Clients";
      $res = mysqli_query($mysqli, $sql);
      ?>
      
      <select name="client">
      
      <?php
      while ($line = mysqli_fetch_array ($res, MYSQLI_ASSOC)) {
      ?>
      
      <option value="<?php $line[Client];?>"> <?php echo $line[Client];?></option>
      
      <?php
      }
      ?>
      
      </select>
      
      <textarea name="description" rows="1" cols="20">Job description</textarea>
      
      <?php
      //Script to retrieve statuses and populate drop down
      $mysqli = mysqli_connect("localhost", "root", "root", "Job_list");
      $sql = "SELECT Status FROM Statuses";
      $res = mysqli_query($mysqli, $sql);
      ?>
      
      <select name="status">
      
      <?php
      while ($line = mysqli_fetch_array ($res, MYSQLI_ASSOC)) {
      ?>
      
      <option value="<?php $line[Status];?>"> <?php echo $line[Status];?></option>
      
      <?php
      }
      ?>
      
      </select>
      
      <textarea name="notes" rows="2" cols="20">Notes</textarea>
      
      <input type="submit" value="Submit">
      
   </form>


I'm wondering if the option value is being posted as the php code. However, I thought that the php should be invisible to the browser and would submit the data that it had displayed.

I have sort of cobbled together the code with a mixture of copy and paste and a quarter an idea of what to do.

Author:  tombolt [ Fri May 07, 2010 4:20 pm ]
Post subject:  Re: PHP help

Worked it out, whoohoo!

Left out first 'echo' in
Code:
<option value="<?php $line[Status];?>"> <?php echo $line[Status];?></option>


Should read
Code:
<option value="<?php echo $line[Status];?>"> <?php echo $line[Status];?></option>

Author:  ProfessorF [ Fri May 07, 2010 10:22 pm ]
Post subject:  Re: PHP help

Yeah.

I was just about to say that.



;)

Author:  Nick [ Sat May 08, 2010 1:58 pm ]
Post subject:  Re: PHP help

Glad you got it sorted - post back if there are any other problems.

Can a mod move this to programming?

Author:  tombolt [ Sat May 08, 2010 2:06 pm ]
Post subject:  Re: PHP help

Nick wrote:
Glad you got it sorted - post back if there are any other problems.

Can a mod move this to programming?


Will do, cheers. Wasn't sure if it belonged in here or programming. I kind of assumed web related stuff went in here as it was scripting rather than programming…

Author:  forquare1 [ Sat May 08, 2010 2:19 pm ]
Post subject:  Re: PHP help

tombolt wrote:
Will do, cheers. Wasn't sure if it belonged in here or programming. I kind of assumed web related stuff went in here as it was scripting rather than programming…


We're quite happy to have all sorts in the programming board, as long as it has some link to programming :D

Author:  Nick [ Sat May 08, 2010 2:57 pm ]
Post subject:  Re: PHP help

tombolt wrote:
I kind of assumed web related stuff went in here as it was scripting rather than programming…


Hmm, well I think people could argue that point 'til the cows come home! I'd personally say it is a programming language - you can compile it after all, but it's usually used for writing scripts.

Personally, when I refer to PHP I do refer to it as a programming language.

*Shrug*

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/