When using "Select *" I'm not able to access all f

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jlgray48
Forum Newbie
Posts: 5
Joined: Sun Apr 22, 2007 11:38 am

When using "Select *" I'm not able to access all f

Post by jlgray48 »

Jcart | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


When I use "Select *" in the code below I am not able to access all fields. If I use "Select Name" or "Select Address" I'm able to access those. Here is my code.

Code: Select all

<?php

$test = $_REQUEST['ID'];
  
$conn=mysql_connect("127.0.0.1", "odbc", "") ; 

mysql_select_db("php000",$conn); 

$sql = "Select name from mystudent where  sid=$test";

$result = mysql_query($sql,$conn) or die("Error".mysql_error()); 

while ($array = mysql_fetch_array($result)) {

print $array['name'];


}
?>

Jcart | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

$sql = "Select * from mystudent where sid= ". intval($test);
?

Notice I've also used intval() because you are expecting an integer.. we don't want anyone trying to insert anything naughty now do we!

mysql_real_escape_string() should be used when you are expecting strings
Post Reply