Solved

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

Posted on 2015-01-29
18
152 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
ID: 40578727
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
ID: 40578731
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
ID: 40578735
if (mysqli_querry($con, $result))

Open in new window


Pretty sure "mysqli_querry" isn't a valid PHP function.
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

Author Comment

by:Scott Johnston
ID: 40578754
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:Andrew Derse
Andrew Derse earned 400 total points
ID: 40578755
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
ID: 40578756
I already found that typo, spelled querry wrong.......
0
 
LVL 13

Expert Comment

by:Andrew Derse
ID: 40578758
Use this instead of mysqli_fetch_array()

mysqli_fetch_assoc()
0
 
LVL 13

Accepted Solution

by:
Andrew Derse earned 400 total points
ID: 40578760
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
ID: 40578772
I insert the query statement into MYSQL and the select statement works fine....
0
 

Author Comment

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

Expert Comment

by:Andrew Derse
ID: 40578779
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:Andrew Derse
ID: 40578782
Hmmm, interesting...
0
 
LVL 13

Expert Comment

by:Andrew Derse
ID: 40578785
Can you post your new code here with the assoc() added to it...?
0
 
LVL 13

Expert Comment

by:Andrew Derse
ID: 40578794
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:Andrew Derse
ID: 40578917
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
ID: 40580803
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
ID: 40601773
I started from Scratch and everything is working. I found a small syntax error.
0
 

Author Closing Comment

by:Scott Johnston
ID: 40601777
Sorry to take so long
0

Featured Post

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

726 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