Reply to topic  [ 7 posts ] 
PHP help 
Author Message
Spends far too much time on here
User avatar

Joined: Fri Apr 24, 2009 8:38 am
Posts: 2967
Location: Dorchester, Dorset
Reply with quote
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.

_________________
I've finally invented something that works!

A Mac User.


Fri May 07, 2010 3:40 pm
Profile
Spends far too much time on here
User avatar

Joined: Fri Apr 24, 2009 8:38 am
Posts: 2967
Location: Dorchester, Dorset
Reply with quote
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>

_________________
I've finally invented something that works!

A Mac User.


Fri May 07, 2010 4:20 pm
Profile
What's a life?
User avatar

Joined: Thu Apr 23, 2009 7:56 pm
Posts: 12030
Reply with quote
Yeah.

I was just about to say that.



;)

_________________
www.alexsmall.co.uk

Charlie Brooker wrote:
Windows works for me. But I'd never recommend it to anybody else, ever.


Fri May 07, 2010 10:22 pm
Profile
Spends far too much time on here
User avatar

Joined: Thu Apr 23, 2009 11:36 pm
Posts: 3527
Location: Portsmouth
Reply with quote
Glad you got it sorted - post back if there are any other problems.

Can a mod move this to programming?

_________________
Image


Sat May 08, 2010 1:58 pm
Profile
Spends far too much time on here
User avatar

Joined: Fri Apr 24, 2009 8:38 am
Posts: 2967
Location: Dorchester, Dorset
Reply with quote
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…

_________________
I've finally invented something that works!

A Mac User.


Sat May 08, 2010 2:06 pm
Profile
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 6:36 pm
Posts: 5150
Location: /dev/tty0
Reply with quote
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


Sat May 08, 2010 2:19 pm
Profile WWW
Spends far too much time on here
User avatar

Joined: Thu Apr 23, 2009 11:36 pm
Posts: 3527
Location: Portsmouth
Reply with quote
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*

_________________
Image


Sat May 08, 2010 2:57 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 7 posts ] 

Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.