Jump to content

what is the correct syntax to line of code?


dwex

Recommended Posts

the page before this sends a value to this page and the value is my table's name.

 

<a href="displayguns.php?paintguns=guns">

 

guns is my table's name.

 

<?php

$tab = $_GET['paintguns'];

$HOST = 'localhost';
$USERNAME = 'root';
$PASSWORD = '';
$DB = 'pbstore';

$link = mysqli_connect($HOST,$USERNAME,$PASSWORD,$DB) or die(mysqli_connect_error());
$sql = "SELECT {$tab}_id , {$tab}_name , {$tab}_price , {$tab}_image
FROM {$tab} ";
$result = mysqli_query($link, $sql) or die(mysqli_error($link));
?>

or the only way would be to change all the table names in my database?

 

You mean field names?

 

It seems stupid to pre-pend your fields with there table name. eg; If you have a table called 'Users', why do you need a field called 'Users_Name'? 'Name' is sufficient.

He's also got an INSERT query where the table name and the column prefixes are from a form field (apparently selected from a drop down menu.)

 

Before you spend any more time on this, you need to fix your database design. Your design is not efficient and is resulting in more complicated code than you need.

 

You need to make your design general purpose. You don't create another table just because you add a new category or type and your column names should only indicate the purpose of the data (id, name, price, image), not what the data in them references.

Archived

This topic is now archived and is closed to further replies.

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