0

I have a working form that allows the user to add invoices to a database, it will then display the invoices in a table, within the table there in a email button within the Name section. When the user clicks the button it will pull up a bootstrap modal that asks for the email, subject, and content. It will then shoot an email address to the entered email address. This is working perfectly, however i would now like it to grab the email address that's associated with the name inside the database.

This is what i've been trying with no success

Home.php

<div class="form-group"> <label class="col-md-4 control-label" for="email">Email:</label> <div class="col-md-5"> <input id="email" name="email" type="text" placeholder="[email protected]" class="form-control input-md" value="<?php echo $query['email']?>"> </div> </div> 

up in my code im connecting o the database like this

 $query = mysql_query("SELECT id, Rep, Date, email, Name, P_O, ADDDATE(Date, Terms) AS Due_Date, Terms, GREATEST(DATEDIFF(NOW(), ADDDATE(Date, Terms)), 0) AS Aging, Open_Balance from Book1"); 

So what im looking for is when the suer clicks the email button next to the customers Name, it will auto fill the modal with the emailaddress thats in the same ROW as the Name.

6
  • Possible duplicate of stackoverflow.com/questions/10379624/… Commented Nov 2, 2015 at 16:39
  • @Akshay not quit i did look through this, im trying to pull data from a database to fill the form with. Commented Nov 2, 2015 at 16:42
  • Try performing a print_r ($results) where $results is the returned value from mysql_fetch_array. If it doesn't print anything then there were no results and if the email shows up blank, well the field is empty Commented Nov 2, 2015 at 17:27
  • @Jujunol that actually grabbed something, its grabing the entire row of the array, it is also grabbing the row at the very top of the array? Commented Nov 2, 2015 at 18:21
  • @Charles Okay, when you say "grabbing the entire row of array" do you mean it's retrieving all the rows from the table? If you could more carefully explain the results then I believe I could produce an answer for you Commented Nov 2, 2015 at 19:10

2 Answers 2

0

You will need to do $database_array = mysqli_fetch_array($query)then echo $database_array['email'];

$query = mysql_query("SELECT id, Rep, Date, email, Name, P_O, ADDDATE(Date, Terms) AS Due_Date, Terms, GREATEST(DATEDIFF(NOW(), ADDDATE(Date, Terms)), 0) AS Aging, Open_Balance from Book1"); $database_array = mysqli_fetch_array($query); <input id="email" name="email" type="text" placeholder="[email protected]" class="form-control input-md" value="<?php echo $database_array['email']?>"> 
Sign up to request clarification or add additional context in comments.

5 Comments

That makes sense however it gave me this error mysqli_fetch_array() expects parameter 1 to be mysqli_result
Hmm wrap your query in an if statement and make sure your sql is not returning false, then if it is returning true run the fetch array. if($query = mysqli_query($connection,"SQL CODE HERE") { //Do the fetch array $datbase_array($query); } else { //Database query failed echo "Error Message"; } Could be a case that your using mysql_query() not mysqli_query() so try mysql_fetch_array() instead
its getting to the database because the table is being filled from the database. The problem i believe is your mixing mysqli and mysql.
Did you have any luck with using mysql_fetch_array() ? Also i thought the database connection variable had to be used in the mysql_query function ?
If i change it to mysql_fetch_array($query) it removes the error but still isnt filling the form
0

It appears to me that the row you're attempting to pull doesn't have an email value ([email] => [4] ...). Reassure that the row you're pulling has a value in the email column.

Also I realized that your SQL doesn't have a WHERE clause (meaning multiple rows could return if more than one row exist in the table). Hope this helps!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.