Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

Submit dropdown list values to mysql

Links for php scripts

Moderators: macek, egami, gesf

Re: Submit dropdown list values to mysql

Postby kevz » Fri Mar 15, 2013 12:00 pm

SCREAM: Error suppression ignored for
Notice: Undefined property: PDOStatement::$rowCount in C:\wamp\www\test\index.php on line 10

could not pull city names for country 2
kevz
New php-forum User
New php-forum User
 
Posts: 29
Joined: Fri Mar 15, 2013 6:50 am

Re: Submit dropdown list values to mysql

Postby seandisanti » Fri Mar 15, 2013 12:02 pm

on that line, update rowCount to be rowCount()
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 681
Joined: Mon Oct 01, 2012 12:32 pm

Re: Submit dropdown list values to mysql

Postby kevz » Fri Mar 15, 2013 12:06 pm

could not pull city names for country 2

it just says that now in the webbrowser. I don't have a clue whats going on to be honest!

***EDIT****
I have checked to make sure that my table names and column names match whats on the script as well.

EDIT:

Ok now i know whats causing the above issue. The 2nd drop down list is not picking up any values from the database
Last edited by kevz on Fri Mar 15, 2013 12:10 pm, edited 1 time in total.
kevz
New php-forum User
New php-forum User
 
Posts: 29
Joined: Fri Mar 15, 2013 6:50 am

Re: Submit dropdown list values to mysql

Postby seandisanti » Fri Mar 15, 2013 12:10 pm

the issue is most likely with the $sql_city query. I made some assumptions there, specifically that you were pulling from table city that contains a field 'country_id' that has the numeric country code.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 681
Joined: Mon Oct 01, 2012 12:32 pm

Re: Submit dropdown list values to mysql

Postby kevz » Fri Mar 15, 2013 12:20 pm

i included the 2 tables
Attachments
tables.gif
the 2 tables: country and city
tables.gif (7.1 KiB) Viewed 261 times
kevz
New php-forum User
New php-forum User
 
Posts: 29
Joined: Fri Mar 15, 2013 6:50 am

Re: Submit dropdown list values to mysql

Postby seandisanti » Fri Mar 15, 2013 12:21 pm

what's the name of the second table? i assumed city, but if it's cities, or something else, it's just a change to line 6
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 681
Joined: Mon Oct 01, 2012 12:32 pm

Re: Submit dropdown list values to mysql

Postby seandisanti » Fri Mar 15, 2013 12:28 pm

my code is working on my side after creating those tables.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 681
Joined: Mon Oct 01, 2012 12:32 pm

Re: Submit dropdown list values to mysql

Postby seandisanti » Fri Mar 15, 2013 12:30 pm

Sorry, one thing to change to make it work exactly as intended; line 37 (for the submit button) needs a ! added to the condition, to reverse the logic. it should read:
Code: Select all

<input type="submit" value="' . (!(isset($_POST['country']))?'Get cities':'Submit form') . '" />';
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 681
Joined: Mon Oct 01, 2012 12:32 pm

Re: Submit dropdown list values to mysql

Postby kevz » Fri Mar 15, 2013 12:34 pm

the name of table 2 is city

****EDIT*****
Could it be something to do with my internet explorer settings? Maybe somethings is disabled in internet options?
Last edited by kevz on Fri Mar 15, 2013 12:37 pm, edited 1 time in total.
kevz
New php-forum User
New php-forum User
 
Posts: 29
Joined: Fri Mar 15, 2013 6:50 am

Re: Submit dropdown list values to mysql

Postby seandisanti » Fri Mar 15, 2013 12:36 pm

Is it still giving an error?
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 681
Joined: Mon Oct 01, 2012 12:32 pm

Re: Submit dropdown list values to mysql

Postby kevz » Fri Mar 15, 2013 12:38 pm

i dont get any errors until i click the submit button. But this is because the 2nd drop down list dont show any values

EDIT: When i click the submit with the 2nd empty drop down list then i get this message "could not pull city names for country 1"
kevz
New php-forum User
New php-forum User
 
Posts: 29
Joined: Fri Mar 15, 2013 6:50 am

Re: Submit dropdown list values to mysql

Postby seandisanti » Fri Mar 15, 2013 12:42 pm

I've posted a working copy of the same thing here on my domain... http://seandisanti.com/trystuff.php
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 681
Joined: Mon Oct 01, 2012 12:32 pm

Re: Submit dropdown list values to mysql

Postby kevz » Fri Mar 15, 2013 12:43 pm

this is the webbrower bit where it shows the 2nd drop down list dont show any thing
Attachments
webbrowser.gif
webbrowser.gif (2.39 KiB) Viewed 258 times
kevz
New php-forum User
New php-forum User
 
