Jump to content

$_GET is not working


Gruzin

Recommended Posts

hi guys,
I have a form where I use id at the end of the URL, like http://www.mysite.com?link_id=65
so I want to GET this variable for database, on the other page it works ok, but on EDIT page it doesn't get the variable... here is the code, your help will be greatly appreciated.

[code]<?php
$name = nl2br($_POST['webname']); // name inputed in form
$url = nl2br($_POST['weburl']); // URL inputed in form
$weburl = "<a href=".$url.">$url</a>"; //greb the link
$rank = nl2br($_POST['rank']); // page rank inputed in form
$comment = nl2br($_POST['webcom']); // comment inputed in form
if(empty($name)){
  echo "Please Enter Website name";
  exit();
}
$con = mysql_connect("localhost","george","pass");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("george", $con);

$link_id = $_GET['link_id']; // get id for db

$update = "UPDATE link_manager SET name = '$name' WHERE id = '$link_id'";
if(!mysql_query($update,$con))
{
  die('Error:'.mysql_error());
}
header( 'Location: http://www.mysite.net/links/' ) ;
mysql_close($con);
?>[/code]
Link to comment
Share on other sites

Here is my modified code, but it doesn't update a record in db and returns error:

[color=red]Warning: Cannot modify header information - headers already sent by (output started at /home/nycapart/public_html/links/add_edit.php:3) in /home/nycapart/public_html/links/add_edit.php on line 28[/color]

[code]<html>
<body>
<input type='hidden' name='link_id' value='<?php $link_id = $_GET['link_id'];?>'>
<?php
$name = $_POST['webname']; // name inputed in form
$url = $_POST['weburl']; // URL inputed in form
$weburl = "<a href=".$url.">$url</a>"; //greb the link
$rank = $_POST['rank']; // page rank inputed in form
$comment = $_POST['webcom']; // comment inputed in form
if(empty($name)){
  echo "Please Enter Website name";
  exit();
}
$con = mysql_connect("localhost","george","pass");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("george", $con);

$link_id = $_GET['link_id']; // get id for db

$update = "UPDATE link_manager SET name = '$name' WHERE id = '$link_id'";
if(!mysql_query($update,$con))
{
  die('Error:'.mysql_error());
}
header( 'Location: http://www.mysite.net/links/' ) ;
mysql_close($con);
?>
</body>
</html>[/code]
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.