Solved

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

Posted on 2015-01-29
18
136 Views
Last Modified: 2015-02-10
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
Comment
Question by:Scott Johnston
  • 8
  • 8
  • 2
18 Comments
 
LVL 70

Assisted Solution

by:Jason C. Levine
Jason C. Levine earned 100 total points
Comment Utility
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
 

Author Comment

by:Scott Johnston
Comment Utility
I just did exactly that and now I have a new error, something to do with my connection.
0
 
LVL 70

Expert Comment

by:Jason C. Levine
Comment Utility
if (mysqli_querry($con, $result))

Open in new window


Pretty sure "mysqli_querry" isn't a valid PHP function.
0
 

Author Comment

by:Scott Johnston
Comment Utility
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
 
LVL 13

Assisted Solution

by:NUKIT
NUKIT earned 400 total points
Comment Utility
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
 

Author Comment

by:Scott Johnston
Comment Utility
I already found that typo, spelled querry wrong.......
0
 
LVL 13

Expert Comment

by:NUKIT
Comment Utility
Use this instead of mysqli_fetch_array()

mysqli_fetch_assoc()
0
 
LVL 13

Accepted Solution

by:
NUKIT earned 400 total points
Comment Utility
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
 

Author Comment

by:Scott Johnston
Comment Utility
I insert the query statement into MYSQL and the select statement works fine....
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:Scott Johnston
Comment Utility
Change the Fetch to assoc and go the same results....
0
 
LVL 13

Expert Comment

by:NUKIT
Comment Utility
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
 
LVL 13

Expert Comment

by:NUKIT
Comment Utility
Hmmm, interesting...
0
 
LVL 13

Expert Comment

by:NUKIT
Comment Utility
Can you post your new code here with the assoc() added to it...?
0
 
LVL 13

Expert Comment

by:NUKIT
Comment Utility
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
 
LVL 13

Expert Comment

by:NUKIT
Comment Utility
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
 

Author Comment

by:Scott Johnston
Comment Utility
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
 

Author Comment

by:Scott Johnston
Comment Utility
I started from Scratch and everything is working. I found a small syntax error.
0
 

Author Closing Comment

by:Scott Johnston
Comment Utility
Sorry to take so long
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now