Jump to content

Search Form


JessicaC

Recommended Posts

I need to write a program that asks a user's name and searches the database for that user.

 

Trying to get search results to show first name and last name when a search query is entered but I can't get it to show at all. Here is my content.php: http://chenschool.elementfx.com/CS334/lab10/content.txt

 

Not sure where in my code it's wrong. I already have one row of data in the table (First name: John, last name: Doe) and entering either John or Doe does nothing (no "John Doe" text appears).

 

I made sure the column names are all correct and yes, I have connected to the database.

Link to comment
Share on other sites

After you have made the changes that benanamen has suggested, perhaps you could then post the code here instead of using a link to place that many of us here do not want to visit. Wrap it in the proper tags, ie the words "php" and "/php" each wrapped in square brackets.

Link to comment
Share on other sites

This "junk" is for a lab assignment for class. I don't need to use anything fancy let alone PDO, something I haven't even learned yet.

 

I figured out what I did wrong. It works now

 

That link does NOT link to a Facebook page. It's my own website, one of the domains which I am using for a class

Edited by JessicaC
Link to comment
Share on other sites

Despite what you have stated, we are only trying to help you to learn NOT to use outdated coding. If this is for a class where you are trying to learn PHP, at least learn the valid, current & modern PHP language. If you should pass this class and move on to being a professional programmer, I would want you to be able to present proper php code to your future employer rather than something that he/she will probably recognize for what it is and dismiss you with a 'thanks for coming in' at your interview.

Link to comment
Share on other sites

While PDO is "way better", it is also "way easier".

 

Wow your professor, and try the following.  The "?" are being replaced by the values in the array.  There are different ways you can pass the values, and different ways to control what is returned, but this will give you the general idea.

 

Have fun!

<?php
$db=new PDO("mysql:host=localhost;dbname=yourdatabase;charset",'yourusername','yourpassword');
$stmt=$db->prepare("select * from users where first_name like ? || last_name like ?");
$s='%'.$_POST['search'].'%';
$stmt->execute([$s,$s]);
$results=$stmt->fetchAll();
echo('<pre>'.print_r($results,1).'</pre>');
Link to comment
Share on other sites

 

This is what you gave us, honey:

http://l.facebook.com/l.php?u=http%3A%2F%2Fchenschool.elementfx.com%2FCS334%2Flab10%2Fcontent.txt&h=FAQH-ZTp1

 

That's odd...I didn't even post that link. My link was this: 

http://chenschool.elementfx.com/CS334/lab10/content.txt

Of course that text file no longer exists. I changed the name...

 

 

Despite what you have stated, we are only trying to help you to learn NOT to use outdated coding. If this is for a class where you are trying to learn PHP, at least learn the valid, current & modern PHP language. If you should pass this class and move on to being a professional programmer, I would want you to be able to present proper php code to your future employer rather than something that he/she will probably recognize for what it is and dismiss you with a 'thanks for coming in' at your interview.

I understand, but as far as I know, my code is supposed to follow certain instructions and we aren't using the very latest PHP. I am not sure why my professor is not using the latest, but I'm using what I learned in class. In any case, the class is easy enough that I am doing really well in the class. I also have no plans on becoming a professional programmer.

 

 

You need to talk to your professor or whoever and tell them they are teaching you code that has been deprecated for over a decade and won't even work at all in the current version of Php.

Does it even matter? If my code works, it works. So what if it's not the very latest version? It's not like I will be keeping these PHP files and code after term is over

Link to comment
Share on other sites

Why are you taking courses when you don't give a shit about the subject, refuse to learn anything about it and will have no benefits whatsoever?

I can understand people who simply keep away from programming. It's not for everybody. But choosing to program when you have no interest in doing anything right is amazingly stupid.

If your professor actually teaches that 90s garbage and accepts code which violates even the most basic programming principles, he needs to get fired. Good grief. The entire IT industry is already suffering greatly from clueless code monkeys and horrible code, but the courses of your university seem to actually create those “programmers”.

 

 

 

