Jump to content


Photo

$cmd


  • Please log in to reply
4 replies to this topic

#1 Immortal55

Immortal55
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 26 March 2006 - 04:49 PM

is the $cmd variable already stated by php? if so what exactly is it doing?

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 26 March 2006 - 04:55 PM

as far as I know $cmd is not a preset variable in PHP. $cmd must be a custom variable you or someone else must be using in your php script.

#3 Immortal55

Immortal55
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 26 March 2006 - 05:10 PM

<? 
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("localhost","user","password"); 
    
//select which database you want to edit
mysql_select_db("spoono_news"); 

//If cmd has not been initialized
if(!isset($cmd)) 
{
   //display all the news
   $result = mysql_query("select * from news order by id"); 
   
   //run the while loop that grabs all the news scripts
   while($r=mysql_fetch_array($result)) 
   { 
      //grab the title and the ID of the news
      $title=$r["title"];//take out the title
      $id=$r["id"];//take out the id
     
     //make the title a link
      echo "<a href='edit.php?cmd=edit&id=$id'>$title - Edit</a>";
      echo "<br>";
    }
}
?>

<?
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
   if (!isset($_POST["submit"]))
   {
      $id = $_GET["id"];
      $sql = "SELECT * FROM news WHERE id=$id";
      $result = mysql_query($sql);        
      $myrow = mysql_fetch_array($result);
      ?>
      
      <form action="edit.php" method="post">
      <input type=hidden name="id" value="<?php echo $myrow["id"] ?>">
   
      Title:<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["title"] ?>" SIZE=30><br>
      Message:<TEXTAREA NAME="message" ROWS=10 COLS=30><? echo $myrow["message"] ?></TEXTAREA><br>
      Who:<INPUT TYPE="TEXT" NAME="who" VALUE="<?php echo $myrow["who"] ?>" SIZE=30><br>
   
      <input type="hidden" name="cmd" value="edit">
   
      <input type="submit" name="submit" value="submit">
   
      </form>
   
   <? } ?>

what is $cmd representing there? I could not understand it (this was in a tutorial)

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 26 March 2006 - 05:33 PM

I think trhe following line:
/If cmd has not been initialized
if(!isset($cmd))
should be:
/If cmd has not been initialized
if(!isset($_GET['cmd']))
as cmd is being sent over as a url parameter/variable see the following code:
//make the title a link
      echo "<a href='edit.php?cmd=edit&id=$id'>$title - Edit</a>";
notice the following edit.php?cmd=editYou are assigning edit as the value of cmd variable. So I guess cmd stores stuff like edit, add and delete.

If the tutorial you got this form actually explained what the code does you should be able to understand, which isn't your fault as just like the other million PHP so called tutorials out there the tutorial you followed may of went along the lines of "Copy the following code and save it as somefile.php, now copy the next bit of code and save it as someotherfile.php! Enjoy!" and didn't even bother explaining what the hell the code is doing. I can't see how that teaches someone PHP but just a stupid Copy 'n' Paste session.

Hope that helps.

#5 Immortal55

Immortal55
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 26 March 2006 - 06:26 PM

ah wow, that helped a lot, thank you!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users