Posts: 29
Joined: Fri Mar 15, 2013 6:50 am

Re: Submit dropdown list values to mysql

Postby seandisanti » Fri Mar 15, 2013 12:44 pm

right... click 'get cities', and it should populate the second drop down
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 681
Joined: Mon Oct 01, 2012 12:32 pm

Re: Submit dropdown list values to mysql

Postby kevz » Fri Mar 15, 2013 12:45 pm

hmmmm......when i tried it from your domain, i get the same problem as mine in my browser


*******EDIT********
Sorry man, even right clicking get cities dont do anything on my web browser but it works on your domain.
kevz
New php-forum User
New php-forum User
 
Posts: 29
Joined: Fri Mar 15, 2013 6:50 am

Re: Submit dropdown list values to mysql

Postby seandisanti » Fri Mar 15, 2013 12:49 pm

lol, sorry, i didn't mean 'right click', i meant 'that looks right, now just click get cities'
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 681
Joined: Mon Oct 01, 2012 12:32 pm

Re: Submit dropdown list values to mysql

Postby kevz » Fri Mar 15, 2013 12:51 pm

it works fine on yours buts not on mine still. Still saying "cant get cities from country 1/2"
kevz
New php-forum User
New php-forum User
 
Posts: 29
Joined: Fri Mar 15, 2013 6:50 am

Re: Submit dropdown list values to mysql

Postby kevz » Fri Mar 15, 2013 12:52 pm

This is the code i got on my notepad ++ at moment.

Code: Select all
 <?php

    $db = new PDO("mysql:host=localhost;dbname=test", "root", "");
    if ($_POST) {//are we responding to a form?
        $country = $_POST['country'];
        $sql_city = "SELECT * FROM city WHERE country_id =" . $country;
        $cityResult = $db->query($sql_city);
        if ((!$cityResult) || $cityResult->rowCount()) {
            die('could not pull city names for country ' . $country);
        }
    }
    $sql_country = "SELECT * FROM country";
    $countryResult = $db->query($sql_country);
    if ((!$countryResult) || $countryResult->rowCount() == 0) {
        die('no countries pulled from database');
    }
    echo '
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <title>Country List</title>
        </head>
        <body>';
    echo '<form id="frm" action="' . ((isset($_POST['city'])?'fullform.php':$_SERVER['PHP_SELF'])) . '" method="post">';
    echo '<select name="country">';
    while ($row = $countryResult->fetch(PDO::FETCH_ASSOC)) {
        echo '<option value="' . $row['id'] . '"' . ((isset($country) && $country == $row['id']) ? ' selected ' : '') . '>' . $row['country'] . '</option>';
    }
    echo "</select>";
    echo '<div id="cityLayer"><select name="city" id="city">';
    if (!empty($cityResult)) {
        while ($cRow = $cityResult->fetch(PDO::FETCH_ASSOC)) {
            echo '<option value="' . $cRow['id'] . '">' . $cRow['city'] . '</option>';
        }
    }
    echo '</select></div>
        <input type="submit" value="' . (!(isset($_POST['country']))?'Get cities':'Submit form') . '" />';
    echo '</body>
        </html>';
   
kevz
New php-forum User
New php-forum User
 
Posts: 29
Joined: Fri Mar 15, 2013 6:50 am

Re: Submit dropdown list values to mysql

Postby seandisanti » Fri Mar 15, 2013 12:54 pm

here's what I've got for everything below the credentials. I removed just that line because now it's got mine instead of yours...
Code: Select all

    
if ($_POST) {//are we responding to a form? 
        
$country $_POST['country'];
        
$sql_city "SELECT * FROM city WHERE country_id =" $country;
        
$cityResult $db->query($sql_city);
        if ((!
$cityResult) || $cityResult->rowCount() == 0) { 
           die(
'could not pull city names for country ' $country);
        }
    }
    
$sql_country "SELECT * FROM country";
    
$countryResult $db->query($sql_country);
    if ((!
$countryResult) || $countryResult->rowCount() == 0) {
        die(
'no countries pulled from database');
    }
    echo 
'
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <title>Country List</title>
        </head>
        <body>'
;
    echo 
'<form id="frm" action="' . ((isset($_POST['city'])?'fullform.php':$_SERVER['PHP_SELF'])) . '" method="post">';
    echo 
'<select name="country">';
    while (
$row $countryResult->fetch(PDO::FETCH_ASSOC)) {
        echo 
'<option value="' $row['id'] . '"' . ((isset($country) && $country == $row['id']) ? ' selected ' '') . '>' $row['country'] . '</option>';
    }
    echo 
"</select>";
    echo 
