Jump to content

PHP id help


aikijohn

Recommended Posts

Hey all,

 

Been a while since ive coded php and am stuck already.

Here is the issue, i have a list being made from the database using id as the identifier. so the link being rendered is client.php?id=1 etc.

 

im trying to use this info to populate the page it directs too using the folowing add on script:

 

<?

$lin = mysqli_connect("*","*","*!","*") or die("Error 1 " . mysqli_error($lin));

 

//consultation:

 

$query = "SELECT * FROM Clients WHERE ID=$id " or die("Error 2 in the consult.." . mysqli_error($lin));

 

//execute the query.

 

$result = mysqli_query($lin, $query);

 

while($row = mysqli_fetch_array($result)) {

$name = $row['1'];

$address = $row['2'];

$city = $row['3'];

$postcode = $row['4'];

$phone = $row['5'];

$email = $row['6'];

 

}

?>

 

Problem is this isnt working and i have no idea why

 

Can anyone help?

Link to comment
Share on other sites

Hey Ch0cu3r,

 

thank you for the reply, i updated it to this:

 

$query = "SELECT * FROM Clients WHERE ID=$_GET['id'] " or die("Error 2 in the consult.." . mysqli_error($lin));

 

however now the page no longer loads up?

 

in dreamweaver its telling me i have a syntax error on that line too?

Edited by aikijohn
Link to comment
Share on other sites

So...the issue is fixed? If so, could you make the thread as solved.

 

For what it's worth, when having a variable like $_GET['id'] work in a double quoted string you can surround the variable with curly brackets:

 

 

<?php
$query = "SELECT * FROM Clients WHERE ID={$_GET['id']} " 
?>

 

Also note that using information from untrusted sources, like the GET variable, without any kind of validations will open your query up for SQL injection attacks. Assuming the ID is a number you could make sure it is with the ctype_digit() function:

http://us1.php.net/ctype_digit

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.