GeneralCan
GeneralCan

Reputation: 317

How to pass a string to a different page using PHP on a click event

Ok, so I've looked around all day and tried many different things, So i was wondering if you guys could help me out.

Here's what I got:

Im building a webpage that Uses a database to update content. the content is updated based on what link the user clicks on. right now I'm using a session to pass a variable to another page to then use that variable to pull a piece of information from the database.

this is the link the user clicks on Page#1:

    session_start();
    <a href="Makes/Audi/Audi.php?brands=audi" name="audi">

and then on page two:

    session_start();

    if(isset($_GET['brands'])){
$_SESSION['brands'] = $_GET['brands'];
}
    // connect to database
mysql_connect ("localhost", "user", "pass") or die ('Error: ' . mysql_error());

    //select the DataBase
mysql_select_db ("Vehicle_Makes");

    //select make's logo and attach it to a variable
$logo = mysql_query("SELECT Logo FROM '".$_GET['brands']."'");
    ?>

and then I pull the path to an image using this:

    <div id="apDiv14"><?php echo $logo;?></div>

but the link to the image does not show up so I added this at the end of the query:

        $logo = mysql_query("SELECT Logo FROM '".$_GET['brands']."'") or die ('Error: ' . mysql_error());

and when I clicked on the link this is what displayed on a blank page:

    Error: 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 ''audi'' at line 1

Please help me out and thanks in advanced.

Upvotes: 0

Views: 247

Answers (4)

Kumar Ravi
Kumar Ravi

Reputation: 429

the FROM keyword in the MySQL query has to be either followed by table name without single quotes or must be within `.

Upvotes: 2

Amber
Amber

Reputation: 526723

$logo = mysql_query("SELECT Logo FROM '".$_GET['brands']."'");

That's not how mysql_query() works. It returns a result ID that you then need to pass to something like mysql_fetch_assoc() to get the actual result row.

Your query is also incorrect, given that you're not specifying the table nor an actual condition to filter on, so it's trying to select all rows from a table named whatever is in your $_GET['brands'] variable.

Upvotes: 0

user166560
user166560

Reputation:

Your query is SELECT Logo FROM 'audi'. That makes 'audi' the name of the table and I think it's invalid syntax to enclose the table name in quotes. But maybe you meant to make the query something like SELECT Logo FROM brands where brand_name = 'audi'?

Upvotes: 0

Tango Bravo
Tango Bravo

Reputation: 3309

Try using backticks instead of single quotes ` instead of ' in your query for the table that you're searching. Also, DON'T EVER USE UNSANITIZED INPUTS!!!!!!!!

Upvotes: 0

Related Questions