Re: [PHP-DB] Filling Drop-Down Box.

2004-12-25 Thread Mike S.
> Hello All,
>
> I want to fill drop-down box from mysql table, if any body
> be kind to tell me a sample code :)
> e.g:
> In my application i want to gather subject list from current
> semester-subject table of a student.
>
> TIA
> --
> Nayyar Ahmad

You know that the HTML code for the drop-down is:

Whatever 1
Whatever 2


Here's some "pseudo-code" remarks that should help you with your coding:

- whatever.html -
Drop-down: 
whatever
   //  for each element in the drop-down.  You can get creative
   //  here if you need to.  Like:
   //  whatever
   //  where ## is the key field, and whatever is another
   //(descriptive) field in your query
   //  close your database connection (or later, if needed)
?>

Try to fill in the actual code yourself.
If you get stuck, you can look at:
http://www.netmask.com/php-db/sample-dropdown.html

Good luck!

:Mike S.
:Austin TX USA

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



Re: [PHP-DB] data is not entering in created database

2004-12-24 Thread Mike S.
> hallo ,
>
> i have wriiten simple php script , below.
> created databse "dollar1_allinfo" with table 'totalinfo'
>
> but on clicking submit button ,
>
> information entered is not entering in database.
>
> also,  echo statements are also not displaying after submit
>
>  if ($submit)
> {
> $db = mysql_connect("localhost","root");
> mysql_select_db("dollar1_allinfo",$db);
> mysql_query("INSERT INTO totalinfo (username,password,) VALUES
> ('$loginusername','$loginpassword')");
>  echo 'thank you';
>  echo 'So Hurry Up';
>   }
>?>
>
> thank you.

Because your query and echoes are within an "if" block, I'd say that
$submit is evaluating to FALSE, and thus not executing the query and
echoes.

Add (before the if statement):

   echo "Submit = $submit";

Make sure that $submit is evaluating to TRUE.


To All Beginning Programmers ("Newbies"), or just people who want to
easily debug their code:
Try adding debugging statements to help you find problems.  A few echoes
or prints in selected locations will help identify the issue.  Make sure
your variables are evaluating to values that you think they should be.

If you want to keep the debugging statements in your code and just
activate them when you need to see them, do something like:
// near the top of your code
$debug=TRUE;
// and anywehere in your code
if ($debug) {
   echo "DEBUG: Submit = $submit\n";
}
// or whatever echo might help you nail down the problem.  Put as many of
these in your code and you can turm them ON and OFF very easily, by
changing one line of code.

OR for even quicker debugging, replace $debug=TRUE; with
   $debug=$_GET['debug'];
and then you can turn it on in by adding ?debug=TRUE at the end of the
URL. Example:  http://www.php.net/path/my.html?debug=TRUE
or:  http://www.php.net/path/my.html?debug=1
**DISCLAIMER**  Using the URL method is NOT a secure way to do this!!! 
And I'm sure there's plenty of folks groaning out there because it is a
BIG security hole.  You really would want to do this on a development
machine and network, and remove the debug code for production.  That
really should go without saying.

Good luck.

:Mike S.
:Austin TX USA

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



Re: SV: [PHP-DB] Drawing table by while

2004-05-26 Thread Mike S.
Or like this (to be a little more complete, with comments):

// initialize counter
$count=0;

// start the table and the first row
echo "";

// loop through fetch results
while ($myrow = mysql_fetch_array($sql))
{
   //  if we've output 5 columns...
   if ($count==5) {
  //  end the current row, start another
  echo "";
  //  and reset our counter
  $count=0;
   }
   // output the next cell in this row
   echo "".$myrow[0]."";
   // and increment the counter
   $count++;
}
// end the row and the table
echo '';


I've used this type of code before, but have not checked the specific code
above for spelling or other typographic errors.

The example code posted earlier (see below) had a small error in that the
counter was incremented twice if it was the first column, therefore only
printing 4 columns.


:Mike S.
:Austin TX USA



> Something like this:
>
> echo '';
> $count=1;
> while ($myrow = mysql_fetch_array($sql))
> {
> If ($count==5) {
>   echo "";
>   $count=1;
> }
> If ($count==1) echo "";
> $count++;
> echo $myrow[0];
> }
> echo '';
>
> Hth Henrik Hornemann
>
> -Oprindelig meddelelse-
> Fra: nabil [mailto:[EMAIL PROTECTED]
> Sendt: 26. maj 2004 14:28
> Til: [EMAIL PROTECTED]
> Emne: [PHP-DB] Drawing table by while
>
>
> Hiya,
>
> How can i draw a new  AFTER FIVE   in the following loop
>
> (i want to echo the records in 5 columns width tables whatever the
> number of records will be fetched)
>
> ..
> echo '';
>
> while ($myrow = mysql_fetch_array($sql))
> {
> echo $myrow[0];
> }
> echo '';
>
>
> --
> |   x |   y |z  |   o |
> --
> |f|q|  h|   hj |
> --
> .
> .
> .

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



[PHP-DB] Re: Form doesnt write to database

2004-02-07 Thread Mike S.
> Dear friends,
> Form doesn't write to mysql database. I have pasted code of mysal
> table structure,html form and php script. Any comments, please.

> // create the SQL statement
> $sql = "INSERT INTO testtable values ('{'', $_POST['testField']}','
> {'', $_POST['testFielda']}','{'', $_POST['testFieldb']}','{'',
> $_POST['testFieldd']}','
> {'', $_POST['testFieldc']}','{'', $_POST['testFielde']}')";

I tried your code on my system and got an error of 'incorrect number of
parameters'.  That's when I realized you need NULL as the first
parameter in your values.  I didn't see in the MySQL docs where it
requires the NULL, but in one of the examples, it was there.

Insert NULL as the first parameter and it should work.

I also got a parse error because of the '{' and '}' symbols around your
$_POST variables.  I changed it to:

$sql = "INSERT INTO testtable values ( NULL, '".$_POST['testField']."',
'".$_POST['testFielda']."', '".$_POST['testFieldb']."',
'".$_POST['testFieldd']."', '".$_POST['testFieldc']."',
'".$_POST['testFielde']."' )";

and got a working solution.

Suggestion: You could try using the mysql_errno() and mysql_error()
functions.  Print them out after your failed statement and you'll see
why the mysql call failed.

Example:
  print "Error # ".mysql_errno()." - ".mysql_error()."\n";

will print the error number and message.  This will give you some idea
of what went wrong.

Good coding practice dictates that you check for an error condition
after mysql calls [using mysql_errno()] and handle any errors
appropriately.

If you don't already have it, you'll want a list of the error codes and
their meanings.  You can find it in the mysql source code
Docs/mysqld_error.txt file.  If you can't find that right now, copy this
web page I whipped up right now:

   http://web.netmask.com/2004/02/mysql-error-codes.html

or, if you prefer a flat, text file:

   http://web.netmask.com/2004/02/mysql-error-codes.txt



Good luck!

:Mike S.
:Austin TX


---
Sent: February 7, 2004, 6:48 pm

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



[PHP-DB] Re: Associated popup menu (php/mysql)

2004-02-05 Thread Mike S.
Actually, there is a way to do this with PHP.  It may not be the best
method, but it is possible.  You could do it with one single source file,
or multiple.

With a single source file you could do something like this:
The first time through would display the first popup with valid choices. 
Form action would post the results of the popup to the same page.  Now you
have a variable with a value from the first popup.  You can then display
your second popup choices based on the first.  And so on for any remaining
popups.

With multiple source files:
The first page displays the first popup. Form action would post the
results to the next page.  As with the first method, you now have a
variable with a value from the first popup.  Display your second popup
choices based on the first.  And so on...

Pro:  You don't need to learn Javascript.
Con:  The web page is redrawn for each new popup selection - not seamless
like a pure Javascript solution may be.

Using multiple source files may help you keep load time down as well as
make it easier to maintain.  It's a matter of personal choice, I think.

If you don't program Javascript, this is one method you may consider -
though I would encourage anyone writing web pages to learn Javascript. It
can be a real lifesaver!  :-)

