Does anyone see something wrong with this case { $id=$r["id"]; $name=$r["name"]; $email=$r["email"]; $category=$r["category"]; $title=$r["title"]; $article=$r["article"]; $article2=$r["article2"]; $article3=$r["article3"]; $package=$r["package"]; $date=$r["date"]; $status=$r["status"]; if($status == "") { $status = "<a href=\"?mode=status&id=$id\">Mark as complete</a>"; } echo "Id: $id - Name: $name - Email: $email - Category: $category - Package: $package - Date: $date <br><h1>$title</h1><br><br>". htmlspecialchars($article) ."<br><br>". htmlspecialchars($article2) ."<br><br>". htmlspecialchars($article3) ."<br><br>$status<br><HR>"; } if($_GET['mode'] == "status") { mysql_query("UPDATE $table SET status ='complete' WHERE id='$id'") or die(mysql_error()); echo"Status changed"; } It is not inserting complete into the db. when I mark complete Any help is much appreciated, if you pm me I would be more than willing to do a free post on my network for your time.
I don't see where you've defined $table. Also, you should enclose the variables in you output strings in curly braces.
check your query.. correct me if im wrong, i suggest concatinating the variables. im not sure if your format is accepted by mysql.
The query should be fine like that. It's impossible to tell from a code fragment if you've correctly set all the variables. Like other I'd just suggest dumping the values before the if condition and see that they're all set the way you think they should. From what I can see assuming all the values are set correctly it should work.
Thanks everyone for trying to answer my dumb question. Here I posted the rest of the code, let me know what you think Thanks <?php session_start(); if(!session_is_registered("username")){ echo"<form action=\"login.php\" method=\"post\"> Username: <input type=\"text\" name=\"username\" size=\"10\"> Password: <input type=\"password\" name=\"password\" size=\"10\"> <input type=\"submit\" value=\"submit\" name=\"submit\"> </form>"; exit(); } $host ="localhost"; $username="username"; $password="password"; $dbname="dbname"; $table = "tablename"; echo"<a href=\"?mode=overview\">Overview</a> - <a href=\"?mode=stats\">Stats</a><br><HR>"; $dbLink = mysql_connect($host, $username, $password); if(!$dbLink) die("Could not connect to database. " . mysql_error()); mysql_select_db($dbname); if($_GET['mode'] == "view") { $id = $_GET['id']; $result = mysql_query("SELECT * FROM $table WHERE id=$id") or die(mysql_error()); while($r=mysql_fetch_array($result)) { $id=$r["id"]; $name=$r["name"]; $email=$r["email"]; $category=$r["category"]; $title=$r["title"]; $article=$r["article"]; $article2=$r["article2"]; $article3=$r["article3"]; $package=$r["package"]; $date=$r["date"]; $status=$r["status"]; if($status == "") { $status = "<a href=\"?mode=status&id=$id\">Mark as complete</a>"; } echo "Id: $id - Name: $name - Email: $email - Category: $category - Package: $package - Date: $date <br><h1>$title</h1><br><br>". htmlspecialchars($article) ."<br><br>". htmlspecialchars($article2) ."<br><br>". htmlspecialchars($article3) ."<br><br>$status<br><HR>"; } } if($_GET['mode'] == "status") { mysql_query("UPDATE $table SET status='complete' WHERE id='$id'") or die(mysql_error()); echo"Status changed"; } if($_GET['mode'] == "overview") { $result = mysql_query("SELECT * FROM $table") or die(mysql_error()); $total = mysql_num_rows($result); echo"Total: $total <br><hr>"; while($r=mysql_fetch_array($result)) { $id=$r["id"]; $name=$r["name"]; $email=$r["email"]; $category=$r["category"]; $title=$r["title"]; $article=$r["article"]; $article2=$r["article2"]; $article3=$r["article3"]; $package=$r["package"]; $date=$r["date"]; $status=$r["status"]; if($status == "") { $status = "<a href=\"?mode=status&id=$id\">Mark as complete</a>"; } echo "<table width=100%><TR><TD align=center valign=middle>Id: $id</TD><TD valign=top align=left>Name: $name <BR> Email: $email <BR> Category: $category - Package: $package - Date: $date <br>$status - <a href=\"?mode=view&id=$id\">View article</a></TD></TR></table><br><HR>"; } } if($_GET['mode'] == "stats") { echo"<br><a href=\"?mode=stats&when=today\">Today</a> - <a href=\"?mode=stats&when=week\">This Week</a> - <a href=\"?mode=stats&when=month\">This Month</a><br><HR>"; $today = date("m/d/y"); $week = mktime(0, 0, 0, date("m"), date("d")-7, date("y")); $lastweek = date("m/d/y", $week); $month = mktime(0, 0, 0, date("m")-1, date("d"), date("y")); $lastmonth = date("m/d/y", $month); if($_GET['when'] == "today") { $result = mysql_query("SELECT * FROM $table WHERE date='$today'") or die(mysql_error()); } if($_GET['when'] == "week") { $result = mysql_query("SELECT * FROM $table WHERE date>'$lastweek'") or die(mysql_error()); } if($_GET['when'] == "month") { $result = mysql_query("SELECT * FROM $table WHERE date>'$lastmonth'") or die(mysql_error()); } if($_GET['when'] == "") { echo"Select a timeframe"; exit(); } $total = mysql_num_rows($result); echo"Total: $total <br><hr>"; while($r=mysql_fetch_array($result)) { $id=$r["id"]; $name=$r["name"]; $email=$r["email"]; $category=$r["category"]; $title=$r["title"]; $article=$r["article"]; $article2=$r["article2"]; $article3=$r["article3"]; $package=$r["package"]; $date=$r["date"]; $status=$r["status"]; if($status == "") { $status = "<a href=\"?mode=status&id=$id\">Mark as complete</a>"; } echo "Id: $id - Name: $name - Email: $email - Category: $category - Package: $package - Date: $date <br>$status - <a href=\"?mode=view&id=$id\">View article</a><br><HR>"; } } ?> PHP:
If I'm not mistaken (I may have gotten lost in the lack of indentation ) the problem is where you've defined $id, because right now it's only being defined when mode == view, but not when mode == status. Try moving it outside the if construct. That is, change the following: if($_GET['mode'] == "view") { $id = $_GET['id']; PHP: ... to this: $id = $_GET['id']; if($_GET['mode'] == "view") { PHP:
And for the love of Pete, sanitize your input! If you aren't going to validate, at least escape $_GET['id'] with mysql_real_escape_string() before putting it into your query. Securing your code from malicious users should be your top priority.