Link to home
Start Free TrialLog in
Avatar of Scott Johnston
Scott JohnstonFlag for United States of America

asked on

PHP form having problems - unable to pass form data(RMA Number) to select querry ...please

I have a simple form that has a user enters a RMA number, the RMA number is then passed to a select query
however I am having problems getting the variable setup correctly in my PHP program that runs the select query.
I am looking for some help.......

FORM
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Add Records Form</title>
</head>
<body>
<form action="RMAlist.php" method="get">
	<p>
    	<label for="RMANumber">RMA Number:</label>
        <input type="text" name="RMA Number" id="RMANumber">
    </p>
    <!--<p>
    	<label for="lastName">Last Name:</label>
        <input type="text" name="lastname" id="lastName">
    </p>
    <p>
    	<label for="emailAddress">Email Address:</label>
        <input type="text" name="email" id="emailAddress">
    </p>-->
    <input type="submit" value="Lookup Record">
</form>
</body>
</htm

Open in new window


PHP lookup - I left out the connection to MYSQL
  $RMANumber = ($con, $_GET['RMANumber']);
$result = " SELECT rma_headers1.RMANumber, rma_headers1.Date, rma_headers1.CustomerNumber, rma_headers1.CustomerDivision, rma_detail_lines1.ItemNumber,
rma_detail_lines1.Qty, rma_detail_lines1.Solution FROM  biotone.rma_headers rma_headers1 INNER JOIN biotone.rma_detail_lines rma_detail_lines1 ON rma_headers1.RMANumber=rma_detail_lines1.RMANumber 
WHERE  (rma_headers1.RMANumber= $RMANumber ) ORDER BY rma_headers1.RMANumber)";


if (mysqli_querry($con, $result)){
    echo "Records lookup successfull.";
  } else{
    echo "ERROR: Could not able to excute $result." . mysqli_error($con);
  }
//$result = mysqli_query($con,"SELECT RegDate, FirstName, LastName, EmailAddress, PhoneNumber, CECredits, CampaignID FROM OpenHouseRegistrations



 echo "<table border='1'>
 <tr>
 <th>RMA Number</th>
 <th>RMA Date</th>
 <th>Customer Number</th>
 <th>Item Number</th>
 <th>Quantity</th>
 <th>Solution</th>
  </tr>";

 while($row = mysqli_fetch_array($result))
   {
   echo "<tr>";
   echo "<td>" . $row['RMANumber'] . "</td>";
   echo "<td>" . $row['Date'] . "</td>";
   echo "<td>" . $row['CustomerNumber'] . "</td>";
   echo "<td>" . $row['ItemNumber'] . "</td>";
   echo "<td>" . $row['Qty'] . "</th>";
   echo "<td>" . $row['Solution'] . "</th>";
   //echo "<td>" . $row['CampaignID'] . "</th>";
   echo "</tr>";
   }
 echo "</table>";

 mysqli_close($con);
 ?> 

Open in new window

SOLUTION
Avatar of Jason C. Levine
Jason C. Levine
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Scott Johnston

ASKER

I just did exactly that and now I have a new error, something to do with my connection.
if (mysqli_querry($con, $result))

Open in new window


Pretty sure "mysqli_querry" isn't a valid PHP function.
My new error is:

Records lookup successfull.

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, string given in C:\Inetpub\wwwroot\RMAlist.php on line 26 (in new coding)  

new code snipet
$RMANumber = mysqli_real_escape_string($con, $_GET['RMANumber']);
$result = "SELECT rma_headers1.RMANumber, rma_headers1.Date, rma_headers1.CustomerNumber, rma_headers1.CustomerDivision, rma_detail_lines1.ItemNumber,
rma_detail_lines1.Qty, rma_detail_lines1.Solution FROM  biotone.rma_headers rma_headers1 INNER JOIN biotone.rma_detail_lines rma_detail_lines1 ON rma_headers1.RMANumber=rma_detail_lines1.RMANumber 
WHERE  (rma_headers1.RMANumber= $RMANumber ) ORDER BY rma_headers1.RMANumber";


if (mysqli_query($con, $result)){
    echo "Records lookup successfull.";
  } else{
    echo "ERROR: Could not able to excute $result." . mysqli_error($con);
  }
//$result = mysqli_query($con,"SELECT RegDate, FirstName, LastName, EmailAddress, PhoneNumber, CECredits, CampaignID FROM OpenHouseRegistrations



 echo "<table border='1'>
 <tr>
 <th>RMA Number</th>
 <th>RMA Date</th>
 <th>Customer Number</th>
 <th>Item Number</th>
 <th>Quantity</th>
 <th>Solution</th>
  </tr>";

 while($row = mysqli_fetch_array($result))
   {
   echo "<tr>";
   echo "<td>" . $row['RMANumber'] . "</td>";
   echo "<td>" . $row['Date'] . "</td>";
   echo "<td>" . $row['CustomerNumber'] . "</td>";
   echo "<td>" . $row['ItemNumber'] . "</td>";
   echo "<td>" . $row['Qty'] . "</th>";
   echo "<td>" . $row['Solution'] . "</th>";
   //echo "<td>" . $row['CampaignID'] . "</th>";
   echo "</tr>";
   }
 echo "</table>";

 mysqli_close($con);
 ?>

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I already found that typo, spelled querry wrong.......
Use this instead of mysqli_fetch_array()

