Solved

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

Posted on 2015-01-29
18
154 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

 

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

Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

Question has a verified solution.

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

This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

635 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