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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.