Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Obtaining Info From Database Table


How do you obtain fields from a table and assign each field to a variable to be used as needed.
An example:

Say i had:

table name : user

Field 1 : User name
Field 2: Password

then i wanted:

$username = field 1
$password = field 2.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Getting Mysql Table Info?
Suppose I have a table with name 'tablename' in my database.

If I have no idea what are the contents of this table, is it still possible to retrieve the structural info in this table, like the field names and sizes?

Getting Table Meta Info
I can query a table in a MySQL database for meta info using

SHOW TABLE STATUS LIKE 'images'

That gives me a single row result of info (Name, Type, Row_format, Rows,
Avg_row_length, etc. But how do get one field from that record in PHP?
Here's what I have so far:

$sqlstatement = 'SHOW TABLE STATUS LIKE 'images''

$result = mysql_query($sqlstatement) or die("Query failed : " .
mysql_error());

I don't know how to reference a field from $result.

Submitting Info To Table?
Can anyone help me to create a simle "one field" form to submit keywords to the following table? It's a simple table, just has an ID, Keyword and Date. Sorry I do not know anything about mySQL or how to submit info to them! PHP Code:

How To Choose Info From One Table To Another
I have a table called "products" in this table is a row for "color" the color row holds the id of a certain color in the "Colors" table. How would i go about using the sku from the products table to search the colors table for the corresponding colors name?

Using Foreach To Make A Table From Db Info
what im trying to do is make a table of all the info from a database that i have im trying to use the foreach function, im not sure if this will work or the most efficent way.

What Is The Best Way To Display Specific Info From A Table?
I am hosting a youth sport site and I want to display schedules by select teams.

I thought that I would want a drop down menu to select one of our 35 divisions, then a secondary search by team of that previously selected division menu.

My schedule is in a table with the fields:
* division
* date
* time
* home_team
* h_score
* visiting_team
* v_score
* field

I see problems, since secondary drop down menu would have to search two different fields.  Any suggestions and hint to where I would even start?

Recall Database Info
Hi, I want to create a page where users can put in certain information like you normialy would in a form but when they click submit another page will load that will look like the original form the signed up with and everything they filed in that time will be there and they can make changes to that and then click submit and the changes are made to databse automaticialy.

How To Send Info To Database
im wondering how to submit info into a database.

i know the code goes something lie
$sql = "UPDATE <tablename> set $var = "var"

but i know that is wrong
and i want to put it in form so on submit it posts it in the database.

Info Deleted Itself From Database?
I got some info (news system) in a SQL database but after some days it deletes by itself it happened to me once but i thought i didnt remembered that i deleted it but today it happened again...it deleted by itself! lol

I have other tables in the same database so its a table problem...

How can i fix this? Did i miss something at the table configuration?

Get And Insert Info Into Database
I have one table (form) that has multiple fields. Here are few fields we need to know: ID, NAME, CITY, STATE, PROFESSION, x, y, z (x, y, z means more than 50 fields that give me more information about each name).

The ID and NAME are unique and they don't change (each name has it's own ID). A NAME and its ID can be in any CITY, STATE or PROFESSION but this is fixed. That means if ID# 123 for Mr JOHN is Austin, TX, that will stay in Austin, TX for ever. I have more than 5000 NAME and it's ID, 9 professions, all US States and all Cities in my database.

Here is what I need to do:
I want to have a form on my site that my visitor finds his name first and then enters more information about him/her that will complete my database fields of x,y,z. What I'm thinking to do is to create a drop down list that the visitor first selects the profession. Based on the profession the second list shows the states that has that profession. Then by selecting the state, all the available cities will show up in the third list, and by selecting the city all the names related to that profession in that city, state will show up and he can select the name from the forth list. Then he enters other required information about him that will be send and saved in the database.

Here is what I have done and I know to do so far:
I have created the database with all the information in one table. I also know how to send data to database to be saved. But my problem at this point is how to create this list selection that narrows the search to find the right person.

Retrieving Info From A Database
I would like the code below to fetch and display in an html table the Ad_Id, Date, and Type_Job fields from the 1st 10 rows of a table called employment. I'd like the results to be sorted first by date and then by the Ad_Id #. I have replaced my username and password with "user" and "password". Currently, the script returns the error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

Also, the script is ignoring the css info that I have supplied. Code:

Populating A Form Wth Database Info
I've coded a piece of code which populates a form with data read from the database:

$connection=mysql_connec ("localhost", "f2821842", "f2821842");
$result=mysql_select_db("QUERIES");
$query=mysql_query("Select * from Emp_Details where emp_num = '$employnum'");
while($row=mysql_fetch_array($query))
{$empname=$row['emp_name'];}

