Insert and select from MySQL database - php

Every user that signs up for the site is given a user id (stored in the database as User_ID), I am using userCake for the login/user management system just to clarify.
I am quite new to MySQL and PHP. I am trying to create a way so that a user can input a link into a form (I have the form created) and then it saves that to the database (new table?). How would I go about;
Creating the table structure for that.?
Posting the URL to the database.?
Retrieving all of the links associated with the User ID.?
Displaying all the users links in a list (a list just for testing)?
I have looked around for some time but can't seem to find anything that helps. All help is greatly appreciated.

i think maybe http://www.sitepoint.com/getting-started-mysql/
other resources are available, I tried "beginning database driven php website" in fav search engine and there is tons and tons of the stuff, i dont think the actual teaching etc can be done in a single post on SO and maybe you should learn to create tables, and query them with a query tool. once you got that you can then do your first php hello world app. create a hello world form then finally hook up database and start then looking at DB security etc.

Related

Best way to get data from non-admins internal to an organization in Wordpress

Here's the scenario:
I want to display a music playlist for each DJ at a radio station on my Wordpress site, but I don't want to have to enter that data in (Each song, artist, album, etc), in a specific custom post type or something like that.
I want each DJ to have access to a form where they can enter the playlist data in, and I can use that data. I was thinking of making a little webpage form that they can access, and then I query the database to get all that stuff, but I imagine that maybe there is an easier way using Wordpress.
The thing is, I don't want to give each DJ admin access to make posts with those custom fields filled in, so I'm not sure if there's a way to do that.
Maybe a page on the website that is password protected to fill out the form, and then I can use that data in a different page on the site? (Password protected so I'm only receiving data from actual DJs, not random people or bots.)
Sorry if this is an ignorant question, or if I'm unclear.
I searched a little bit, and couldn't find much.
Thanks in advance for ideas and insight!
You need to decide your method for doing this and try it out, when you run into a problem then you post here. It sounds like you know what you need. You're looking for a password protected form (which will check against a database) and pages based on a query to the database. This can be done in PHP or you might be able to find a Wordpress plugin to help you out.
Maybe start by making the PHP form. Then you could add the password protection. After you have that working you could make the PHP page that would query the information submitted. Take it one step at a time. It'll be much easier for people to help you if you're troubleshooting a specific issue rather than trying to figure out the logistics of how the whole system will work.

php mysql one to many relationship or something else?

I am trying to figure out what to do from here. I am using mysql for my database.
In my form from mysql I wish to have the possibility for people to upload from 1 to many images that can be queried along with the data submitted in the form. I am not asking for someone to write me the code, but to point me in the right direction of what type of solution I can use or what I can read on to learn to get this done.
User example here:
1. a registered user is filling out a form for example a car for sale ad.
2. user wishes to upload images relating to that car sale ad.
3.if the user fills out the car for sale form and clicks submit/next.How to display the form the user just clicked submit in the next page to appear,so the user can add images there/here?
I hope someone can point me in the right direction or can give me their input on what else I can read on to do this.
Thank you in advance
Personally when I start having to get into complex HABTM relationships and the what I want to use an ORM. I personally use CakePHP's. It has a very robust relational mapping system (HasMany, HasOne, BelongsTo, HasAndBelongsToMany) which is a bit of a pain to learn to do in SQL your self.
If you don't have access to a server with the right php modules 3.0 can be a pain to install, but 2.0 has a really nice RubyOnRails style ActiveRecord system too.

Is there a way I can change where a PHP page selects from a MYSQL database by using a form?

I have a website and I want to make it easier for someone to change certain information being shown without them having to edit the HTML/PHP and using FTP.
At the moment I have this information in a php file which is included in the MYSQL query.
It would be a lot easier if this was done using a form, say a text field where a person can type the table name and it updates on the main page and starts displaying that table instead.
Sorry if I haven't explained this well. :(
I have a good news for you.
Every php/mysql-driven site in the world is made this exact way - to edit site contents using HTML form.
Even first PHP version name was PHP/FI, stands for Form Interpreter.
Even better, a site user doesn't have to deal with mysql - it's all being done in PHP. No need to type table names into form field - all table names already written in PHP code.
Usual PHP application being connected to just one mysql database - so, no need to choose.
As for the tables, it's being done this way: a user selects some human-readable matter, like "Latest news" and being redirected to the PHP script called, say, news.php. this script runs a query for the news table in the database and outputs some HTML formatted news highlights!
Even more, you don't even need to program! There are plenty of ready-made programs, such as Wordpress
store what you want to be editable in a mysql text field.
remove tags you dont want him to see
in the form echo the editable information in a textarea
have him edit
add tags
update the mysql
note depending on the users knowledge depends on how many tags you would like to remove/add. the less per a field the easier.
on more complicated things i like to have the person log in. if he has permission then all the editable fields have an edit button. if he clicks it it goes to a page with a form that he can use to edit that 1 field

php report button

I am working on a search script and on each search result I want a report link button. I am not sure how to make one. I have looked on google for answers but cannot come up with anything. Can anyone give me an idea of what to do? or does anyone know where there is an example of this? I plan on using the link id and making a new table on mysql to send reports to. I am just looking for a basic button to send reports to mysql I am just not sure what would be the best way to do it. I have the data for the link id's I just need to be able to report it to a new table I am assuming. Any suggestions or examples are very appreciated. Thanks.
Chris,
First you will want to create that new table in your database to capture this information. Lets assume to you will have the following fields (very basic, you may want to add more): ReportId, LinkId, DateReported. ReportId is our primary key, LinkId is the ID you reference in your question and the DateReported is the server time we logged the transaction.
With this table created you are going to want to create a new php page, lets call it report-link.php. You are going to want to make this page accept a querystring variable called linkid (accessible in the $_GET[] collection). In the code of this page you will want to write a SQL query that inserts the value of the linkid parameter into the new link report table in the database (along with the date()).
On your search page you will be able to have users report an entry by clicking a link with the href of /path/to/report-link.php?linkid=<?php echo $link_id; ?>
Please note this example is very simplistic in nature, and offers no security for spamming, pleasant end user experience after they click the link, but this is the process you will want to follow in setting this feature up. After you have it working you can spruce up the experience for your users.

Why is the record not showing up in the DB

i am trying to create a custom solution for a client using their prior system. The client is using Miva which is a user friendly CMS type system to manage their store. The problem is prior to yesterday everytime i entered a record in the miva site it would show up in PHPmyadmin and I could query it and use the Custom solution. FOr some reason now when I create products in the admin I get no records in the DB.
The product is clearly there
but not stored in the db, any ideas on how and where is stored
Logic dictates that either:
Your query was wrong
You're querying the wrong database
The website does not relate to the database you're querying
You're asleep and none of this is real.
Are you able to do a wildcard search for something specific like a piece of text or file location? If no errors are being thrown when you're adding items then it should be there.

Categories