Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 159
  • Last Modified:

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

0
Scott Johnston
Asked:
Scott Johnston
  • 8
  • 8
  • 2
3 Solutions
 
Jason C. LevineNo oneCommented:
name="RMA Number"

Open in new window


Don't use spaces in name parameters if you want to use them in PHP.  Change the above to remove the space, replace with a dash or something.
0
 
Scott JohnstonSystems ConsultantAuthor Commented:
I just did exactly that and now I have a new error, something to do with my connection.
0
 
Jason C. LevineNo oneCommented:
if (mysqli_querry($con, $result))

Open in new window


Pretty sure "mysqli_querry" isn't a valid PHP function.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Scott JohnstonSystems ConsultantAuthor Commented:
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

0
 
Andrew DerseIT ManagerCommented:
Yes, remove the extra r from the msqli_query portion.

Also, comment out all of the data from the PHP lookup page and see if you are actually passing the correct RMA number using...

$RMANum = $_GET['RMANumber'];

Open in new window


If you aren't getting anything, there's your problem.  If you are, let's work on the query problem.
0
 
Scott JohnstonSystems ConsultantAuthor Commented:
I already found that typo, spelled querry wrong.......
0
 
Andrew DerseIT ManagerCommented:
Use this instead of mysqli_fetch_array()

mysqli_fetch_assoc()
0
 
Andrew DerseIT ManagerCommented:
Excellent, good catch ;)  Can you see if the mysqli_fetch_assoc() will suit your query needs better?  I tend to only use assoc() and that's what you are attempting to do as well...the array() won't work for how you have it pulled out in the while section...
0
 
Scott JohnstonSystems ConsultantAuthor Commented:
I insert the query statement into MYSQL and the select statement works fine....
0
 
Scott JohnstonSystems ConsultantAuthor Commented:
Change the Fetch to assoc and go the same results....
0
 
Andrew DerseIT ManagerCommented:
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() .
0
 
Andrew DerseIT ManagerCommented:
Hmmm, interesting...
0
 
Andrew DerseIT ManagerCommented:
Can you post your new code here with the assoc() added to it...?
0
 
Andrew DerseIT ManagerCommented:
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

0
 
Andrew DerseIT ManagerCommented:
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

0
 
Scott JohnstonSystems ConsultantAuthor Commented:
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?
***************************************
0
 
Scott JohnstonSystems ConsultantAuthor Commented:
I started from Scratch and everything is working. I found a small syntax error.
0
 
Scott JohnstonSystems ConsultantAuthor Commented:
Sorry to take so long
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 8
  • 8
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now