If my code works, it works.

 

Your code does not work. You don't even know what that means. All it does is look convincing enough to deceive your professor, and that's just sad.

Link to comment
Share on other sites

I totally agree with Jacques1 response(s) on this topic. To be teaching the future coders of the world old coding styles/methods is just wrong. Furthermore as Jacques says sending future coders out into the world with these flimsy skills is no different than sending untrained unsilled graduates out there to do any other job that they are not fully qualified for. A programmer has to have the mindset and the skillset that IS REQUIRED to do a good job, not an outdated skillset and a lackadaisical attitude toward producing good products.

 

As a former pro who had to hire coding talent I was fooled a couple of times by people who did not qualify for this kind of work but did a great job of scamming me (and their previous employers who gave them glowing recommendations!) and putting me in the position of having a half of an employee. This may sound conceited coming from an IT guy but this kind of work is not about the money. It's about (or was about) developing a talent for relating the skills of a computer to the skills needed for a task and making an exemplary solution. It is not just about making code that works. Hopefully the OP has a major that DOES appeal to her and will encourage her to do the best job possible when employed in it. From what she has stated I'll be glad when "her code" gets her a passing grade and she departs from this department and goes back to her more-favored field of study. The IT world does not need malicious hackers nor dis-interested money-seeking desk jockeys.

Link to comment
Share on other sites

I totally agree with Jacques1 response(s) on this topic. To be teaching the future coders of the world old coding styles/methods is just wrong. Furthermore as Jacques says sending future coders out into the world with these flimsy skills is no different than sending untrained unsilled graduates out there to do any other job that they are not fully qualified for. A programmer has to have the mindset and the skillset that IS REQUIRED to do a good job, not an outdated skillset and a lackadaisical attitude toward producing good products.

 

As a former pro who had to hire coding talent I was fooled a couple of times by people who did not qualify for this kind of work but did a great job of scamming me (and their previous employers who gave them glowing recommendations!) and putting me in the position of having a half of an employee. This may sound conceited coming from an IT guy but this kind of work is not about the money. It's about (or was about) developing a talent for relating the skills of a computer to the skills needed for a task and making an exemplary solution. It is not just about making code that works. Hopefully the OP has a major that DOES appeal to her and will encourage her to do the best job possible when employed in it. From what she has stated I'll be glad when "her code" gets her a passing grade and she departs from this department and goes back to her more-favored field of study. The IT world does not need malicious hackers nor dis-interested money-seeking desk jockeys.

 

Yes, Jessica might not have formatted her existing script correctly for this forum, but her questions were not bad.  And yes, her professor might be at fault for teaching obsolete techniques, but that is not her fault.

 

She never said that she wanted to fake herself as a programmer, and in fact said she didn't want to become one.  What is wrong with trying to expand ones horizon by becoming familiarl with programming, and maybe she will become one (and I hope a good one!) if we support her and get off her case.

 

I have a 13 year old daughter who shows interest, and I am as passionate as Jacques1 is about security that we support young ladies in this industry.

Link to comment
Share on other sites

Who says I don't give a "shit" about the subject? I do. But it doesn't mean I have total interest in pursuing a career in programming (I honestly do not know what I want to do). I am taking the class because I need to fulfill a requirement. I am majoring in information science. That school is merging with the computer science department to form a new school.

 

I still don't understand what the issue is with my professor teaching PHP6. Is it really as outdated as PHP7??

 

And just because I am now learning "obsolete code" doesn't mean I would use it in a future job. How do you know I won't learn proper coding? I have no intention of scamming people let alone hacking.

 

All I am doing right now is trying to complete an assignment!

  • Like 2
Link to comment
Share on other sites

You are not learning “PHP6”. There's no such thing. This is 90s technology abused to the point that the application could do anything: crash, spill out sensitive data, compromise the whole system. It's literally malware.

 