<form name="webregform" action="webadmin2.php" method="post">
<input name="requiredname" type="text" size="30" value="<?php echo "$empname"; ?>">
</form>

When I echo the $requiredname, I get spaces and no data, and I know that $empname is not a space-it does read a value in a database. 1. How can I get $requiredname to print a value?

Ordering Info Returned From Database
I have a PHP page on my site which pulls back info from my MySQL database and displays it in a table under appropriate headings. Is there code that I could add to these headings so that

a) the same page could be redisplayed with the information sorted by the third column instead of the first
b) information in the columns could be displayed in reverse order (maybe Z to A or highest figure to lowest figure)

Session Variable Info To Database
I have a 2 page form. The first page page of the form POSTS to the 2nd page which, after being filled out, should send all the information (from pages 1 and 2) to the database. I have created a session variable and have placed it at the top of the 2nd page. For brevity´s sake I have placed only one of the variables in this example:

<?php
session_start();
$_SESSION["sessanimals"] = $_POST["animals"];
?>

After filling out the remaining variables on page 2, I want all the information (the info from page 1 brought over in the session variable and the info from page 2) sent to the database. I tried creating an INSERT RECORD on page 2 but only the variables on page 2 are subsequently sent upon submission. How do I get all the info into my database??

Here are a list of my questions:

1. Is there any way of creating one session variable for all my page 1 form variables (I have 20+ variables)?
2. is there a way to denote ALL the variables in = $_POST[]; or do they have to be listed separately?
3. How do I post all the data from page 1 and 2 into my database at once?

Insert Form Info Into Database
i am trying to enter info from a form into a mysql database. when i submit the form, a new row is created, but the information isn't contained in it? any thoughts? PHP Code:

Filling Form With Database Info
I have a table with 5 fields for a tour business activity list
: (1) id -table key (2) name (3)description (4)picture -text link not
binary(5) country. I would like to create a form that takes all the
activitys an puts it neatly down on site in checkboxes so user can
select activtys.this will be linked to form mail.i would like the
activitys to be seperated by the country they r in?

Update Database Info Using Forms
i have a page uses select and cases. i already have setup and working, auth/login to the page, create a new row in the table. i am now trying to have the user alter the information that the just put into the table.

this is the code where i have setup to modify the info, $id is passed over. this puts the correct information into the form field. when i hit submit, the information, $name, $content, $id are not passed over. echo-ing results blank. PHP Code:

Hiding Database Connection Info
In a php script, I have to connect to a remote mysql database. I'm a bit
worried that some user might be bale to retrieve the source of the page and
see the user name and password to connect to the db.

Is this resonable? What's the best way to avoid it?

User Info Not Posting To Database
I am trying to figure out why my script isn't updating the information of the user names stored in the database. Can anyone give me the solution?
Below is the script: Code:

How To Obscure Database Info In PHP Pages
I'm moving from Cold Fusion to PHP and I have a question that none of
the books I have answers adequately:
In Cold Fusion, database connection parameters like the table, username
and password are configured on the server. Since they are at the
backend, nothing is exposed on the page except the queries themselves.
In PHP, from what I see, the database info is on the page. Is this not a
security risk? How can one be sure that this info is not on the page
sent to the user?

What Is Indexing In Mysql And How It Will Be Useful And How We Can Retrieve Database Content Easily From A Database Table Containing About 5lakhs Datas
I need to select data from a database table containing huge amount of
data. Now I am storing data using one primary key and I am just using
simple select statement, and this process gives me the output but it is
taking long to execute the query. As much I had heared I want to use
some indexing or cluster indexing which might help me but I am not so
familiar with these things.

Validating Form Info Before Inserting It Into Database
I have been trying to create a PHP application where you can add customer contacts to a MySQL database.

Now, my problem began when I created a form where the user can add in a customer's name and info to the database. In an effort to alert the user that they may be adding a customer that is already setup in the database, knowing that some of the customers may have the same names, e.g. there is more than one Bobby Ray Brown, I decided to add a script that queries the "customers" table in the database and searches for all results that match the input from the user. Code:

Entering/checking Info Into Mysql Database
I have set up a client database where one can view, add, edit and delete entries. I ran into a problem setting up the add page. On this page i have set up forms to add info into the DB, and it works fine, but i dont want duplicate clients. Is there a way to set it up so that when you submit the form with the info it checks for duplicates and if there is one returns "sorry this record exists?"

Retrieve An Image In Folder From Info Out Of Database
i am having problems displaying an image once i have uploaded
it. i upload it to a folder and store its name in a database. below is
the code to display the image. I have figured out the the code is not
grabbing the name from the database but i can not figure out why. can
anyone help?

//Retrieves data from MySQL
$data = mysql_query("SELECT IMAGE_NAME FROM item") or
die(mysql_error());

