i need some help on php select statements

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mevijaynair
Forum Newbie
Posts: 1
Joined: Mon May 26, 2008 2:52 am

i need some help on php select statements

Post by mevijaynair »

i use a database named 'users'
with table 'transactions'
with fields 'sort1' sort2 bale balew pieces status

Code: Select all

<?php
echo ("<br>");
echo ("<br>");
if (!isset($_POST['submit']))
{
?>
<form action="" method="post">
 
 
Transaction Id<input type="text" name="transactionida"><br>
Status<select name="statusa">
  <option value=".">.</option>
  <option value="0">Available</option>
  <option value="1">Reserved to</option>  
  <option value="2">Delivered</option>
  </select><br>
Customer<input type="text" name="customera"><br>
<br><br><br><input type="submit" name="submit" value="Submit!">
</form></div>   
<?php
}
else
{
 
    $transactionida = $_POST['transactionida'];
    $statusa = $_POST['statusa'];  
   $customera = $_POST['customera'];  
    
    
if ($transactionid == "")
    {
        echo "Enter Transaction ID";        
    }
    
if($status== "1"){if($customer==""){echo "Enter Customer Name";Exit();}}
 
if($status == ".")
{
    echo "Echo Enter Status";
}
 
if($status == "1")
{
$result1 = mysql_query("UPDATE transactions SET status= 1,customer= '$customera' WHERE transaction_id='$transactionida'") 
or die(mysql_error());  
}
  if($status == "0") 
 { 
    $result1 = mysql_query("UPDATE transactions SET status= 0 WHERE transaction_id='$transactionida'")or die(mysql_error());
 
}
 if($status == "2") 
 { 
    $result1 = mysql_query("UPDATE transactions 
    SET status= 2 
    WHERE transaction_id='$transactionida'")or die(mysql_error());
 
}
    ?> <font size="3"><strong><?  
$result = mysql_query("SELECT * FROM transactions where transaction_id='$transactionida'")
or die(mysql_error());  
 
// store the record of the "example" table into $row
$row = mysql_fetch_array( $result );
// Print out the contents of the entry 
?>
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<th><font face="Arial, Helvetica, sans-serif">Transaction ID</font></th>
<th><font face="Arial, Helvetica, sans-serif">Sort 1</font></th>
<th><font face="Arial, Helvetica, sans-serif">Sort 2</font></th>
<th><font face="Arial, Helvetica, sans-serif">Bale</font></th>
<th><font face="Arial, Helvetica, sans-serif">Bale Weight</font></th>
<th><font face="Arial, Helvetica, sans-serif">Bags</font></th>
<th><font face="Arial, Helvetica, sans-serif">Pieces</font></th>
<th><font face="Arial, Helvetica, sans-serif">Symbol</font></th>
<th><font face="Arial, Helvetica, sans-serif">Color</font></th>
<th><font face="Arial, Helvetica, sans-serif">Status</font></th>
<th><font face="Arial, Helvetica, sans-serif">Customer</font></th>
<th><font face="Arial, Helvetica, sans-serif">Entry Date</font></th>
<th><font face="Arial, Helvetica, sans-serif">Sort By</font></th>
</tr>  
<tr>
<td><font face="Arial, Helvetica, sans-serif"><? echo $row['transaction_id']; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $row['sort1']; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $row['$sort2']; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $row['bale'];?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $row['balew'];?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $row['bags']; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $row['pieces']; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $row['symbol']; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $row['color']; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? if ($row[$status]==0)
{echo "Available";}
if($row[$status]==1)
{echo "Reserved to";}
if($row[$status]==3){echo "Delivered";}?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $row['Customer']; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $row['entry_date']; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $row['sortedby']; ?></font></td>
</tr>
</table>
<?}?>
 
problem one Update statement doesnt work- Im a newbiee to PHP so do let me know where i go wrong in this.


Also if some one could help me how to use mysql to use select statement based on two field conditions and based on that sum other fields , it would be very grateful
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: i need some help on php select statements

Post by califdon »

mevijaynair wrote:problem one Update statement doesnt work- Im a newbiee to PHP so do let me know where i go wrong in this.
What do you mean "doesn't work"? Do you get an error? If so, what is it? Or do you mean that it simply doesn't update the record? There is no way to know what's wrong without knowing this. If there is no error, it means the syntax of your SQL query is valid, so if the record is not updating, the most likely cause is that there was no record with the transaction_id you searched for. What transaction_id was it? Oh, you don't know? Then you must put a temporary debugging statement in there, to echo (so you can read it on the screen) what values are in the important variables just before you try to update the record.
Also if some one could help me how to use mysql to use select statement based on two field conditions and based on that sum other fields , it would be very grateful
Something like:

Code: Select all

SELECT  ....  FROM  ....  WHERE field1='xxxx' AND field2=99 AND (field2 + field3)=888
Post Reply