aznjay Posted September 21, 2008 Share Posted September 21, 2008 http://alltraxx.uni.cc/admin/test2.php <form action="editlinks.php" method="post"> <select name="base"> <option value="ps">Photoshop</option> <option value="phptut">Php Tutorial</option> </select> <input type="submit" name="table" value="submit"> </form> http://alltraxx.uni.cc/admin/editlinks.php <? include ("database.php");?> <? $tabs = $_POST["base"]; //display all the news $result = mysql_query("select * from $tabs 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 $rob=$r["id"];//take out the id //make the title a link echo "<a href='editlinks.php?cmd=edit&id=$id'>$title - Edit</a> | "; echo "<a href='editlinks.php?cmd=delete&id=$rob'>DELETE</a>"; echo "<br>"; } ?> <? if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit") { if (!isset($_POST["submit"])) { $id = $_GET["id"]; $tabs = $_POST["base"]; $sql = "SELECT * FROM $tabs WHERE id=$id"; $result = mysql_query($sql); $myrow = mysql_fetch_array($result); ?> <form method="post"> <input type=hidden name="id" value="<?php echo $myrow["id"] ?>"> Title:<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["head"] ?>" SIZE=30><br> Name:<INPUT TYPE="TEXT" NAME="who" VALUE="<?php echo $myrow["name"] ?>" SIZE=30><br> Time:<INPUT TYPE="TEXT" NAME="who" VALUE="<? echo date("g:i a"); ?>" SIZE=30><br> Date:<INPUT TYPE="TEXT" NAME="who" VALUE="<? echo date("M.j.y"); ?>" SIZE=30><br> Message:<br><TEXTAREA NAME="message" ROWS=15 COLS=40><? echo $myrow["msg"] ?></TEXTAREA><br> <input type="hidden" name="cmd" value="edit"> <input type="submit" name="submit" value="submit"> </form> <? } }?> The $tabs doesn't carry through out the page.. and i'm getting this error..I don't know how to fix it Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/jayjay/public_html/admin/editlinks.php on line 9 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/jayjay/public_html/admin/editlinks.php on line 31 I'm getting this error because of the $tabs Quote Link to comment https://forums.phpfreaks.com/topic/125208-_post-does-not-work/ Share on other sites More sharing options...
Adam Posted September 21, 2008 Share Posted September 21, 2008 Try echo'in out $tabs and make sure its correct, and also change: $result = mysql_query("select * from $tabs order by id"); to.. $result = mysql_query("select * from {$tabs} order by id") or die('MySQL Error: ' .mysql_error()); ...then see what happens. Adam Quote Link to comment https://forums.phpfreaks.com/topic/125208-_post-does-not-work/#findComment-647198 Share on other sites More sharing options...
aznjay Posted September 21, 2008 Author Share Posted September 21, 2008 Try echo'in out $tabs and make sure its correct, and also change: $result = mysql_query("select * from $tabs order by id"); to.. $result = mysql_query("select * from {$tabs} order by id") or die('MySQL Error: ' .mysql_error()); ...then see what happens. Adam It does not work...same error as the last time.. Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/jayjay/public_html/admin/editlinks.php on line 9 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/jayjay/public_html/admin/editlinks.php on line 31 Quote Link to comment https://forums.phpfreaks.com/topic/125208-_post-does-not-work/#findComment-647205 Share on other sites More sharing options...
wildteen88 Posted September 21, 2008 Share Posted September 21, 2008 It is caused due to a logic error try <?php include "database.php" if(isset($_POST['base'])) { $tabs = $_POST["base"]; //display all the news $result = mysql_query("select * from $tabs 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 $rob=$r["id"];//take out the id //make the title a link echo "<a href='editlinks.php?cmd=edit&id=$id&base=$tabs'>$title - Edit</a> | "; echo "<a href='editlinks.php?cmd=delete&id=$rob&base=$tabs'>DELETE</a>"; echo "<br>"; } } elseif(isset($_REQUEST["cmd"]) && $_REQUEST["cmd"] == "edit") { if (!isset($_POST["submit"])) { $id = $_GET["id"]; $tabs = $_GET["base"]; $sql = "SELECT * FROM $tabs WHERE id=$id"; $result = mysql_query($sql); $myrow = mysql_fetch_array($result); ?> <form method="post"> <input type=hidden name="id" value="<?php echo $myrow["id"] ?>"> Title:<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["head"] ?>" SIZE=30><br> Name:<INPUT TYPE="TEXT" NAME="name" VALUE="<?php echo $myrow["name"] ?>" SIZE=30><br> Time:<INPUT TYPE="TEXT" NAME="time" VALUE="<? echo date("g:i a"); ?>" SIZE=30><br> Date:<INPUT TYPE="TEXT" NAME="date" VALUE="<? echo date("M.j.y"); ?>" SIZE=30><br> Message:<br><TEXTAREA NAME="message" ROWS=15 COLS=40><? echo $myrow["msg"] ?></TEXTAREA><br> <input type="hidden" name="cmd" value="edit"> <input type="hidden" name="base" value="<?php echo $base; ?>"> <input type="submit" name="submit" value="submit"> </form> <?php } else { echo '<pre>' . print_r($_POST, true) . '</pre>'; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/125208-_post-does-not-work/#findComment-647209 Share on other sites More sharing options...
aznjay Posted September 21, 2008 Author Share Posted September 21, 2008 It is caused due to a logic error try <?php include "database.php" if(isset($_POST['base'])) { $tabs = $_POST["base"]; //display all the news $result = mysql_query("select * from $tabs 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 $rob=$r["id"];//take out the id //make the title a link echo "<a href='editlinks.php?cmd=edit&id=$id&base=$tabs'>$title - Edit</a> | "; echo "<a href='editlinks.php?cmd=delete&id=$rob&base=$tabs'>DELETE</a>"; echo "<br>"; } } elseif(isset($_REQUEST["cmd"]) && $_REQUEST["cmd"] == "edit") { if (!isset($_POST["submit"])) { $id = $_GET["id"]; $tabs = $_GET["base"]; $sql = "SELECT * FROM $tabs WHERE id=$id"; $result = mysql_query($sql); $myrow = mysql_fetch_array($result); ?> <form method="post"> <input type=hidden name="id" value="<?php echo $myrow["id"] ?>"> Title:<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["head"] ?>" SIZE=30><br> Name:<INPUT TYPE="TEXT" NAME="name" VALUE="<?php echo $myrow["name"] ?>" SIZE=30><br> Time:<INPUT TYPE="TEXT" NAME="time" VALUE="<? echo date("g:i a"); ?>" SIZE=30><br> Date:<INPUT TYPE="TEXT" NAME="date" VALUE="<? echo date("M.j.y"); ?>" SIZE=30><br> Message:<br><TEXTAREA NAME="message" ROWS=15 COLS=40><? echo $myrow["msg"] ?></TEXTAREA><br> <input type="hidden" name="cmd" value="edit"> <input type="hidden" name="base" value="<?php echo $base; ?>"> <input type="submit" name="submit" value="submit"> </form> <?php } else { echo '<pre>' . print_r($_POST, true) . '</pre>'; } } ?> I got this error :Parse error: syntax error, unexpected T_IF in /home/jayjay/public_html/admin/editlinks.php on line 4 Quote Link to comment https://forums.phpfreaks.com/topic/125208-_post-does-not-work/#findComment-647218 Share on other sites More sharing options...
DarkWater Posted September 21, 2008 Share Posted September 21, 2008 Missed a ; on the first line of code. Quote Link to comment https://forums.phpfreaks.com/topic/125208-_post-does-not-work/#findComment-647220 Share on other sites More sharing options...
wildteen88 Posted September 21, 2008 Share Posted September 21, 2008 Woops, add a semi-colon ( ; ) at the end of this line include "database.php" Quote Link to comment https://forums.phpfreaks.com/topic/125208-_post-does-not-work/#findComment-647221 Share on other sites More sharing options...
aznjay Posted September 21, 2008 Author Share Posted September 21, 2008 Woops, add a semi-colon ( ; ) at the end of this line include "database.php" There is still a problem when ever I click to edit the...The information doesn't load in the forms... Quote Link to comment https://forums.phpfreaks.com/topic/125208-_post-does-not-work/#findComment-647275 Share on other sites More sharing options...
aznjay Posted September 21, 2008 Author Share Posted September 21, 2008 $ids = $_GET["id"]; $tabsl = $_GET["base"]; $sql = "SELECT * FROM phptut WHERE id=14"; $result = mysql_query($sql); $myrow = mysql_fetch_assoc($result); ?> <form method="post"> <input type=hidden name="id" value="<?php echo $myrow["id"] ?>"> Title:<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["head"] ?>" SIZE=30><br> Name:<INPUT TYPE="TEXT" NAME="name" VALUE="<?php echo $myrow["name"] ?>" SIZE=30><br> Time:<INPUT TYPE="TEXT" NAME="time" VALUE="<? echo date("g:i a"); ?>" SIZE=30><br> Date:<INPUT TYPE="TEXT" NAME="date" VALUE="<? echo date("M.j.y"); ?>" SIZE=30><br> Message:<br><TEXTAREA NAME="message" ROWS=15 COLS=40><? echo $myrow["msg"] ?></TEXTAREA><br> <input type="hidden" name="cmd" value="edit"> <input type="hidden" name="base" value="<?php echo $base; ?>"> <input type="submit" name="submit" value="submit"> </form> <?php } else { echo '<pre>' . print_r($_POST, true) . '</pre>'; } } ?> On this part of the code, it doesn't show any data.. in the forms.. what's wrong with it?? Quote Link to comment https://forums.phpfreaks.com/topic/125208-_post-does-not-work/#findComment-647281 Share on other sites More sharing options...
aznjay Posted September 22, 2008 Author Share Posted September 22, 2008 BUMP!!! Quote Link to comment https://forums.phpfreaks.com/topic/125208-_post-does-not-work/#findComment-647334 Share on other sites More sharing options...
Minase Posted September 22, 2008 Share Posted September 22, 2008 explain me what you want to do,i cant understand your last post too good Quote Link to comment https://forums.phpfreaks.com/topic/125208-_post-does-not-work/#findComment-647335 Share on other sites More sharing options...
Adam Posted September 22, 2008 Share Posted September 22, 2008 try to find some errors... for example on querys like: $result = mysql_query($sql); add: $result = mysql_query($sql) or die('MySQL Error: ' .mysql_error()); Also echo out your inputs to make sure they're valid.. $ids = $_GET["id"]; $tabsl = $_GET["base"]; die('INPUTS: ' .$ids. ' ... ' .$tabsl); You may also want to make sure there's actually a record being retrieved from the database: $result = mysql_query($sql); if (mysql_num_rows($result) == 0) { print 'No record found!'; } else { $myrow = mysql_fetch_assoc($result); // print out form } Your codes very minimal at the minute.. Adam Quote Link to comment https://forums.phpfreaks.com/topic/125208-_post-does-not-work/#findComment-647340 Share on other sites More sharing options...
aznjay Posted September 22, 2008 Author Share Posted September 22, 2008 try to find some errors... for example on querys like: $result = mysql_query($sql); add: $result = mysql_query($sql) or die('MySQL Error: ' .mysql_error()); Also echo out your inputs to make sure they're valid.. $ids = $_GET["id"]; $tabsl = $_GET["base"]; die('INPUTS: ' .$ids. ' ... ' .$tabsl); You may also want to make sure there's actually a record being retrieved from the database: $result = mysql_query($sql); if (mysql_num_rows($result) == 0) { print 'No record found!'; } else { $myrow = mysql_fetch_assoc($result); // print out form } Your codes very minimal at the minute.. Adam Thank you for that but i've tried all of that and it doesn't fix it still... i tried to echo it... it shows the table and the id, but it's not getting the data from SQL Quote Link to comment https://forums.phpfreaks.com/topic/125208-_post-does-not-work/#findComment-647363 Share on other sites More sharing options...
aznjay Posted September 22, 2008 Author Share Posted September 22, 2008 bump!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Quote Link to comment https://forums.phpfreaks.com/topic/125208-_post-does-not-work/#findComment-647395 Share on other sites More sharing options...
aznjay Posted September 22, 2008 Author Share Posted September 22, 2008 elseif(isset($_REQUEST["cmd"]) && $_REQUEST["cmd"] == "edit") { if (!isset($_POST["submit"])) { $ids = $_GET["id"]; $tabsl = $_GET["base"]; $sql = "SELECT * FROM $tabsl WHERE id=$ids"; $result = mysql_query($sql) or die('MySQL Error: ' .mysql_error()); $myrow = mysql_fetch_array($result); ?> <form method="post"> <input type=hidden name="id" value="<?php echo $myrow["id"]; ?>"> Title:<INPUT TYPE="TEXT" NAME="right" VALUE="<?php echo $myrow["title"]; ?>" SIZE=30><br> Description:<INPUT TYPE="TEXT" NAME="left" VALUE="<?php echo $myrow["desp"]; ?>" SIZE=30><br> Time:<INPUT TYPE="TEXT" NAME="up" VALUE="<? echo date("g:i a"); ?>" SIZE=30><br> Date:<INPUT TYPE="TEXT" NAME="down" VALUE="<? echo date("M.j.y"); ?>" SIZE=30><br> Article:<br><TEXTAREA NAME="side" ROWS=15 COLS=40><? echo $myrow["article"] ?></TEXTAREA><br> <input type="submit" name="update" value="submit"> </form> <?php } elseif ($_POST["update"]) { if (!isset($_POST["update"])) { echo '<meta http-equiv="refresh" content="1;url=editlinks.php">'; $id = $_POST["id"]; $title = $_POST["right"]; $tme = $_POST["left"]; $dte = $_POST["down"]; $message = $_POST["side"]; $tabsl = $_GET["base"]; $sql = "UPDATE $tabsl SET title='$title',time='$tme',date='$dte',article='$message', WHERE id=$id"; //replace news with your table name above $result = mysql_query($sql); } } else { echo '<pre>' . print_r($_POST, true) . '</pre>'; } } ?> Okay everything works...but now i'm adding an update command but why won't it UPDATE... Quote Link to comment https://forums.phpfreaks.com/topic/125208-_post-does-not-work/#findComment-647423 Share on other sites More sharing options...
CroNiX Posted September 22, 2008 Share Posted September 22, 2008 Its not good to mix <? and <?php. You should always just use <?php so change the others to that. Dont know if thats the problem, but a suggestion. Quote Link to comment https://forums.phpfreaks.com/topic/125208-_post-does-not-work/#findComment-647512 Share on other sites More sharing options...
wildteen88 Posted September 22, 2008 Share Posted September 22, 2008 Fixed your code, <?php include "database.php"; if(isset($_POST['base'])) { $tabs = $_POST["base"]; //display all the news $result = mysql_query("SELECY * FROM $tabs 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 $rob = $r["id"];//take out the id //make the title a link echo "<a href='editlinks.php?cmd=edit&id=$id&base=$tabs'>$title - Edit</a> | "; echo "<a href='editlinks.php?cmd=delete&id=$rob&base=$tabs'>DELETE</a>"; echo "<br>"; } } elseif(isset($_REQUEST["cmd"]) && $_REQUEST["cmd"] == "edit") { // perform the following when the form below is submitted if(isset($_POST['edit_update'])) { $id = $_POST["id"]; $title = $_POST["title"]; $time = $_POST["time"]; $date = $_POST["date"]; $message = $_POST["message"]; $tabs = $_POST["base"]; $sql = "UPDATE $tabs SET title='$title',time='$time',date='$date',article='$message', WHERE id=$id"; $result = mysql_query($sql) or die(mysql_error()); echo 'Table `'.$tabs.'` updated!'; } // form hasn't been submitted yet, display edit form else { $id = $_GET["id"]; $tabs = $_GET["base"]; $sql = "SELECT * FROM $tabs WHERE id=$id"; $result = mysql_query($sql); $myrow = mysql_fetch_array($result); ?> <form method="post"> <input type=hidden name="id" value="<?php echo $myrow["id"] ?>"> Title:<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["head"] ?>" SIZE=30><br> Name:<INPUT TYPE="TEXT" NAME="name" VALUE="<?php echo $myrow["name"] ?>" SIZE=30><br> Time:<INPUT TYPE="TEXT" NAME="time" VALUE="<?php echo date("g:i a"); ?>" SIZE=30><br> Date:<INPUT TYPE="TEXT" NAME="date" VALUE="<?php echo date("M.j.y"); ?>" SIZE=30><br> Message:<br><TEXTAREA NAME="message" ROWS=15 COLS=40><?php echo $myrow["msg"] ?></TEXTAREA><br> <input type="hidden" name="cmd" value="edit"> <input type="hidden" name="base" value="<?php echo $base; ?>"> <input type="submit" name="edit_update" value="submit"> </form> <?php } } elseif(isset($_REQUEST["cmd"]) && $_REQUEST["cmd"] == "delete") { echo 'Perform delete action here'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/125208-_post-does-not-work/#findComment-647795 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.