//Puts it into an array
while($info = mysql_fetch_array( $data ))
{
//Outputs the image and other data
Echo "<img src=http://www.abcxyz.com/pics/".$info['photo'] ."<br>";
}

Sends SMTP Mail From Database Info
I've got this script that I want to use to send SMTP mail from a form that allows the user to select recipients from a dropdown list that is created using database info and send a message.  Two of the selections in the dropdown list are groups.  My script works fine when the user selects only one recipient.  I run into trouble when the user selects one of the two groups.

The message ends up getting sent numerous times to the people in the group. I received the message 9 times.  I think the script is looping more times than it should.  Does this make sense so far?  Here's the script that receives the form data and connects to the DB to get the recipient email addresses and then sends the message: Code:

Retrieving Database Info Based On User
I'm still quite new to php and mysql but I have been unable to figure this out.  I'm attempting to display a specific row and column from a mysql database based on the user.

$result = mysql_query("SELECT fbleague FROM users WHERE username = $_SESSION[username]");
fbleague is the column
users is the table
username is the primary key column
$_SESSION[username] is the username variable

Then later I try to display it with

echo "You are in league $result ";

I know $_SESSION[username] is set correctly because I can display that with no problems. 

Uploading Info From A Text File Into A MySQL Database
what would the PHP and SQL code be to say basically: make a new row and put this in the field, what comes after each comma goes in a new field, and each new line should be a new row.

I have a huge text file that i don't have a way to upload directly into a MySQL database because my webhost isn't allowing it for some reason.

Upload & Query MySQL Info Database With Image Files
I want a database I can enter information and upload a photo from a web form. Then I want to query that database for the text info with its related photo and display it (formatted) in a browser (html).

Summary:

1. upload photo's and text information to database with my add article form.
2. Query the database and page the results with the text and related photo.

It comes in three parts:

1. add_article.php [Text / Photo Upload Form]
2. insert_article.php [Inserts into database]
3. articles.php [View Output]

Here is what I have this far:

Obtaining The URL
$_SERVER["SERVER_NAME"] and $_SERVER["HTTP_HOST"] are good and all, but none
of them are reliable.

Eg: Not all subdomains will have a vhost entry for them in Apache, or the
Host: header is not filled in.

So are there any other methods of determining the URL of the script itself?

Obtaining SQL Fieldnames
I was wondering if there was an easy way using (my)sql to obtain the database fieldnames. I have created a form to review survey results and would rather have it pull the field names from the database rather than making them static.

Obtaining O.S Type
Is there a way to obtain what operating system a user is using when they register to my site without them giving the info which would mean they could lie. Similar to how you get their ip but with operating systems?

The reason why is cos multiple accounts i want to allow as long as the two accounts are not on the same OS which adds extra proof they they may be "brothers and sisters" etc with two computers.

If they cheat for example and say "hes my brother he is on a different pc in a different room.." i want to find a way to get enough info to prove it.. cos my fear is banning people who ain't lying.. cos there are bound to be instances... i just want to keep it as fair as possible.

PHP Obtaining Emails - New Server
I am keeping my existing web host, but have changed email hosts for my domain name - ALL PHP / web scripts etc remain on my existing host....

START CODE :-
=============================
$server = "mail.DOMAIN.com";
$server = "{".$server.":143/notls"."}"."INBOX";
echo "<PRE>Using NEW password server / Userid. - JAN 18th 2007";

$user = "mail";
$password = "password";

$subjectMatch = "Test"; // subject of the email messages you want processed
$delete = "N"; // if delete is Y then processed mail will be deleted
$maxdelete="Y";

#$host = "{".$server.":143"."}"."INBOX";
$msgStream = imap_open($server, $user, $password);
=============================
END CODE

I'm using the above code...

It HAS been working on my existing host (checking my POP account.. )

Due to some issues, I am changing hosts for emails, but keeping all my
web / HTTP services on my existing host...

QUESTION :- I'll assume that when the above is run, it searches for
the Email/POP DNS settings & not http (EG http://mail.DOMAIN.com )

:- my new POP account is represented by "mail" & "password" represents
my actual password (both are correct in my script)...

QUESTION :-

Is there any code I can add to the script, to advise it has TRIED to
connect, but something (error) has occurred.
(or just connected sucessfully- But no messages received...)
& possibly the DNS / IP address of the host it has tried to connect to?

PS,

I opened my new email service 1-2 days ago (my time), but advised my
current website/host to change the DNS settings etc - only about 4-5
hours ago....

QUESTION :- I'll assume as the WWW DNS for email points to my web host
- The web-host DNS will re-direct emails to the new-host - in the
mean-time (till DNS propegation occurs for all emails... )

Obtaining The Size Of A File
I need to obtain the filesize of a file thats not on the same server. As
filesize() need a realpath and not a url how else can this be done?

Obtaining Email Address.
I have been a victim of a website ( coded using php ) managing to obtain my
email address just by visiting the website. I know get loads of rubbish via
that email account.

How have they managed to do this?

The reason i ask is so i can stop it. Oh and also being into php a bit i
would also like to try it out :) just for fun.

