Jump to content

Recommended Posts

i am new to php and i dont know how i would get some data from a mysql database to display when a person enters a number in a form

 

basically i am creating an order tracking page which will have a form that asks for an order number and the persons postcode, on entering the correct postcode with the correct order number the customer will be shown their orders status.

 

all i dont know is how i would tell the form to check the database and make sure that the postcode and the order number were the same in that row?

 

i havent done much work with forms.

 

Thanks

Steve

ok i now have some script that i created but i need it to do an if statement for 2 variables e.g.

if($ordernumber + $postcode){
   echo $order;
   }
else{
   echo "There are no repaits in the database for that postcode and order number.";
   }

 

do you see what i mean? im not sure how i get the if($ordernumber + $postcode) to work as it errors when i do it like that

ok so i have looked around and i got how to do the if statement u use && instead of + but my form still returns nothing

 

here is the code

<?php
$db =mysql_connect ("localhost","dbuser","dbpass");
mysql_select_db("db to use",$db);
if($on && $post) {
// query DB
$sql = "SELECT * FROM repair ORDER BY status postdate DESC WHERE on ='$on' post ='$post'";
$result = mysql_query($sql);

if(mysql_num_rows($result) > 0){
while($row=mysql_fetch_array($result)){
echo "Date Submitted: $row[postdate]<br>";
echo "Order Number: $row[on]<br>";
echo "Postcode: $row[postcode]<br><br>";
echo "Status: $row[status]<br><br>";
echo "Comments: $row[comments]<br><br>";
echo "Technician: $row[technician]<br><br>";
echo "Due By: $row[dueby]<br><br>";
}
}else{
echo "There are no repaits in the database for that postcode and order number.";
}

//display data
}else{
//display form
?>
<form method=post action="<?php echo $PHP_SELF?>">
  <p>
    Order number:
    <input type="text" name="order number">
  </p>
  <p>Postcode:
    <input type="text" name="postcode"> 
  </p>
  <p>
    <input type="submit">
      </p>
</form>
<?php
}
echo $sql
?>

 

i have the code uploaded here http://blacklimecomputers.co.uk/track/check.php when i look at the source it seems that the form doesnt know to action to itself any ideas what i can do???

ok tried

 

<form method=post action="<?php echo "$_SERVER['PHP_SELF']"; ?>">

 

didnt work so i tried

 

<form method=post action="<?php echo $_SERVER['PHP_SELF']; ?>">

 

that worked but when i insert test order number and test postcode it doesnt return anything

 

test order number is: 123456789

test postcode is: ls8 1bu

 

i get the following error

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/marksie/public_html/blacklime/track/check.php on line 11

There are no repaits in the database for that postcode and order number.SELECT * FROM repair ORDER BY status postdate DESC WHERE on ='123456789' postcode ='ls8 1bu'

 

and the php is now

 

<?php
$db =mysql_connect ("localhost","dbuser","dbpass");
mysql_select_db("dbname",$db);
$on = $_POST['on'];
$post = $_POST['postcode'];
if($on && $post) {
// query DB
$sql = "SELECT * FROM repair ORDER BY status postdate DESC WHERE on ='$on' postcode ='$post'";
$result = mysql_query($sql);

if(mysql_num_rows($result) > 0){
while($row=mysql_fetch_array($result)){
echo "Date Submitted: $row[postdate]<br>";
echo "Order Number: $row[on]<br>";
echo "Postcode: $row[postcode]<br><br>";
echo "Status: $row[status]<br><br>";
echo "Comments: $row[comments]<br><br>";
echo "Technician: $row[technician]<br><br>";
echo "Due By: $row[dueby]<br><br>";
}
}else{
echo "There are no repaits in the database for that postcode and order number.";
}

//display data
}else{
//display form
?>
<form method=post action="<?php echo $_SERVER['PHP_SELF']; ?>">
  <p>
    Order number:
    <input type="text" name="on">
  </p>
  <p>Postcode:
    <input type="text" name="postcode"> 
  </p>
  <p>
    <input type="submit">
      </p>
</form>
<?php
}
echo $sql
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.