mysqli_fetch_assoc()
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I insert the query statement into MYSQL and the select statement works fine....
Change the Fetch to assoc and go the same results....
So you no longer have the error when using the mysqli_fetch_array() ?

If you are still getting that error, you need to change it to: mysqli_fetch_assoc() .
Hmmm, interesting...
Can you post your new code here with the assoc() added to it...?
Can you try the code below, but replace your database connection information in the appropriate place?

<?php 

$RMANumber = $_GET['RMANumber'];

//conection: 
$link = mysqli_connect("myhost","myuser","mypassw","mybd") or die("Error " . mysqli_error($link)); 

//consultation: 

$query = "SELECT rma_headers1.RMANumber, rma_headers1.Date, rma_headers1.CustomerNumber, rma_headers1.CustomerDivision, rma_detail_lines1.ItemNumber,
rma_detail_lines1.Qty, rma_detail_lines1.Solution FROM  biotone.rma_headers rma_headers1 INNER JOIN biotone.rma_detail_lines rma_detail_lines1 ON rma_headers1.RMANumber=rma_detail_lines1.RMANumber 
WHERE  (rma_headers1.RMANumber= $RMANumber ) ORDER BY rma_headers1.RMANumber)" or die("Error in the consult.." . mysqli_error($link)); 

//execute the query. 

$result = mysqli_query($link, $query); 

//display information: 
echo "<table border='1'>
 		<tr>
 		<th>RMA Number</th>
 		<th>RMA Date</th>
 		<th>Customer Number</th>
 		<th>Item Number</th>
 		<th>Quantity</th>
 		<th>Solution</th>
  </tr>";
  
while($row = mysqli_fetch_array($result)) { 
  echo "<tr>";
  echo "<td>" . $row['RMANumber'] . "</td>";
  echo "<td>" . $row['Date'] . "</td>";
  echo "<td>" . $row['CustomerNumber'] . "</td>";
  echo "<td>" . $row['ItemNumber'] . "</td>";
  echo "<td>" . $row['Qty'] . "</th>";
  echo "<td>" . $row['Solution'] . "</th>";
  //echo "<td>" . $row['CampaignID'] . "</th>";
  echo "</tr>";
} 
echo "</table>";
?> 

Open in new window

I actually worked on this a little bit and created a function for you, for every time you need to connect and do a select query...again, please replace the connection params with your database info...

<?php 

function setQuery($sql) {
	$server = 'localhost';
	$user = 'root';
	$pass = 'password';
	$dbname = 'test';
	
	$db = new mysqli($server, $user, $pass, $dbname);
 
	// check connection
	if ($db->connect_error) {
  		$error = $db->connect_error;
	}
	
	$result = $db->query($sql);
	return $result;	
}

$RMANumber = $_GET['RMANumber'];

//consultation: 

$sql = "SELECT rma_headers1.RMANumber, rma_headers1.Date, rma_headers1.CustomerNumber, rma_headers1.CustomerDivision, rma_detail_lines1.ItemNumber,
rma_detail_lines1.Qty, rma_detail_lines1.Solution FROM  biotone.rma_headers rma_headers1 INNER JOIN biotone.rma_detail_lines rma_detail_lines1 ON rma_headers1.RMANumber=rma_detail_lines1.RMANumber 
WHERE  (rma_headers1.RMANumber= $RMANumber ) ORDER BY rma_headers1.RMANumber)" or die("Error in the consult.." . mysqli_error($link)); 

//execute the query. 

$result = setQuery($sql); 

//display information: 
echo "<table border='1'>
 		<tr>
 		<th>RMA Number</th>
 		<th>RMA Date</th>
 		<th>Customer Number</th>
 		<th>Item Number</th>
 		<th>Quantity</th>
 		<th>Solution</th>
  </tr>";
  
while($row = mysqli_fetch_assoc($result)) { 
  echo "<tr>";
  echo "<td>" . $row['RMANumber'] . "</td>";
  echo "<td>" . $row['Date'] . "</td>";
  echo "<td>" . $row['CustomerNumber'] . "</td>";
  echo "<td>" . $row['ItemNumber'] . "</td>";
  echo "<td>" . $row['Qty'] . "</th>";
  echo "<td>" . $row['Solution'] . "</th>";
  //echo "<td>" . $row['CampaignID'] . "</th>";
  echo "</tr>";
} 
echo "</table>";
?> 

Open in new window

Still getting the same error.  I think I am going to start from scratch.

I re-worked the coding from scratch, and I am not getting the error any more, however it will not find the RMA Number and retrieve the data.
If I create a PHP file to lookup all the data with out the form, it work perfectly.  I enter in the form to enter in the RMA Number works fine.  Can the type of field the RMA Number is setup as cause a lookup problem when using MYSQL? or can the form have the wrong type of data in the retrieval of the RMA Number?
***************************************
I started from Scratch and everything is working. I found a small syntax error.
Sorry to take so long