'<div id="cityLayer"><select name="city" id="city">';
    if (!empty(
$cityResult)) {
        while (
$cRow $cityResult->fetch(PDO::FETCH_ASSOC)) {
            echo 
'<option value="' $cRow['id'] . '">' $cRow['city'] . '</option>';
        }
    }
    echo 
'</select></div>
        <input type="submit" value="' 
. (!(isset($_POST['country']))?'Get cities':'Submit form') . '" />';
    echo 
'</body>
        </html>'
;
      
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 681
Joined: Mon Oct 01, 2012 12:32 pm

Re: Submit dropdown list values to mysql

Postby seandisanti » Fri Mar 15, 2013 12:55 pm

if you want; go to http://localhost/phpMyAdmin then select the 'test' database, then click export and have it save to a .sql file. if you message that to me i can find the difference in the schema, because i think that's where the issue is
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 681
Joined: Mon Oct 01, 2012 12:32 pm

Re: Submit dropdown list values to mysql

Postby kevz » Fri Mar 15, 2013 1:09 pm

the file!
kevz
New php-forum User
New php-forum User
 
Posts: 29
Joined: Fri Mar 15, 2013 6:50 am

Re: Submit dropdown list values to mysql

Postby seandisanti » Fri Mar 15, 2013 1:49 pm

have to actually include the file or it's contents... :D
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 681
Joined: Mon Oct 01, 2012 12:32 pm

Re: Submit dropdown list values to mysql

Postby kevz » Mon Mar 18, 2013 12:39 pm

The problem has been fixed, thanks alot. i also found a good tutorial about drop down lists using javascript http://www.youtube.com/watch?v=FTJszYP6O6s

If you are a newbie like me and really desperate to create dynamic drop down list, just visit the site above and you will be all good. Also ask the guys on here for further help, they are really good esp. seandisanti
kevz
New php-forum User
New php-forum User
 
Posts: 29
Joined: Fri Mar 15, 2013 6:50 am

Re: Submit dropdown list values to mysql

Postby seandisanti » Mon Mar 18, 2013 2:21 pm

lol, thanks, I'm glad you got it sorted, and there are a lot of people on here that are happy to help, and I'd say several offer better help than me, but the consideration is appreciated and I'm glad i could help
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 681
Joined: Mon Oct 01, 2012 12:32 pm

wholesale leather handbags Burberry Outlet Online

Postby galloway8 » Mon Jun 03, 2013 5:57 am

The perfect squash racquet can make or break your squash game, aspects like grip size, head size, string tension, racket swing and flex all facilitate to discover which type of squash racquet will offer the most ideal power and control for your squash game.. On the other hand, if you are unable to obtain a good racquet, your game play will be affected.
When it pertains to selecting the perfect racquet, you have to ensure to examine every one of your options for the frames weight and balance. This is for the reason that these are the two most vital elements that can affect your game, speed, maneuverability, control and several more. As such, you should discover the most ideal Dunlop Squash racquet to help you play the game well.
Normally when seeking for the perfect weight of Squash racquets, burberry trench belt it just relates to the balance between your power and maneuverability. Meanwhile, balance relates to how tuned in you are to the game to showcase maximum control. burberry london trench You have to ensure that you test the several different racquets that you are considering so you can find one that can help you with your game.
Conventional racquets were made of wood. They were also between 368 and 397 grams. As a result of the improvements in technology, producers are now able to produce racquets that are lighter than 226 grams. To this, some racquets from Dunlop Squash are even burberry trench mens lesser than 120 grams. Because of this, individuals who make use of these racquets are in a position to maneuver more effortlessly. They also have a simpler swing due to the reduced weight of these racquets. Even though the heavier ones are typically more stronger, light racquets assist the individuals swing allowing them to maneuver quickly.
As there is an apparent change in how game play has burberry trench men affected the advancement of Squash racquets, it is significant to burberry women coat identify which one is best for you. If you are playing a slow pace game, you can make do with a little heavier racquet in order to hit the ball with a slower swing and still produce significant speed on the ball. However, if the game tends to be quick, you will be benefited from a light racquet. This is because of the player needing to be in a position to move swiftly, shorten their swing and maneuver through the courtyard. With the light racquet, this is something you can easily achieve.
Irrespective of the racquet producer, you must ensure that you get a racquet that suits you ideally. By selecting the right racquet, you will be in a position to take burberry mens trench coats advantage of your gaming experience. You will have an easy time with your favorite game as you have made the investment in the perfect tool.

Related articles:


burberry bags sale Burberry Outlet Online Sale (51)

burberry flat shoes Burberry Outlet Online Sale (1

burberry usa sale Burberry Outlet Online Sale (37)
galloway8
New php-forum User
New php-forum User
 
Posts: 200
Joined: Mon Jan 07, 2013 3:36 am

PreviousNext

Return to PHP Scripts

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.