yuckysocks Posted April 22, 2008 Share Posted April 22, 2008 Hi, My goal is to show a table of user-posted results to an admin, who can then approve the data and change the value of the "approved" column from 0 to 1. <?php // Connecting, selecting database $link = mysql_connect('localhost', 'xxxx', 'xxxx') or die('Could not connect: ' . mysql_error()); mysql_select_db('case_studies') or die('Could not select database'); if(!isset($cmd)) { // Performing SQL query FOR UNAPPROVED CASES $query = 'SELECT id, schoolname, schoolcity, state FROM casestudies WHERE approved = 0'; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); // Printing results in HTML echo "<table class=\"sortable\">\n"; echo "<th>School Name</th> <th>School City</th> <th>State</th> <th>Approval Link</th>"; while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "\t<tr>\n"; echo "\t\t<td><a href='casestudy.php?id=".$line['id']."'>".$line['schoolname']."- Check me for Accuracy</a></td>\n"; echo "\t\t<td>".$line['schoolcity']."</td>\n"; echo "\t\t<td>".$line['state']."</td>\n"; echo "\t\t<td><a href='admin.php?cmd=approve&id=".$line['id']."'>Approve the $schoolname case study and make it public</a>"; echo "\t</tr>\n"; } echo "</table>\n"; } if($_GET["cmd"]=="approve") { $id = $_GET["id"]; $sql = "UPDATE casestudies SET approved = 1 WHERE id = $id"; } // Closing connection mysql_close($link); ?> Some ideas are cobbled together from different sample scripts, so I don't really know where the issue lies. When I click on the "Approve" link, it goes to a blank page, but the data remains unchanged. Help! Also, thanks so much to everyone in the forum, you all are VERY helpful. -Alex Link to comment https://forums.phpfreaks.com/topic/102321-solved-can-someone-troubleshoot-a-simple-script/ Share on other sites More sharing options...
jonsjava Posted April 22, 2008 Share Posted April 22, 2008 This should work <?php // Connecting, selecting database $link = mysql_connect('localhost', 'xxxx', 'xxxx') or die('Could not connect: ' . mysql_error()); mysql_select_db('case_studies') or die('Could not select database'); if(!isset($cmd)) { // Performing SQL query FOR UNAPPROVED CASES $query = 'SELECT id, schoolname, schoolcity, state FROM casestudies WHERE approved = 0'; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); // Printing results in HTML echo "<table class=\"sortable\">\n"; echo "<th>School Name</th> <th>School City</th> <th>State</th> <th>Approval Link</th>"; while ($line = mysql_fetch_assoc($result)) { $id = $line["id"]; $schoolname = $line["schoolname"]; $schoolcity = $line["schoolcity"]; $state = $line["state"]; echo <<<END \t<tr>\n; \t\t<td><a href='casestudy.php?id=$id'>$schoolname- Check me for Accuracy</a></td>\n; \t\t<td>$schoolcity</td>\n; \t\t<td>$state</td>\n; \t\t<td><a href='admin.php?cmd=approve&id=$id'>Approve the $schoolname case study and make it public</a>; \t</tr>\n END; } echo "</table>\n"; } if($_GET["cmd"]=="approve") { $id = $_GET["id"]; $sql = "UPDATE casestudies SET approved = 1 WHERE id = $id"; } // Closing connection mysql_close($link); ?> Link to comment https://forums.phpfreaks.com/topic/102321-solved-can-someone-troubleshoot-a-simple-script/#findComment-523910 Share on other sites More sharing options...
yuckysocks Posted April 22, 2008 Author Share Posted April 22, 2008 What I have right now is <?php // Connecting, selecting database $link = mysql_connect('localhost', 'xxxx', 'xxxx') or die('Could not connect: ' . mysql_error()); mysql_select_db('case_studies') or die('Could not select database'); if(!isset($cmd)) { // Performing SQL query FOR UNAPPROVED CASES $query = 'SELECT id, schoolname, schoolcity, state FROM casestudies WHERE approved = 0'; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); // Printing results in HTML echo "<table class=\"sortable\">\n"; echo "<th>School Name</th> <th>School City</th> <th>State</th> <th>Approval Link</th>"; while ($line = mysql_fetch_assoc($result)) { $id = $line["id"]; $schoolname = $line["schoolname"]; $schoolcity = $line["schoolcity"]; $state = $line["state"]; echo <<<END \t<tr>\n; \t\t<td><a href='casestudy.php?id=$id'>$schoolname- Check me for Accuracy</a></td>\n; \t\t<td>$schoolcity</td>\n; \t\t<td>$state</td>\n; \t\t<td><a href='admin2.php?cmd=approve&id=$id'>Approve the $schoolname case study and make it public</a>; \t</tr>\n END; } echo "</table>\n"; } if($_GET["cmd"]=="approve") { $id = $_GET["id"]; $sql = "UPDATE casestudies SET approved = 1 WHERE id = $id"; } // Closing connection mysql_close($link); ?> Clicking on the links still won't update my data... Maybe my query is wrong? Also, fyi, I stripped the semi-colons from the echo-->HTML section. I ended up with 5 semis x 3 records = 15 semi colons in a line up top. Any hints would be great. Thanks! Link to comment https://forums.phpfreaks.com/topic/102321-solved-can-someone-troubleshoot-a-simple-script/#findComment-523941 Share on other sites More sharing options...
jonsjava Posted April 22, 2008 Share Posted April 22, 2008 holy crap I'm blind! <?php // Connecting, selecting database $link = mysql_connect('localhost', 'xxxx', 'xxxx') or die('Could not connect: ' . mysql_error()); mysql_select_db('case_studies') or die('Could not select database'); if(!isset($cmd)) { // Performing SQL query FOR UNAPPROVED CASES $query = 'SELECT id, schoolname, schoolcity, state FROM casestudies WHERE approved = 0'; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); // Printing results in HTML echo "<table class=\"sortable\">\n"; echo "<th>School Name</th> <th>School City</th> <th>State</th> <th>Approval Link</th>"; while ($line = mysql_fetch_assoc($result)) { $id = $line["id"]; $schoolname = $line["schoolname"]; $schoolcity = $line["schoolcity"]; $state = $line["state"]; echo <<<END \t<tr>\n; \t\t<td><a href='casestudy.php?id=$id'>$schoolname- Check me for Accuracy</a></td>\n; \t\t<td>$schoolcity</td>\n; \t\t<td>$state</td>\n; \t\t<td><a href='admin2.php?cmd=approve&id=$id'>Approve the $schoolname case study and make it public</a>; \t</tr>\n END; } echo "</table>\n"; } if($_GET["cmd"]=="approve") { $id = $_GET["id"]; $sql = "UPDATE casestudies SET approved = 1 WHERE id = $id"; mysql_query($sql) or die(mysql_error()); /* FORGOT TO RUN THE QUERY..don't feel bad. I missed it too */ } // Closing connection mysql_close($link); ?> Link to comment https://forums.phpfreaks.com/topic/102321-solved-can-someone-troubleshoot-a-simple-script/#findComment-523944 Share on other sites More sharing options...
craygo Posted April 22, 2008 Share Posted April 22, 2008 Yes java you must run the query LOL Link to comment https://forums.phpfreaks.com/topic/102321-solved-can-someone-troubleshoot-a-simple-script/#findComment-523946 Share on other sites More sharing options...
yuckysocks Posted April 22, 2008 Author Share Posted April 22, 2008 Well, at least you're blind and not a total newbie who didn't recognize that at all. I printed out the file, and went through it line by line, writing in English what each part did, and next to $sql = QUERY I wrote "performs operation". Shows how much I still have to learn! Thanks so much for all the help. Link to comment https://forums.phpfreaks.com/topic/102321-solved-can-someone-troubleshoot-a-simple-script/#findComment-523952 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.