extracting id from db from a form field

extracting id from db from a form field

am 27.05.2011 21:11:54 von David McGlone

Hello everyone,

I need a little help. I've never tried to extract from a db in the
manner I'm trying. It's pretty simple and straightforward I believe, but
for some reason I can't figure out how.

What I have is a form with 1 simple field, and this field takes the ID
of the row I want returned.

Here's my code so far.

--index.php--

echo '


Enter Error Code:




' ;

-result.php-
$errorcode = $_POST['ErrorCode'];

echo $errorcode;

$sql = mysql_query("SELECT errorcode,definition FROM Sheet1");

while ($row = mysql_fetch_array($sql)) {
echo "$row[errorcode]
";
echo "$row[definition]
";
}

So far this is as far as I've got. I can successfully post the number
entered into the form field, but I'm having trouble making use of the
number.

With this code, my idea was to turn the posted number from the form into
a variable and use that as a reference to extract that row number from
the db, but my attempts are unsuccessful.

I've also unsuccessfully attempted to use a WHERE clause in my SELECT to
only display the row that is posted.

I hope all this makes sense.

Regards,
David M.




--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: extracting id from db from a form field

am 27.05.2011 21:48:46 von Karl DeSaulniers

Hi David,
Try this..

if(!isset($_POST['ErrorCode'])) {
die('You did not enter an error code!');
} else {
$errorcode = $_POST['ErrorCode'];
$sql = mysql_query("SELECT * FROM Sheet1 WHERE errorcode='".
$errorcode."' ");
if($sql && mysql_numrows($sql) > 0) {
$row = mysql_fetch_array($sql);
for($i=0; $i echo ("Error Code: ".$row[$i]['errorcode']."
");
echo ("Error Definition: ".$row[$i]['definition']."
");
echo ("
");
}
} else {
die('No Error Code found in database');
}
}

Have not tested this, and there may be a better "short-hand" way of
writing this, but hope it gets you on your way...

Best,
Karl

On May 27, 2011, at 2:11 PM, David McGlone wrote:

> Hello everyone,
>
> I need a little help. I've never tried to extract from a db in the
> manner I'm trying. It's pretty simple and straightforward I
> believe, but
> for some reason I can't figure out how.
>
> What I have is a form with 1 simple field, and this field takes the ID
> of the row I want returned.
>
> Here's my code so far.
>
> --index.php--
>
> echo '


> Enter Error Code:

>

>
>
' ;
>
> -result.php-
> $errorcode = $_POST['ErrorCode'];
>
> echo $errorcode;
>
> $sql = mysql_query("SELECT errorcode,definition FROM Sheet1");
>
> while ($row = mysql_fetch_array($sql)) {
> echo "$row[errorcode]
";
> echo "$row[definition]
";
> }
>
> So far this is as far as I've got. I can successfully post the number
> entered into the form field, but I'm having trouble making use of the
> number.
>
> With this code, my idea was to turn the posted number from the form
> into
> a variable and use that as a reference to extract that row number from
> the db, but my attempts are unsuccessful.
>
> I've also unsuccessfully attempted to use a WHERE clause in my
> SELECT to
> only display the row that is posted.
>
> I hope all this makes sense.
>
> Regards,
> David M.
>
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

Karl DeSaulniers
Design Drumm
http://designdrumm.com


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: extracting id from db from a form field

am 27.05.2011 22:35:19 von Karl DeSaulniers

Oh I forgot..

.... WHERE errorcode='".mysql_real_escape_string($errorcode)."');

Best,
Karl


On May 27, 2011, at 2:48 PM, Karl DeSaulniers wrote:

> Hi David,
> Try this..
>
> if(!isset($_POST['ErrorCode'])) {
> die('You did not enter an error code!');
> } else {
> $errorcode = $_POST['ErrorCode'];
> $sql = mysql_query("SELECT * FROM Sheet1 WHERE errorcode='".
> $errorcode."' ");
> if($sql && mysql_numrows($sql) > 0) {
> $row = mysql_fetch_array($sql);
> for($i=0; $i > echo ("Error Code: ".$row[$i]['errorcode']."
");
> echo ("Error Definition: ".$row[$i]['definition']."
");
> echo ("
");
> }
> } else {
> die('No Error Code found in database');
> }
> }
>
> Have not tested this, and there may be a better "short-hand" way of
> writing this, but hope it gets you on your way...
>
> Best,
> Karl
>
> On May 27, 2011, at 2:11 PM, David McGlone wrote:
>
>> Hello everyone,
>>
>> I need a little help. I've never tried to extract from a db in the
>> manner I'm trying. It's pretty simple and straightforward I
>> believe, but
>> for some reason I can't figure out how.
>>
>> What I have is a form with 1 simple field, and this field takes
>> the ID
>> of the row I want returned.
>>
>> Here's my code so far.
>>
>> --index.php--
>>
>> echo '


>> Enter Error Code:

>>

>>
>>
' ;
>>
>> -result.php-
>> $errorcode = $_POST['ErrorCode'];
>>
>> echo $errorcode;
>>
>> $sql = mysql_query("SELECT errorcode,definition FROM Sheet1");
>>
>> while ($row = mysql_fetch_array($sql)) {
>> echo "$row[errorcode]
";
>> echo "$row[definition]
";
>> }
>>
>> So far this is as far as I've got. I can successfully post the number
>> entered into the form field, but I'm having trouble making use of the
>> number.
>>
>> With this code, my idea was to turn the posted number from the
>> form into
>> a variable and use that as a reference to extract that row number
>> from
>> the db, but my attempts are unsuccessful.
>>
>> I've also unsuccessfully attempted to use a WHERE clause in my
>> SELECT to
>> only display the row that is posted.
>>
>> I hope all this makes sense.
>>
>> Regards,
>> David M.
>>
>>
>>
>>
>> --
>> PHP Database Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>
> Karl DeSaulniers
> Design Drumm
> http://designdrumm.com
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

Karl DeSaulniers
Design Drumm
http://designdrumm.com


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: extracting id from db from a form field

am 27.05.2011 22:50:37 von David McGlone

On Fri, 2011-05-27 at 14:48 -0500, Karl DeSaulniers wrote:
> Hi David,
> Try this..
>
> if(!isset($_POST['ErrorCode'])) {
> die('You did not enter an error code!');
> } else {
> $errorcode = $_POST['ErrorCode'];
> $sql = mysql_query("SELECT * FROM Sheet1 WHERE errorcode='".
> $errorcode."' ");
> if($sql && mysql_numrows($sql) > 0) {
> $row = mysql_fetch_array($sql);
> for($i=0; $i > echo ("Error Code: ".$row[$i]['errorcode']."
");
> echo ("Error Definition: ".$row[$i]['definition']."
");
> echo ("
");
> }
> } else {
> die('No Error Code found in database');
> }
> }
>
> Have not tested this, and there may be a better "short-hand" way of
> writing this, but hope it gets you on your way...

Thank you Karl, after a minute or two, or three ;-) I had it working,
but I had to change in the first line !isset to empty. For some reason
it wasn't working with !isset. and I had to
change: .$row[$i]['errorcode']. to .$row['errorcode']. because it wasn't
allowing for more than 1 digit in the error code number, but it was
displaying the correct error definition
and
.$row[$i]['definition']. to .$row['definition']. had to be changed
because it was displaying the error code and not the definition.

Now the only problem I've got to figure out is altering it so it doesn't
exclude row[0].

Blessings,
David M.



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: extracting id from db from a form field

am 27.05.2011 23:08:54 von Karl DeSaulniers

Hi David,
Yeah sorry, that was all of the top of the head, so I apologize if
anything was incorrect.
I am glad you got it working though..

Best,
Karl


On May 27, 2011, at 3:50 PM, David McGlone wrote:

> On Fri, 2011-05-27 at 14:48 -0500, Karl DeSaulniers wrote:
>> Hi David,
>> Try this..
>>
>> if(!isset($_POST['ErrorCode'])) {
>> die('You did not enter an error code!');
>> } else {
>> $errorcode = $_POST['ErrorCode'];
>> $sql = mysql_query("SELECT * FROM Sheet1 WHERE errorcode='".
>> $errorcode."' ");
>> if($sql && mysql_numrows($sql) > 0) {
>> $row = mysql_fetch_array($sql);
>> for($i=0; $i >> echo ("Error Code: ".$row[$i]['errorcode']."
");
>> echo ("Error Definition: ".$row[$i]['definition']."
");
>> echo ("
");
>> }
>> } else {
>> die('No Error Code found in database');
>> }
>> }
>>
>> Have not tested this, and there may be a better "short-hand" way of
>> writing this, but hope it gets you on your way...
>
> Thank you Karl, after a minute or two, or three ;-) I had it working,
> but I had to change in the first line !isset to empty. For some reason
> it wasn't working with !isset. and I had to
> change: .$row[$i]['errorcode']. to .$row['errorcode']. because it
> wasn't
> allowing for more than 1 digit in the error code number, but it was
> displaying the correct error definition
> and
> .$row[$i]['definition']. to .$row['definition']. had to be changed
> because it was displaying the error code and not the definition.
>
> Now the only problem I've got to figure out is altering it so it
> doesn't
> exclude row[0].
>
> Blessings,
> David M.
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

Karl DeSaulniers
Design Drumm
http://designdrumm.com


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: extracting id from db from a form field

am 27.05.2011 23:13:11 von Karl DeSaulniers

To get row 0
make the for loop change to

for($i=-1;

Best,
Karl

On May 27, 2011, at 4:08 PM, Karl DeSaulniers wrote:

> Hi David,
> Yeah sorry, that was all of the top of the head, so I apologize if
> anything was incorrect.
> I am glad you got it working though..
>
> Best,
> Karl
>
>
> On May 27, 2011, at 3:50 PM, David McGlone wrote:
>
>> On Fri, 2011-05-27 at 14:48 -0500, Karl DeSaulniers wrote:
>>> Hi David,
>>> Try this..
>>>
>>> if(!isset($_POST['ErrorCode'])) {
>>> die('You did not enter an error code!');
>>> } else {
>>> $errorcode = $_POST['ErrorCode'];
>>> $sql = mysql_query("SELECT * FROM Sheet1 WHERE errorcode='".
>>> $errorcode."' ");
>>> if($sql && mysql_numrows($sql) > 0) {
>>> $row = mysql_fetch_array($sql);
>>> for($i=0; $i >>> echo ("Error Code: ".$row[$i]['errorcode']."
");
>>> echo ("Error Definition: ".$row[$i]['definition']."
");
>>> echo ("
");
>>> }
>>> } else {
>>> die('No Error Code found in database');
>>> }
>>> }
>>>
>>> Have not tested this, and there may be a better "short-hand" way of
>>> writing this, but hope it gets you on your way...
>>
>> Thank you Karl, after a minute or two, or three ;-) I had it working,
>> but I had to change in the first line !isset to empty. For some
>> reason
>> it wasn't working with !isset. and I had to
>> change: .$row[$i]['errorcode']. to .$row['errorcode']. because it
>> wasn't
>> allowing for more than 1 digit in the error code number, but it was
>> displaying the correct error definition
>> and
>> .$row[$i]['definition']. to .$row['definition']. had to be changed
>> because it was displaying the error code and not the definition.
>>
>> Now the only problem I've got to figure out is altering it so it
>> doesn't
>> exclude row[0].
>>
>> Blessings,
>> David M.
>>
>>
>>
>> --
>> PHP Database Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>
> Karl DeSaulniers
> Design Drumm
> http://designdrumm.com
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

Karl DeSaulniers
Design Drumm
http://designdrumm.com


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: extracting id from db from a form field

am 27.05.2011 23:46:00 von Karl DeSaulniers

Actually you can keep $i as zero, it should still get row 0 now that
I think of it.

dont know how your table is set up so hard to tell.


On May 27, 2011, at 4:31 PM, David McGlone wrote:

> On Fri, 2011-05-27 at 16:13 -0500, Karl DeSaulniers wrote:
>> To get row 0
>> make the for loop change to
>>
>> for($i=-1;
>
> Hmm, when changing to -1 the error prints to the screen twice and when
> entering 0 I still get "You did not enter an error code!"
>
> Blessings,
> David M.
>

Karl DeSaulniers
Design Drumm
http://designdrumm.com


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: extracting id from db from a form field

am 28.05.2011 00:20:24 von Karl DeSaulniers

Good 2 hear.

Pay it forward.. :)

On May 27, 2011, at 4:50 PM, David McGlone wrote:

> On Fri, 2011-05-27 at 16:13 -0500, Karl DeSaulniers wrote:
>> To get row 0
>> make the for loop change to
>>
>> for($i=-1;
>
> Karl, it's completely working now, I changed empty back to !isset and
> that did the trick. Got me curious now :-)
>
> Blessings,
> David M.
>

Karl DeSaulniers
Design Drumm
http://designdrumm.com


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php