Jump to content

ronc0011

Members
  • Posts

    54
  • Joined

  • Last visited

ronc0011's Achievements

Member

Member (2/5)

0

Reputation

1

Community Answers

  1. OK never mind I finally spotted what the problem was . The variable "conn" didn't have the right syntax. It should have been "$conn" Fixed it instantly.
  2. Honestly I’ve hit this wall more times than I can count. It typically turns out to be something seemingly arbitrary like single or double quotes and only maters sometimes and sometimes not. OK enough with the ranting. Here is the code that is making me pull my hair out… It’s a PDO connection string that I’m getting from a Youtube video. $host = "127.0.0.1"; $user = "root"; $pass = "r00t"; $db = "cars"; try{ conn = new PDO ("mysql:host=$host;dbname=$db", "$user", "$pass"); conn -> setAttrabute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "Oh happy day we have connected to our database"; } Catch (PDOException $e) { die("Well, that didn't work at all"); } It’s giving me this error… Parse error: syntax error, unexpected '=' in C:\Apache24\htdocs\PDO\conn.php on line 10 Line 10 is the line with the new PDO. I’ve been staring at the example code and comparing it to my code till my eyes are about to cross and I can’t find what it is that’s causing the problem. I’ve tried it with double quotes as well as single quotes. No help. I only say that because it’s been an issue on other occasions
  3. I’m working on building a web (html) form for a vehicle maintained app. I think most of it will be pretty straight forward but the first problem is building the dropdown list for Make & Model. I have found some info on doing this with javascript but I’m wondering if there is a way to do this with PHP. Basically I need to make a dropdown list of Automobile brands / makes i.e. Ford, Chevy, Dodge, etc. Next I need a second dropdown list of models. The models need to be dependent on the Make selected in the first, “Make” dropdown. So if Ford is selected on the “Make” dropdown then the options shown in the “Model” dropdown will be appropriately, Mustang, Taurus, Focus, F50, etc. The Javascript I’ve found looks like this… function populate(s1,s2){ s2.innerHTML = ""; if(s1.value == "Chevy"){ var optionArray = ["|","camaro|Camaro","corvette|Corvette","impala|Impala"]; } else if(s1.value == "Dodge"){ var optionArray = ["|","avenger|Avenger","challenger|Challenger","charger|Charger"]; } else if(s1.value == "Ford"){ var optionArray = ["|","mustang|Mustang","shelby|Shelby"]; } for(var option in optionArray){ var pair = optionArray[option].split("|"); var newOption = document.createElement("option"); newOption.value = pair[0]; newOption.innerHTML = pair[1]; s2.options.add(newOption); } } </head> <body onload="process()"> <h2>Choose Your Car</h2> <hr /> Choose Car Make: <select id="slct1" name="slct1" onchange="populate(this.id,'slct2')"> <option value=""></option> <option value="Chevy">Chevy</option> <option value="Dodge">Dodge</option> <option value="Ford">Ford</option> </select> <hr /> Choose Car Model: <select id="slct2" name="slct2"></select> <hr /> </body> </html> This code does in fact work though I’m not actually seeing how to capture and use the selected values from the second list. Actually that’s why I’m looking to see if there is a PHP approach to this. This code kind of loses me at the end where its creating newOptions and where it’s storing the selected values.
  4. This apparently was the issue It's not the first time I've been tripped up by the double / single quotes issue. In fact I did have that string as double quotes originally and swapped them for single quotes when it wasn't working . I don't remember why / how it wasn't working. That was 4 days ago.
  5. Hmm.. I’m not real sure what the fifferencwe was but I’ll review is later I actuall had a previous version on the file commented out which I just swapped for the one that wasn't working and apparently that was the problem, made the swap and every hing started working So here’s the working version… $conn = new PDO ( "mysql:host=" . $db_host . ";dbname=" . $db , $db_user , $db_pw); var_dump ($conn);
  6. Really? You're thinking there's a problem with the PDO connection string?
  7. Thank you for your quick and informative response. I made the corrections you noted . In fact when that didn’t seem to work I copy / pasted it into my page. Still no joy. So now that block reads thus… <?php $query = "SELECT * FROM t1" ; $result = $conn->query($query); if ($result->rowCount()>0) { foreach ( $result as $item ) { echo ( $item ['name']. $item ['email']); } } ?> Still getting the same error. Actually I had suspected the line you referenced but couldn’t spot the problem. However I wasn’t aware of the “spaces” issue” (I’m very new to PHP). In any event the issue persist. So clearly, the error message says it’s trying to call a function on a Boolean but what I’m not understanding is why the Youtube presenter’s code is working and mine isn’t. Why isn’t his code seeing that variable as a Boolean and choking when it tries to run? The only difference I can see is that the Youtube code names his connection string $odb and I named mine $conn. BTW the video is here https://www.youtube.com/watch?v=BQx5TJe1Fr0 And that block of code is in the last half of the video.
  8. I don’t seem to be able to find the issue with this code. I’m following along with a tutorial I found on Youtube and so far I’ve managed to get everything to work . This piece is toward the end of this particular section and it’s giving me this error and I’ve looked and looked and don’t seem to be able to find the problem I have a file named conn.php and of course a file, index.php. The connection string is in “conn.php” like so… <?php $db_host = "127.0.0.1"; $db_user = "root"; $db_pw = "r00t"; $db = "test1"; echo "$db_host <br/> $db_user <br/> $db_pw <br/> $db <br/> "; $conn = new PDO ( 'mysql:host = $db_host; dbname = $db; charset = utf8', "$db_user", "$db_pw"); var_dump ($conn); ?> The extra stuff is just there to check the connection. Gives me positive feedback. On the index.php page I begin the page with… <?php require_once ("conn.php"); ?> Then after the Html DOCTYPE etc… Inside the Body tags I have this… <?php $query = "SELECT * FROM t1" ; $result = $conn -> query ($query); if ($result->rowCount()>0) { foreach ( $result as $item ) { echo ( $item ['name']. $item ['email']); } } ?> There is a database named test1 with a table named t1. In this table there are 3 columns ID, name, and email. With 4 records / rows. When I try to run this it throws this error… Fatal error: Uncaught Error: Call to a member function rowCount() on boolean in C:\Apache24\htdocs\t-1\index.php:33 Stack trace: #0 {main} thrown in C:\Apache24\htdocs\t-1\index.php on line 33 I’m running all this on my laptop I have Apache 2.4 and PHP 7 and MySQL 5.6. These are all straight installs. No WAMP . Am I just not seeing something really obvious??? Any thoughts on this???
  9. Actually I just deleted several copies of the TS versions in order to clear room on my little Surface Pro. As noted before every time I tried to use PHP7 Apache wouldn’t start and googling it only turned up pages citing the missing dll issue. Thus my views on the state of modern American education.
  10. Well, what'd ya know? After a 2nd day of searching I've run across a site with links to the PHP7 downloads that are actually complete. This tutorial has links to the Apache24 downloads and the PHP7 downloads and wonder of wonders, these downloads actually have the “php7apache2_4.dll” file. I literally couldn’t begin to count the sites I went to and tried unsuccessfully to implement. Small wonder the big tech companies are outsourcing / recruiting overseas engineers and coders. The American academic environment is turning out useless wastes of time. BTW here is the page that actually provides for a successful install of Apache 2.4 and PHP7 . https://danielarancibia.wordpress.com/2015/09/27/installing-apache-2-4-and-php-7-for-development-on-windows/ In my case this is on a Windows Surface pro running Windows 8.1
  11. I have spent an entire day trying to make this work and it simply will not do it. I have tried Apache from everywhere, finally from Apache Lounge. I have tried PHP version VC11, VC14 no matter what I try as soon as I add the line “php5_module "c:/php/php5apache2_4.dll" or “php7_module "c:/php7/php5apache2_4.dll"… whatever. Frankly it’s become impossible to keep up with all the myriad configurations. Well actually PHP7 doesn’t even have a “php7apache2_4.dll” even though any documents you can find on it will tell you to point to that file, It doesn’t exist. All I’ve been able to find on it is some useless garbage about a mistake in the build After that I went back to trying to install VC11 still no joy it absolutely will not load . Apache will not run after these lines are added. BTW Apache is installed at “C:/Apache24”. PHP is installed at “C:/PHP” Apache will not start with the lines... LoadModule php5_module "c:/php/php5apache2_4.dll" AddHandler Application/x-httpd.php .php PHPIniDir C:/PHP I’ve been doing this for a solid 10 hours with consistently the same results. Apache will run fine until I add those lines in any of the countless arrangements suggested on all the enumerable web pages professing to tell you how to install PHP on windows 8. The really screwed up thing is that I’ve had it running before and nowhere near this much trouble
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.