Obtaining Page Title
I was wondering if someone could tell me the easiest way to obtaining the page title of a specific url? I've tried to use fopen and those functions but I got the below error.

QuoteWarning: fopen() [function.fopen]: URL file-access is disabled in the server configuration in /home/web/ute.php on line 2

Obtaining More Information On Mysql Querys
I have a mysql database with two keys, one is primary and the other unique.
I have a script to inster records in this database.If the user insert a repeated field I will get an error.But it doesn't matter in wich column the repeatition was generated I always get the errno: 1062 (by the way, where can I find a list of errnos).
How can I know which columnd generated the error ? It is on english on the string returned by mysql_error, is there any other way to get it ? (or would I have to parse and work with that string?)


Obtaining File Mime-type
Does php have a way of obtaining a file mime type other than for images? I'e, a user may upload an image or a short movie clip, i need to know how to deal with it without having to rely on the file extensions. Script may be installed on a windows machine so file() is out of the question unless windows as an alternative to file().

Form Obtaining Values For Process
I have a form which has a while loop inside to echo a table. But not only that i have a submit button and a check box which I want to have the value of the row's ID so that if the submit button is pressed it will delete the adjacent row.. but just curious if this following idea is going to work : Code:

Obtaining The Whole Query String From $_GET
I'm doing a complex search engine script for one of my clients.

Instead of having clumbersome code checking to see if $_GET variables are set and then setting them to pass onto the next page, do you know if there is a way of getting the WHOLE query string from the URL after ? in PHP?

Putting Info Into A DB / Passing Info Between Pages
I have run into an issue...I have posted previously, but my scenario has changed.

Here is the situation...

If a user clicks on a link ('abc123' for example) I want to insert into my database some predefined information about 'abc123' - I have assigned a value that is echoed in future pages for 'abc123'.

So, what I need is some mechanism to, when a user clicks 'abc123', have a pre-defined username and password be entered into the database. I need this so future pages can utilize the session values.

Content Of Database Table Twice?
Why does this code repeat the content of the database table? It connects O.K. but display table contents twice (I only need it once) Code:

Table Name In Ms Access Database
I'd like to know how can i get and store the table names of an ms access database. I use odbc_result_all but i don't know how to exctract and store information about the table name.

How To Search More Than One Table In A Database
Say I have a user input a search string and they click search.  What would my mySQL string look like if i wanted it to search TABLE:'set_01' and TABLE:'set_02' at the same time for the same information?

Delete A Row From A Database Table
I'm trying to delete a row from a database table.  I've made a connection yet it's not working.  Is there something wrong with the following code?

mysql_query("DELETE * from  `contactinfo` WHERE Submission_Number = 1 ");

Changing A Database Table
Is it possible to change a table in a database without just dropping it and recreating it.  As example, I have a photo column which stores an URL, but it seems to only be accepting about 25 characters.  Is there a way I can update the table without starting it over?  Also, when I made the photo column I think I put, photo varchar(25), is there any reason I don't want to make it like varchar(1000), although I know that varchar only accepts 255, so what do I change varchar to?

Selecting Whole Database VS One Table
In querying a regular DB you use the following code: $query = "SELECT * FROM table_name";

Well I want to be able to do something like this: $query = "SELECT * FROM database_name";

Here is my reasoning:

I have built and intranet for the company I work for. I have imported all of the data requested from an Excel Spreadsheet into the corresponding SQL tables. Now for the page I am wanting to pull off my weird select db_name code works like this:

I want to be able to go there and display the Table names within that DB and when a user clicks on one of the links it will reload the page displaying the results for the corresponding Table. Make sense?

How Does One Retrieve All Table Names From A Database...
I'm trying, through an SQL statement, to retrieve table names and column names from a selected database.

Something like...

**PSUEDO CODE**

GET all_table_names FROM $db

->returns(table1, table2, table3, table4)

Import CSV File Into Database Table
Are there any programs like phpmyadmin, that allow you to import CSV files without first converting them into mysql statements? mysql front?

I've created the table and fields, and it should be easy enough to import the data into its respective columns.

Script Not Inserting To Database Table
I submit the form to insert the data into the table, when I submit the form for this script to process, The "if" statement is true because the "echo" statement in the else says so, but the else is what the script is doing. Can't figure out why. PHP Code:


Copyright © 2005-08 www.BigResource.com, All rights reserved