Jump to content

passing a variable through the URL


robcrozier

Recommended Posts

How do you pass a variable from one page through the URL to another page using a link to do so?

in other words - i have a variable on one page and i want to click a link to redirect to another page, taking the variable with me so that i can use it on the next page too!

please help!!!!
Link to comment
Share on other sites

hi again! Right the variable seems to be getting passed through (i can see this by echoing it in the new page) however why wont it let me use it in a mysql query?

heres where i pass the variable in through a link whilst printing out some rows from a database table at the same time:

[code]
while($nt=mysql_fetch_array($r))
  {
    echo "<tr>
    <td>$nt[title]</td>
    <td>$nt[description]</td>
    <td>$nt[age_rating]</td>
    <td>$nt[cast]</td>
    <td width = 11%>$nt[date_added]</td>
    <td><a href='delete_entry.php?title=$nt[title]'>Delete</a></td>
    </tr>";
  }
[/code]

And here is where it is being passed into the next page:

[code]

<?php

  
     $title = $_GET['title'];
     //echo $title;    
  

require_once ('mysql_connect.php'); // Connect to the database.

$query = "delete * from dvds where title = $title";
$result = mysql_query($query);

if($result){
echo 'done';
mysql_close();
}
else{
echo mysql_error();
}
[/code]

And here is the error message that i keep getting:

[code]
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '* from dvds where title = Matrix' at line 1
[/code]

Why the hell is it doing this???
Link to comment
Share on other sites

You need to put single quotes around strings in the query:
[code]<?php
$query = "delete * from dvds where `title` = '$title'";
?>[/code]
I also put back-ticks around your field name "title". These make sure it is not mistaken for a reserved word.

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