Page 1 of 1

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

Posted: Sun Apr 22, 2007 9:41 pm
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]

Posted: Sun Apr 22, 2007 9:56 pm
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