Reply
PHP/MySQL UPDATE and SET
Old 10-26-2009, 12:53 AM PHP/MySQL UPDATE and SET
Novice Talker

Posts: 6
Name: It's a secret
Trades: 0
Hello,

I'm trying to make a script so I can select a "unit" and change it's status to either "available" or "unavailable". I just can't seem to get it to work though.

Here is what I'm currently using:

PHP Code:
<?php
        
// Display Units
        
$resultIncident mysql_query("SELECT * FROM units");

echo 
"<table border='1'>
<tr>
<th>Unit ID</th>
<th>Unit Status</th>
<th>District</th>
<th>Change Status</th>
</tr>"
;

while(
$row mysql_fetch_array($resultIncident))
  {
  echo 
"<tr>";
  echo 
"<td>" $row['id'] . "</td>";
  echo 
"<td>" $row['status'] . "</td>";
  echo 
"<td>" $row['district'] . "</td>";
  
//make the title a link
  
echo "<input type='hidden' name='pin' value='$row[id]'/>";
  echo 
"<td><input type='submit' class='deleteButton' name='unitStatusN' value='Delete Incident'/></td>";
  echo 
"</tr>";
  }
echo 
"</table>";

        
?>
<?php
// Unit Status (Available)
/*
if ($_POST['statusAvailable']){
    $uid = $_POST['id'];
    $queryUnit = mysql_query("UPDATE units SET status='Available' WHERE id='$uid'")or die(mysql_error());
}
// Unit Status (Unavailable)
if ($_POST['statusUnavailable']){
    $uid = $_POST['id'];
    $queryUnit = mysql_query("UPDATE units SET status='Unavailable' WHERE id='$uid'")or die(mysql_error());
}
*/
//Change Unit Status
if ($_POST['unitStatusN']) {
    
$unitID $_POST['id'];
    
$unitQuery mysql_query("UPDATE units SET status='unavailable' WHERE id='$unitID'")or die(mysql_error());
    
$resultUnit mysql_query($query);
}

// Delete Incident
//If cmd has not been initialized
if(!isset($status)) 
{
   
//display all the news
   
$resultUnit mysql_query("select * from units order by id"); 
   
   
//run the while loop that grabs all the news scripts
   
while($r=mysql_fetch_array($resultUnit)) 
   { 
      
//grab the title and the ID of the news
      
$idUnit=$r["id"];//take out the id
    
}


$statusN "Unavailable";
?>
If anyone can help me with this, I'd be very grateful.

Thanks

Last edited by Dutchcoffee; 10-26-2009 at 12:57 AM..
Dutchcoffee is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 10-26-2009, 04:41 AM Re: PHP/MySQL UPDATE and SET
tripy's Avatar
Do not try this at home!

Posts: 3,176
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
What is the definition of your table ?
Is the field "units" a varchar ?
Also, does the die(mysql_error()) output something or does the update goes without problem ?

Does the block "if ($_POST['unitStatusN'])" is entered (put an echo in it or something like that to check)?
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is online now
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 10-26-2009, 10:42 AM Re: PHP/MySQL UPDATE and SET
Novice Talker

Posts: 6
Name: It's a secret
Trades: 0
Ok, here's a picture of what I currently have...



In the "Unit Status" column, I want to be able to press either "Available" or "Unavailable" on the right, and it will change it in that "Unit Status" column for the specific unit.

Is that a little clearer?
Dutchcoffee is offline
Reply With Quote
View Public Profile
 
Old 10-26-2009, 11:09 AM Re: PHP/MySQL UPDATE and SET
tripy's Avatar
Do not try this at home!

Posts: 3,176
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Sadly, no.

I need the definitions of the table columns.
What is their type? char, varchar, enum, int ?

I need the ouptut of describe tableName in the sql front-end, like this:
Code:
mysql> describe band;
+-------------+--------------+------+-----+---------+----------------+
| Field       | Type         | Null | Key | Default | Extra          |
+-------------+--------------+------+-----+---------+----------------+
| id          | int(11)      | NO   | PRI | NULL    | auto_increment |
| band_id     | int(11)      | YES  |     | NULL    |                |
| release_ids | varchar(255) | YES  |     | NULL    |                |
+-------------+--------------+------+-----+---------+----------------+
3 rows in set (0.02 sec)
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is online now
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 10-26-2009, 08:06 PM Re: PHP/MySQL UPDATE and SET
Novice Talker

Posts: 6
Name: It's a secret
Trades: 0
Sorry, I'm pretty new to this stuff so...I'll try my best.

The database name is "units"

I have 4 fields (id, status, district, uid) The id field is varchar(4). The status field is varchar(300). The district field is varchar(10). And the uid row is int(30) and is auto_increment. Each of these fields is NOT null.

Is this what you need? Sorry if this isn't.
Dutchcoffee is offline
Reply With Quote
View Public Profile
 
Old 10-26-2009, 09:02 PM Re: PHP/MySQL UPDATE and SET
tripy's Avatar
Do not try this at home!

Posts: 3,176
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
No, it's ok. It was my question.
Now I know that the "status" field is really a varchar field.

I just reviewed the PHP code you gave up there, and I don't see much to say.
The logic seems ok.

Just, is it the full file, or just an excerpt of it?
I'm asking because I find a bit strange that you do the update part after the display.

It means that when you hit this page with an update request, you first fetch and display the value in the db, then do the update.
Therefore, what is displayed on the page is not up to date.

Could this be your problem?
When you click the update button in the page, do you see the changes in the db if you check the particular entry you updated ?
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is online now
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 10-26-2009, 09:56 PM Re: PHP/MySQL UPDATE and SET
Novice Talker

Posts: 6
Name: It's a secret
Trades: 0
The code I gave is just an excerpt of it. Would you like the full code?

Last edited by Dutchcoffee; 10-27-2009 at 12:30 AM..
Dutchcoffee is offline
Reply With Quote
View Public Profile
 
Old 10-27-2009, 01:44 AM Re: PHP/MySQL UPDATE and SET
lizciz's Avatar
Ultra Talker

Posts: 330
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Yes, please
__________________
596f75206d65616e20796f752063616e2061637475616c6c79 207265616420746869733f
lizciz is online now
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Reply     « Reply to PHP/MySQL UPDATE and SET
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.13116 seconds with 13 queries