Just try entering the name “O'Reilly”.

 

You have not completed the task. You haven't even developed a basic understanding of technology. If you think the code will be accepted, it just demonstrates how worthless this kind of education is.

  • Like 1
Link to comment
Share on other sites

@JessicaC - It sounds like you solved your initial question. Is that correct?

 

 

I still don't understand what the issue is with my professor teaching PHP6. Is it really as outdated as PHP7??

 

For what it's worth, PHP 6 was in development but was scrapped. The developers ended up going in a different direction. Since articles and books were being written for PHP 6, the developers of PHP decided to name the next release PHP 7. More information can be found here:

https://en.wikipedia.org/wiki/PHP#PHP_6_and_Unicode

 

I haven't spent any time with PHP 6, so I don't know off hand the differences between PHP 6 and PHP 7. But if you are interested, I'm sure you could find the information somewhere.  :happy-04:

Link to comment
Share on other sites

To be teaching the future coders of the world old coding styles/methods is just wrong.

 

Do you think there's any value in knowing the old coding style? There's going to be a lot of broken scripts in the very near future, once PHP 7+ is the only option. Someone needs to know how those old scripts used to work and be able to replace the mysql_* function calls.

 

I'm having difficulties putting myself in the shoes of a newbie for this particular problem.  :shrug:

Link to comment
Share on other sites

I do believe there will be plenty of 'old coders' out there to help those without the foresight to have kept up to date.  There is no need to 'train' the future generation how to create outdated code.  Let's face it - how many of us had Latin available to us as an option in high school?  I know my father did but it was unheard of when I went to school.

 

Learn the current stuff.  The other can be easily handled should the need arise.

Link to comment
Share on other sites

Who said anything about PHP 7 anyway? PDO was introduced in PHP 5.1 back in 2005. The mysql_real_escape_string() function even existed in PHP 4!

 

What do you think she should learn, cyberRobot? Rasmus Lerdorf's PHP/FI from 1995? I guess somebody is still using that, and maybe they need help converting it. A future-proof job, eh?

 

On a more serious note: I don't know about you, but when I started programming, I absolutely hated those people who called me a “newbie” and patted me on the back rather than actually teaching me something. It's condescending bullshit.

Edited by Jacques1
Link to comment
Share on other sites

The point is nobody told her to use PHP 7. benanamen recommended PDO, and now you're busy sabotaging that and telling her to go back to ext/mysql. Because that's “future-proof”.

 

I'm not sure where you got that from. I have no problem with suggesting PDO. For those unaware that the mysql_* functions are going away, it's good to let them know. Then it's up to them to decide on how to proceed.

 

With that said, if I was taking a collage course and my project said to use the old mysql_* functions to solve a given problem, I would use the outdated method. I may approach the professor about the outdated method. But I wouldn't jeopardize my grade because others were telling me the code is garbage.

Link to comment
Share on other sites

What requirements said anything about the mysql_* functions? Where is that other than in your head?

 

I'm baffled that somebody would tell a student not to learn and not to think for herself as it might “jeopardize her grade”. Is that how your education worked?

 

Where I come from, learning is the whole point of going to university, and professors appreciate students who do more than required. Thinking for yourself is actually encouraged and leads to better grades if anything. But maybe things work differently in Trumpland. ;)

Link to comment
Share on other sites

What requirements said anything about the mysql_* functions? Where is that other than in your head?

 

In Reply #10, Jessica mentioned that she was following "certain instructions." Of course, she didn't say those instructions told her to use specific functions. Maybe she's allowed to solve the problem however she wants. Or maybe she's supposed to solve in a certain method. I don't know.

 

 

I'm baffled that somebody would tell a student not to learn and not to think for herself as it might “jeopardize her grade”. Is that how your education worked?

 

At times, yes. But most of my instructors were just fine.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.