Page 1 of 1

Updating ID number

Posted: Tue Jan 26, 2010 9:48 am
by daebat
I need to call to the database, display by id number (editable), and then submit for changes. What am I doing wrong here?

Code: Select all

<?
mysql_connect("localhost", "user", "pdub") or die(mysql_error()) ;
mysql_select_db("table") or die(mysql_error()) ;
 
if(!isset($cmd)) 
{
 
   $result = mysql_query("select * from test order by id"); 
   
   while($r=mysql_fetch_array($result)) 
   { 
 
      $title=$r["title"];//take out the title
      $id=$r["id"];//take out the id
      $thumb=$r["thumb"];
      
      echo "<form><table>
        <tr>
        <td><input type='text' name='id' value='$id' size='3'></td><td width='350px'><strong>$title</strong></td>
        </tr>
        <td colspan='2' align='center'><img src='upload/test/$thumb'></td>
        </table></form>
         ";
    }
}
?>
<?
echo "<div style='text-align:center;'><a href='testorder.php?cmd=order&id=$id'>Submit</a></div>";
?>
<?
if($cmd=="order")
{
    $sql = "UPDATE test SET id=$id";
    $result = mysql_query($sql);
    echo "UPDATED!";
    echo "<a href='main.php'>Click here to return to the Administration Area.</a>";
}
}
 
 
?>
 

Re: Updating ID number

Posted: Tue Jan 26, 2010 10:03 am
by lshaw
I have a feeling it could be this bit.

Code: Select all

$sql = "UPDATE test SET id=$id";
    $result = mysql_query($sql);
    echo "UPDATED!";
    echo "<a href='main.php'>Click here to return to the Administration Area.</a>";
You need to put $id in quotation marks.

Code: Select all

$sql = "UPDATE test SET id='$id'";
I am not sure, but I think you must also have a where

Code: Select all

$sql = "UPDATE test SET id='$id' WHERE x='y'";

Re: Updating ID number

Posted: Tue Jan 26, 2010 10:19 am
by requinix
Quotation marks aren't necessary - in fact, if the id is a number then you shouldn't use quotes - but without that WHERE it'll update every row in the table.

Re: Updating ID number

Posted: Tue Jan 26, 2010 10:28 am
by daebat
$sql = "UPDATE test SET id='$id' WHERE x='y'";
What would x and y be? You were right about the quotes around $id so thank you for that. Still not working though.

Re: Updating ID number

Posted: Tue Jan 26, 2010 11:14 am
by nothing1306
:banghead:

This file name is testorder.php:
<? // <?php
mysql_connect("localhost", "user", "pdub") or die(mysql_error()) ;
mysql_select_db("table") or die(mysql_error()) ;
// $cmd = $_GET["cmd"];
// $id = $_GET["id"];
if(!isset($cmd))
{

$result = mysql_query("select * from test order by id");

while($r=mysql_fetch_array($result))
{

$title=$r["title"];//take out the title
$id=$r["id"];//take out the id

$thumb=$r["thumb"];

echo "<form><table>
<tr>
<td><input type='text' name='id' value='$id' size='3'></td><td width='350px'><strong>$title</strong></td>
</tr>
<td colspan='2' align='center'><img src='upload/test/$thumb'></td>
</table></form>
";
}
}
?>
<? // <?php
echo "<div style='text-align:center;'><a href='testorder.php?cmd=order&id=$id'>Submit</a></div>";
/*
* echo "<div style='text-align:center;'><a href='testorder.php?cmd=order&id=$id'>Submit</a></div>";
*/

?>
<? // <?php
if($cmd=="order")
{
// Is "id" primari key ?
$sql = "UPDATE test SET id=$id";
$result = mysql_query($sql);
echo "UPDATED!";
echo "<a href='main.php'>Click here to return to the Administration Area.</a>";
}
} // <~~~ error


?>

Re: Updating ID number

Posted: Tue Jan 26, 2010 11:22 am
by lshaw
It could be WHERE id=$id (the current id) but i can't tell if you are storing the current id in a variable

Re: Updating ID number

Posted: Tue Jan 26, 2010 12:29 pm
by daebat
This file name is testorder.php:
Nothing... you bolding the code doesn't mean anything to me. I am pretty new to PHP but am starting to understand some of this stuff. Why would I use the $GET statement for CMD? ID is the primary key.

Re: Updating ID number

Posted: Wed Jan 27, 2010 12:41 am
by nothing1306
Why would I use the $GET statement for CMD?
Why? :crazy: I don't remember... I did forget it

Sometimes... I don't know what I did or said... Can anybody here help me?