Checking For Existing Data In Mysql Table..
I'm having a bit of a problem on a project I'm working on.. Here's the deal: I want to log search terms. Easy enough, right? Well, to make things interesting, I want to *NOT* log terms less than 3 chars long, *AND* if the term's already in the database, I don't want to add the term again, I just want to update the 'count' field to reflect that there was a 'hit' to the word.
Here's how I coded it note: it doesn't work because I suck and I have no real idea how to do what I'm trying to do): This is the actual "recording" code I came up with:
if(strlen($term)>3){
$record_term = sql_query("insert into $terms(ID, Term, count) values ('', '$term','')");
Now, this is the code I've come up for for the adding to the count part.. (and I know it's wrong, if someone can fix that too, I'd appreciate it):
$query = mysql_query("SELECT term, count FROM Term WHERE term like $term;");
$entry = @mysql_fetch_array($query);
$new_count = $entry["count"]+1;
$query = mysql_query("UPDATE links SET count = $new_count, WHERE Term like $term;");
mysql_close($db);
-----------------------------------------
So how do I combine these two actions to do what I want it to do? and what's wrong with the second query?
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Table And PHP Scripts For Existing Data
I've been using MySQL for several months and enjoyed great success when installing other people's scripts to databses I make using phpMyAdmin. My challenge is developing from scratch the scripts, for which I've got good resources, manuals, and much time into practice and test. My question is three-fold, as I have 14,000 records of Security Dealers that I want to install in MySQL at www.securitydealers.com 1) what should my table SQL statement look like for data (sample) as follows; "John Doe","Managing Partner","BM SECURITIES LTD.","P.O. Box 201","Grand Cayman","Cayman Islands,"","","345--555-5999", 2) once the table is created inside my database on MySQL, how do I load the data in? 3) what is the best choice of variables, operators and arrays for my PHP script, to display only records from a certain city, country, company name or Dealer name?
Checking For Existing Files
If I include a file using include() or require(), is there a method of checking for the existance of the file before including it, therefore skipping the dreaded error message; or alternatively, supressing the error completely?
Checking Values In A Table (MySQL)
I've got a tables with two variables, "one" and "two". I want the value of "two" when "one" equals $blaa It is easy, like this PHP Code:
Checking A MySQL Table Exists
Is there any particular way to check if a MySQL table exists? At the moment, I'm running a SELECT query on the table, and then seeing if mysql_num_rows returns a result or not, assuming the table doesn't exist if no result index exists.
Using PHP To Sort Data In MySQL Table 1 By Values In Table 2
I have a MySQL database with 2 tables in it. products and prices.. Products has a field in it called 'prodno'. Prices has a field in it called 'prodid'. There is one of each item in products and each product has it's own unique 'prodno' There are multiple instances of each product's pricing in prices.. One for each price.. So if a product had multiple prices depending on quantity it would have an entry for each price.. Example: id = 1 prodid = 7001 qty = 300 price = 12.5 id = 2 prodid = 7001 qty = 400 price = 15.5 I was wondering if I could query the database getting info from the products table but sort it according to the prices in the prices table. Kinda like doing a "SELECT * FROM products" ordering it by the lowest price value from each item.. This is all very confusing to me, and I'm the one writing it. Let's try one last time.. Query the database selecting * from products (I plan on using all the info in products) and ordering them by the lowest price for each item in the prices table. I've tried sorting the results of just a basic SELECT * FROM products using Javascript and PHP but with pagination in the results it makes it a bit hard.
Q. Data Not Posting Mysql Table
I am trying to post from a form to table using the code below from file2.php and having two problems: 1. The data is not being posted to the table 2. After submit is pressed the following message comes up: "The page cannot be displayed" - The browser can't find the file, because it is looking for http://file2.php instead of http://teachercards.org//file2.php
Adding Data To Mysql Table
I have the following script which is supposed to process a complete order for a serial number from a POST. It has so far been working okay. It processes the order successfully, then sends an email to me and to the user, but it is failing at the point where it has to do the insert of the data into the CustomersTable. PHP Code:
Replace A Cell In A Table With New Data In MySQL?
how to replace a cell in a table with new data in MySQL? -OR- A good site that will explain it step by step and not just list functions? For example, I have a change username page, Need it to change the username field in the users function as a result.
PHP Form Overwrites MySQL Table Data
I have a PHP form sending data to a MySQL table, and I am wondering if I can add some sort of code to the PHP page that will make the form data overwrite any potentially old data already in the table.
Retrieve Data From Mysql Table And Put A Hyperlink For Download
I have created a database and a table and have stored the information in mysql table. Now my question is how do I retrieve that data from the my sql table and have a php page that when someone goes to say:download.php, he/she will be able to download the data from my mysql table? Also what if I have multiple tables in mysql that I want to be able to download from the php file?
Importing A Flat Pipe Delimited File Into A MySQL Data Table
I have done this in perl but eeew I don't want to use perl anymore. I want to be able to take a flat file that looks like this: mbriones@...|Marian|Briones bobsmith@...|Bob|Smith janedoe@...|Jane|Doe (etc) The table has more than 3 fields, so I'd want to process the flat file and then do an INSERT into mailinglist SET field=$value for each line. Does someone have a nice way for me to do this? The flat file will be uploaded to the server via a form (copy) and then be processed.
MySQL Existing Connection?
is there a way to check with PHP whether a mySQL connection already exist between a script and the database. In that case it can be decided to connect or leave things as is.
Automatically Add Unique Id To Existing Mysql Db
I am working on a MySQL db (+/- 18000 items) which was converted from FoxPro. But is doesn't have a unique id-field and I was wondering how to add such a field and the incremented numbers in it automatically, without having to enter 18000 unique numbers.
Checking $_POST Against Records In Table
I have a table containg name, description, url which contains many records When I submit a new form, I want it to check the url fields in the table and check it against what I have posted. Therefore something like $check_table = function here to get all urls if($_POST['url'] == $check_table) { return false; } else { return true} However, how do I get all the urls and get it to check each one?
Checking Whole Table With Strpos Code
I have a problem now to check the whole table with this code... can someone please help me? $q6=mysql_query('SELECT * FROM banlinktable'); $o6=mysql_fetch_object($q6); $banurl=$o6->url; if (strpos($newsubmitrul, $banurl) != FALSE) { exit; } With this code it will only check the last inserted row, how can I check the whole banlinktable for the url?
Migrating Existing Site From Older Version Of PHP & MySQL
There's an existing website (on a single box running Linux, Apache, PHP 4.1.2, MySQL 3.23.58) that I need to migrate over to another setup (2 boxes, the web/app server running MS 2003 Server, IIS6, PHP 5.2.4 and a DB box running on SuSE, MySQL 5.0.26). I've gotten the connection between the two new boxes to work, but a lot of the code from the original website doesn't seem to work. Is there anything obvious I should know about migrating code from the older setup to the newer one, which is running different versions of PHP and MySQL. I've attached 2 php files (both renamed to txt). When I bring up the dir_master.php file, the only thing that comes up is the Name, Affiliation, and Department headers from the contents.php file.... nothing gets displayed from the MySQL database. Like I said, I have been able to pull stuff out of the DB using code I wrote myself to test it, so I'm sure the PHP to MySQL connection is working. I think the issue might be with the PHP code and how the HTML is embedded in it, but like I said, this isn't my field of expertise. I'm hoping there's a quick syntax fix that I can use without having to completly rewrite everything.... especially since there's a number of PHP files that will need to get changed.
Error Checking For Unique Value In Database Table?
I am inserting data into user table which contains 5 fields, sounds simple enough normally but 2 of the fields are designated as UNIQUE. If someone does enter a value which already exists, how do I capture this specific error? Would it make more sense to actually run a SELECT query first and if that returned a result, then I use that for error checking and don't run insert until select returns nothing?
Checking Data
I'm making a php/MySQL newsletter system and I want to know how to, before inserting the data in the database, check if the e-mail is already stored... something like this: if email is already in the database returns "E-mail already in database!" else INSERT INTO `newsletter` VALUES ('email@host.com', 'name'); than returns "E-mail stored sucessfully. The e-mail validation is already done, but the system is accepting same e-mail multiple times.
Update Table While Insert Data To Another Table
it seem like mine coding din work. [php]<? include("checkin.html"); $conn=mysql_connect('localhost','root','') or die ('Could not connect to server'); $today = date("Y.m.d"); mysql_select_db('hms', $conn); $ok = mysql_query("INSERT INTO check_in(ID,room_no,datein)values ('$ID','$room','$today')", $conn); if( $ok ){ $up = mysql_query("UPDATE studtable SET checked = 'checkin' where [ID] = '%ID'); if(mysql_affected_rows( $up ) == 1) { echo'Checked IN!' }else { echo'No such student to check in' }} else { echo'Check In FAILED, please check again'}?>[php]
Checking For Data Before Doing Sql Insert
I have a html form (generated by PHP) that users can fill out and submit into a database. Everything works fine. However, I'd like to check to make sure that each field in the form actually contains data (no null/void fields) before doing the insert into the database. Any tips on how to do this?
Grab Content From HTML Table And Place Into MySQL Table?
I am in the process of helping a co-worker upgrade some of his old static html pages into dynamic MySQL driven pages. He currently has a lot of pages with huge tables displaying data. Does anyone know if there is a script or class that can convert a table to a .sql file for upload?
Table Background Color Based On Results From MySQL Table
I am trying to get the "Did User Agree" field on a database query to be colored Green for "Agreed" Red for "Disagreed" and Blue for "Agreed (2nd Time)" .. I have my PHP setup to do the query just fine as of right now with alternating column colors, just can't seem to get the colors to work as I am hoping for. Can anyone help me get the Agreed? table's background color to the colors above? Code:
Mysql Fetch_field Gets Table Alias, Not Real Table Name
After a SQL 'select .... from tablename alias' the mysql_fetch_field function returns a value $result=>table which will contain the alias, not the actual table name. Is there a way to get the actual table name ? I am running mysql 4.1 and php 4.4
Checking MySQL
How would I write a function that returns true if it finds a matching entry in the table. For example: In table tab, column col, there are multiple different entries but a matching entry may be about to be inserted, how can I check if it's already there? I also need it to return true or false for the purpose of an if statement. If it is already in the database it should return true. function check(){ } My code so far, yes pathetic.
Checking If Row Exists In MySql Database.
I have a form that sends data into a database with account name, password, etc. but If someone goes to create an account with the same name, it overrides the other entry. How do I get my php script to check if the account name already exists before it does the INSERT.
Checking Password Against Mysql Database
I am creating my own login and user authentication script for an intranet site, however i am having major trouble concerning password checking in the script. i have a MySQL database table holding the user detials, username, password etc. What i am trying to do is compare the user input password to the password held in the database table.
Dynamically Checking Mysql Row Type
Is it possible to check the types of columns in a mysql resultset so you don't need to know the type of data returned beforehand? I'd like to be able to do something like: if($coltype == "datetime") { // parse date }else if ($coltype == "varchar") { // parse string }
Table Data
I have a table on a php page with the cells containing database data from a mysqldatabase. what would be the easiest way to allow a user to change how the data is listed by clicking on the top of each data column? I have seen this feature on most applications but cant figure out how to doit??
Table Data Row
I have a script that pulls information from a table. This table contains foreign id keys for other tables. This code works just fine, but pulls id numbers. I would like to make a change to this file to convert the id numbers into their matching names. I have tried to use this type of code:
Data Into Table
I'm trying to get a neat and clean readout of all of the parasites that are in the MySQL table. Right now everything works except all of the info is all over the table and I can't seem to get the table to be clean and presentable for when I open my site to the public. Code:
Checking For Values In MySQL And Other Conditions Not Working?
I'm trying to redirect when testing for certain condidtions as shown below. When the conditions are ture, it redirects, but still goes ahead and processes the sql query. What am I doing wrong??? And then sometimes when the conditions are correct, it doens't redirect. It appears to be very inconsistent. //Check for repeat name $result = mysql_query("SELECT * FROM survey WHERE FirstName = '".$FirstName."' AND LastName = '".$LastName."' "); $num_rows = mysql_num_rows($result); if($num_rows > 0){header("location: ./oops.htm");}; //Check for repeat email $result = mysql_query("SELECT * FROM survey WHERE EmailAddress = '".$EmailAddress."' "); $num_rows = mysql_num_rows($result); if($num_rows > 0){header("location: ./oops.htm");}; //Check for existance of first name, last name, and email if(!$FirstName){header("location: ./oops.htm");}; if(!$LastName){header("location: ./oops.htm");}; if(!$EmailAddress){header("location: ./oops.htm");}; $newrecord = ("INSERT INTO survey (FirstName) values ($'Joe')"); $result=mysql_query($newrecord);
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?"
Help Listing Data In Php From My Table.
I have a result set that came from the query "SELECT * FROM characters" and I want it to list on my php page the results like: Name gender race Name gender race Name gender race How could I do that?
Inserting Data Into A Table
I would like to know if there is anything strange about the script below(I have only just started to learn php so there may well be!) Although it seems to work, occasionally it doesn't just insert a single row into the data base, instead 2 or 3 duplicate rows end up in the table. Could the explanation be that I tried this morning to create a table and forgot I already had one with this table name in the database. Would that have damaged the table in some way making it misbehave! I have commented out the bit about creating tables as I only want to insert data with this script at the moment. One other thought occurs to me, is the problem due to my host freedom to surf as its only a free host and I expect you get what you pay for(or don't pay for in this case). I have subscribed to a pay host http://www.phpwebhosting.com but I am unable to use the database that they have provided because they have informed me that I must use a telnet shell to log into my database and I have absolutly no idea what this is(is it in my Win98?) or do I need to go and get one. I am still waiting for this host to email me back with some help. If there is anyone out there who could tackle all or some of my problems I would be very grateful indeed! One last thought - I think there is something very strange going on as sometimes when I visit my database, there is less entries in this table than last time, some have been chucked away and my id entries are all out of order now, something like 1,2,3,11,5,7,12 - the last insert had id = 12 next to it and somehow another duplicate has sprung up id = 11???????? Whats going on please! <html> <head> <title> Connecting to Mysql server at ISP host</title> </head> <body> <?php $Host = "db.davegraham.f2s.com:3306";// Set the variables for the database access: $User = "p0c79"; $Password = "********"; $DBName = "p0c79"; $TableName = "Jokes2"; $link = @mysql_connect("$Host", "$User", "$Password"); if (!$link) { print("<P>Unable to connect to the " . "database server at this time.</P> "); //note how 2 strings have been concatonated exit(); } else { print("Your now connected to the Mysql server at the host ISP.<P> "); } if (! @mysql_select_db("$DBName") ) { print("<P>Unable to locate the $DBName database at this time.</P> "); exit(); } else { print("The database $DBName has been located.</P> "); } /* $sql = "CREATE TABLE $TableName (ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, JokeText TEXT, JokeDate DATE NOT NULL )"; if ( mysql_query($sql) ) { print("<P>$TableName table successfully created!</P> "); } else { echo("<P>Error creating $TableName table: " . mysql_error() . "</P>"); } */ $Query="INSERT into $TableName VALUES(Ɔ', 'hello hello hello!', ��-08-08')"; if (mysql_query ($Query)) { print ("The query was successfully executed!<br> "); } else { print ("The query could not be executed!<br> "); } mysql_close($link); ?> </body> </html>
Column Data From One Table To Another
im trying to get the vend_name column data from one table(manuf) into another table (products2) that has the same vend_name column which is empty but has a vend_code column as a key identifier. im wondering if theres a way to put the data from the vend_code column and vend_name column from the first into an array so that i can populate the vend_name column of the 2nd table this is what ive come up with below, it seems to be just puting the last record into those two array variables PHP Code:
Entering Data Into A Second Table:
Using a script, I able to insert the data into the first table of my mysql db, but when I try to insert the same into second table(duplicate, so same vars, etc.. no prob at that level), it doesn't go through. It doesn't even make an empty row(which would mean wrong vars) Someone told me to check in the logs of both PHP and mySQL. How do I do this?
Copy Table Data To Another
I've been searching in the PHP forums for this answer, and I've found something similar, and have used to this to the problem I have. Anyway, when I do run this script I get an error line 5 which is the 'while' statement. $query_newsfeed = "SELECT itemid,heading,news_date,content FROM newsfeed"; $query1_exec = mysql_query ( $query_newsfeed ); // Error here! while ( $query_row = mysql_fetch_assoc ( $query1_exec ) ) { $query2 = "INSERT INTO newsfeed_map ( itemid,heading,news_date,content ) VALUES ( $query_row[$itemid],'$query_row[$heading]','$query_row[$news_date]','$query_row[$content]' )" $query2_exec = mysql_query ( $query2 ); Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource Any ideas where I could be going wrong?
How To Replace ID With Data From Another Table.
I'm working on a project where I have a MySQL table that contains profile data. This data has 2 grouping fields one for group and one for criteria. The client wants the flexibility to edit and rename these grouping fields without having to go back and make changes to each profile. With this said, I created 2 more tables one for group and one for criteria. Tables would look like this:
Inserting Data Into A Table.
I keep getting a parse error with this code. What am I doing wrong? The SQL statement works in MySQL. Is there something wrong w/the way I'm decaring my PHP variables? Code:
Dynamic Data In Table
Trying to display dynamic data in a table. The code spits out the table just fine, but won't display the $name variable at all, I just get table cells w/ broken links. I must be missing something but can't get it, thanks. my code:
|