Jump to content

$_POST[""] does not work...


aznjay

Recommended Posts

 

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>';
    }
}
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

    $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??

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites


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...

Link to comment
Share on other sites

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';
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.