SQL Query/echo not working


Posted on 16th Feb 2014 07:03 pm by admin

Hey all,

I'm trying to run (what I thought) was a simple operation and it isn't working. I haven't coded anything in about 2 years, and I'm self taught at that so I know I've got quite a few gaps in my knowledge base.

Here's what is running right now:

Code: <?php

$con = mysql_connect("localhost","adminaccount","adminpassword");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("mornin14_idiot2009", $con);

$id = $_GET['id'];

$query = "SELECT * FROM idiot WHERE index = '15'"; //I want this to say WHERE index = $id, but I'm testing this with just a #
$result = mysql_query($query);

$numrows = mysql_num_rows($result);


for ($x=0; $x<$numrows; $x++){
$result_row = mysql_fetch_row($result);
echo $result_row[0];
echo "<br />";
echo $result_row[1];
echo "<br />";
echo $result_row[3];
echo "<br />";
echo $result_row[5];
echo "<br />";

}


?>


Now it should only be returning one row since I'm checking for a specific index #.

When I just do a basic select * from idiot and omit the where clause, it works fine and dumps the whole table in the for loop. But if I try a specific where, it falls apart. Any help would be greatly appreciated.

No comments posted yet

Your Answer:

Login to answer
196 Like 44 Dislike
Previous forums Next forums
Other forums

How to make URL loads only on login
On my page, when a user login he's redirects to user_home.php. I made it also to open the chat scree

Data storage spaces in varchar2
Trying to understand what's happening.
I am selecting a value from a table that is defined as c

Web Application Recipe
Hi Guys!

I am working with the Web Application recipes. I am currently working on the sen

[PHP HELP] Php order form.
Hello to everyone @ phpfreaks. Im new to this site and hope to learn lots of things here.

Fir

Save User Inputs while javascript reloading!
hi..
i have written a PHP code in which i reload the page when user selects a value in dropdown..

please hep to get values from a table row
can anyone tel me how I can select and get data from one row by pressing an Edit button in that row

PHP login form help (Done Most of It)
Hi i am having a problem, when i try logging in it is always saying "Invalid Login" im not

Is it possible to stop reservation creation in PM Order?
Hi All,

Is it possible to stop reservation creation in PM Order?

Thanks in adv

Is there a function ... auto send IP
Is there some function that can be sent to a ddns service that returns the ip address of a ddns forw

How to return to a previous page after running a PHP script
I'm having a bit of a melt down here because I think this should be really easy but can't work it ou

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash