Immortal55 Posted March 26, 2006 Share Posted March 26, 2006 is the $cmd variable already stated by php? if so what exactly is it doing? Quote Link to comment https://forums.phpfreaks.com/topic/5854-cmd/ Share on other sites More sharing options...
wildteen88 Posted March 26, 2006 Share Posted March 26, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/5854-cmd/#findComment-20875 Share on other sites More sharing options...
Immortal55 Posted March 26, 2006 Author Share Posted March 26, 2006 [code]<? //connect to mysql//change user and password to your mySQL name and passwordmysql_connect("localhost","user","password"); //select which database you want to editmysql_select_db("spoono_news"); //If cmd has not been initializedif(!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>"; }}?>[/code][code]<?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> <? } ?>[/code]what is $cmd representing there? I could not understand it (this was in a tutorial) Quote Link to comment https://forums.phpfreaks.com/topic/5854-cmd/#findComment-20878 Share on other sites More sharing options...
wildteen88 Posted March 26, 2006 Share Posted March 26, 2006 I think trhe following line:[code]/If cmd has not been initializedif(!isset($cmd)) [/code]should be:[code]/If cmd has not been initializedif(!isset($_GET['cmd'])) [/code]as cmd is being sent over as a url parameter/variable see the following code:[code]//make the title a link echo "<a href='edit.php?cmd=edit&id=$id'>$title - Edit</a>";[/code]notice the following [b]edit.php?cmd=edit[/b]You 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. Quote Link to comment https://forums.phpfreaks.com/topic/5854-cmd/#findComment-20884 Share on other sites More sharing options...
Immortal55 Posted March 26, 2006 Author Share Posted March 26, 2006 ah wow, that helped a lot, thank you! Quote Link to comment https://forums.phpfreaks.com/topic/5854-cmd/#findComment-20898 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.