With either method (PHP or Javascript), you'll probably want to code in
some way for the user to go back and re-select the first popup, i.e. start
over.

Sorry, I don't have sample code.  I haven't had a need for this type of
popups yet, but I have a project coming up soon that probably will.  If I
get a chance to code up a sample, I'll make it available.

Good luck.

:Mike S.
:Austin TX

On Thu February 5 2004 7:33pm, Micah Stevens wrote:
>
> Javascript is client side programming, PHP is server side and unable to
> control actions and make decisions on what's happening in the browser
> except  in a 'third person' manner.
>
> Simply put, you can't do this with PHP.
>
> On Thu February 5 2004 5:21 pm, alb_shop wrote:
>> Hello all,
>>
>> I've been searching for hours and cannot find the answer or sample in
>> in any forum.
>>
>> What is the best method (any sample or help would be appreciated), to
>> associate popup menus in a form. Choosing the first popup menu (Main
>> categorie) should provide to me the results for the second popup menu
>> (subcategory).
>>
>> Ie : Countries --> states
>>
>> I know that javascript can do this sort of things, but I would like to
>> use only php. Is that possible ?
>>
>> I have two tables in mysql: Countries & states that can be associated
>> by id_country.
>>
>> Thank you


---
Sent: February 6, 2004, 12:09 am

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