Jump to content


Photo

$_GET is not working


  • Please log in to reply
6 replies to this topic

#1 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 03 September 2006 - 09:26 AM

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.

<?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);
?>

I don't need your script, I'll try to write it myself

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 03 September 2006 - 10:19 AM

put the link_id in a hidden field on your form, instead of in the querystring. Then it gets POSTed with rest of the form data.

<input type='hidden' name='link_id' value='65'>

Why all the nl2br() calls? You don't want to store 'br' in db fields, just the raw data
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 03 September 2006 - 11:54 AM

ok, Thanks Barand, I'll try that...
I don't need your script, I'll try to write it myself

#4 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 03 September 2006 - 12:11 PM

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

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

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

I don't need your script, I'll try to write it myself

#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 03 September 2006 - 02:00 PM

Read my post again

put the link_id in a hidden field on your form


If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#6 rallokkcaz

rallokkcaz
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts
  • LocationSomewhere, CA (Cactus Area)

Posted 03 September 2006 - 02:16 PM

try setting up an array?

#7 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 03 September 2006 - 02:28 PM

Thanks a lot it works and I'am happy  ;D
I don't need your script, I'll try to write it myself




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users