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?
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Database P0c79 - Table Personaldetails Error
I can't create a table in my database. I get the following message: Database p0c79 - table personaldetails Error SQL-query: CREATE TABLE personaldetails (id TINYINT not null AUTO_INCREMENT, firstname VARCHAR (15) not null , surname VARCHAR (15) not null , password VARCHAR (10) not null , teacherstatus ENUM not null , PRIMARY KEY (id)) MySQL said: You have an error in your SQL syntax near 'not null , PRIMARY KEY (id))' at line 1. I can't see what is wrong with this - it looks perfect to me, and there is no room for error as all I am doing is ticking boxes in phpMyadmin.
Error In Generating Table From Database Select Statment
I am trying to dynamically create a table with the results from a select statement. Below is the code that is not working. Any help would be oh so greatly appreciated. This is for a final at school which is due in an hour. This is the only thing I can't seem to make work. Code:
Second Unique ID In Table
I'm trying to create a messaging system for a project I'm working on. Theoretically I only need one table to do this, but I do need a unique auto increment primary key 'id' and a thread_id column. The thread_id column will contain a unique value for new messages, and will contain referential values for thread replies (children).. What is the best way of accomplishing this or should I just create a thread table with just one column?
Unique ID Error
I'm working on a Unique ID system for individual cases that get inputted into a DB. Here's the code, it works the first time I insert something into the DB, but after that everything returns 0 except the current year.. Code:
How To Pull Only Unique Items From Database?
I have a table like this: date, author, title, content now I want to grab the 3 latest items from this table from 3 DIFFERENT authors. I want this: -article by jim -article by sally -article by john Not this: -article by jim -article by jim -article by sally even if the two latest articles happen to be by jim, lets only grab the first one and move on. So basically I need (in pseudo-sql/plaintext): select title from contenttable where author=unique order by date limit 3 I've got everything code-wise except the "author=unique" part, how do I do that?
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.
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?
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?
Checking Database
Is it possible to check the database to see if information being submitted is already present in the database?
Error Checking
I have a classic problem: things run properly on my test server but don't work on the live server (different PHP version, different master Apache config, etc...) which I do not admin. In particular, for 'security reason' the access to the error.log file has long been disabled and I don't get any message on screen. Things just don't happen the way they should. I've tried putting various takes on this in my .htaccess to no avail: php_flag display_errors on php_value error_log /home/dargaud/logs/error.log # Nothing there php_value error_reporting E_ALL php_flag html_errors on php_flag log_errors on php_flag track_errors on What else can I try to troubleshoot issues without admin rights on the server ?
Checking A Database For A User Name
How can you check a database for something. I have a database with several fields and a page for creating new rows. I'd like to make it able to search the database for one of the fields, the user name, and add a new row it the name is not present and update the row if the user name is present. Any good ideas?
Error Checking On Date
I am writing a script that checks a date that was submitted from the previous form. In cold fusion where is a function called Isdate(variable) and if it came back false, then you kick out an error. I found the checkdate function, but you have to break the date into a Day Month and Year variables. Is there another way to check the date that I'm just not seeing?
Group Error Checking
Need to check a group of form inputs and want to run them in a group instead of separate statements. This is what i have so far and no luck any suggestions. I just put the form fields as variables in these to test and this is a far as I got before I realized this may not be the best way. Any suggestions? Code:
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.
Checking The Database To See If Submission Already Exists...
I have set up a form. Once the form is submitted the information is sent to this page (see code) below. I am trying to use an if statement to check if the VIN already exists in the database before it is INSERTed into MySQL. If the vin does exist the user gets an error saying so. If it doesn't exist the ELSE statement INSERTs the information into the database and the user gets a thank you message. Code:
Validation & Error Checking Broken?
I'm validating a simple form for input via post ($PHP_SELF). Near the end I check for username and password. I'm using simple if, elseif, else statements. I require them to enter password twice and check that they match. Problem is script doesn't valide past username input and I dont know why!! If you don't enter a password it doesn't do the validation anymore, it just dies for some reason. I would greatly appreciate anyones help, I've stared at this thing for hours and hours. Here is code...
Form Input Error Checking
Have a form field being inserted, needs to only allow an integer value through. Which function do I want to use to check the passed var to see if there are any non-integer values present? PHP Code:
Error Checking Custom Forms
I am writing software that allows users to create custom html forms...when they place the forms on their pages using a display function the site visitor can fill them out. The info is passed to a processing page...it all works dandy if there are no errors. My question is, if there ARE errors what would be the best wasy to redirect the user back to the form..with the POST data in there. I have looked through the posts regarding headers and fsockopen and stuff like that....but I am not sure how to implement this. I can grab the $_SERVER['HTTP_REFERER'] from the form page....so I can send them back to the correct page. But I am unclear on the most efficient way to repopulate the form with the information they have submitted...in other words...how can I pass the data back to the form after realizing it had errors.
Even After Proper Error Checking, I Still Get PHP Warnings
I've this class method, which makes sure I've got a variable that is a resource: function close() { if (is_resource($this->datastoreResultsPointer)) { mysql_free_result($this->datastoreResultsPointer); mysql_close(); } } all the same, I'm getting these PHP errors: Warning: mysql_free_result(): 286 is not a valid MySQL result resource in /home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/McDatastoreResultsMySql.php on line 89 Warning: mysql_close(): no MySQL-Link resource supplied in /home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/McDatastoreResultsMySql.php on line 90
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?"
Checking If A Value Is Not In An Array And Deleting Record From Database
I have been trying to figure this one out and have come up against a brick wall although I know it should be relatively simple. I have a form that passes an array to a php script from a multiple select box that is created dynamically. If a user deselects an item then I want to delete the record from the database but am having a big problem with it. The table in the dbase is quite simple with just three fields: id classid formid Basically, the form send through a classid and a formid value and I want to delete any records that have a classid that are not in the form array and have a formid which is passed as a hidden value. I suppose really what I want is to know how to see if a classid is not in the array that is passed.
Checking For Duplicates In Database On Form Submit
I had the idea to use the following to check for duplicate value when a form is submitted to a database: elseif ($result == $_POST['serialnumber']) { $db_handle = pg_connect('dbname=test2 user=andy password=da4531'); $query = 'SELECT serialnumber FROM system'; $result = pg_query($query); pg_close($db_handle); echo "<h2><b>Duplicate serial number! Go back, change serial number and submit form again.<b></h2><br />"; } I can't figure out how to get $_POST['serialnumber'] to check against each record of $result. Any ideas? All values of 'serialnumber' need to be unique.
Do Professional PHP Programmers Use Error Checking In Their Code?
I've made it habit to check all returns in my code, and usually, on most projects, I'll have an error function that reports error messages to some central location. I recently worked on a project where someone suggested to me I was spending too much time writing error messages, and that I was therefore missing the benefit of using a scripting language. The idea, apparently, is that the PHP interpreter writes all the error messages that are needed, and that I shouldn't write such code myself. I was given the impression that if I needed extensive error checking, or strict typing, then I should use a real language, like Java, but if I'm going to use a scripting language like PHP or Ruby, then I should leave errors to the interpreter, since the whole point of using scripting languages is speed of development. Has anyone else heard this argument, and do you agree with it? I'm wondering how other PHP programmers handle error messages. Check everything or leave it to the PHP interpreter to tell you when there is an error? Which of these two functions is better, the one with error checking or the one without? function getWeblogEntries() { $query = "SELECT * FROM weblogs"; $result = mysql_query($query); $howManyWeblogEntries = mysql_num_rows($result); for ($i=0; $i < $howManyWeblogEntries; $i++) { $row = getRow($result); extract($row); echo "<h1>$headline</h1>"; echo "<h7>$date</h7>"; echo "<div class="mainContent">$mainContent</div>"; } } function getWeblogEntries() { $query = "SELECT * FROM weblogs"; $result = mysql_query($query); if ($result) { $howManyWeblogEntries = mysql_num_rows($result); for ($i=0; $i < $howManyWeblogEntries; $i++) { $row = getRow($result); if (is_array($row)) { extract($row); echo "<h1>$headline</h1>"; echo "<h7>$date</h7>"; echo "<div class="mainContent">$mainContent</div>"; } else { reportError("In getWeblogEntries, the function getRow failed to return an array on the $i iteration."); } } } else { reportError("In getWeblogEntries, the query to the database failed."); } }
Error Checking/code Comparison Tools
does anyone have a cool/free/cheap tool that they use for error-checking that would allow you to e.g. copy code from two different pages and find where they are different? I have some code that seems to work in one page but not in another and I can't find the difference. I could just copy and paste but then I wouldn't really learn anything.
Problems With Error Checking / Control Of POST Variables
I have a small form that on button press submits to a PHP file for further processing into a database. I have to change the script as it allows blank / nothing to be submitted to the database. The intention is that if any of the two form fields are blank (empty) then the page is resent stating that they have to fill in all the fields to post (to a database). If I deliberately leave the fields blank and submit the form, querying the database shows that both fields are zero / null - so nothing was entered in to the database. However, if I use an echo command to see what is going on (before the data is entered into a database) I get the $TheName field with a "1" and the $TheComment field with an unknown entry (it doesn't echo anything to the screen - but it's not empty). The code I've used to test this is: $TheName = $_POST[gbName]; $TheComment = $_POST[gbComment]; if (($TheName = NULL) or ($TheComment = NULL)) { echo 'Quick error check running:<BR>' echo "Name: $TheName<BR>"; echo "Comment: $TheComment"; exit; } This does NOT execute as these fields are not empty. It only runs if I change to: if (($TheName = !NULL) or ($TheComment = !NULL)) Which is pointless as it will always execute with genuine entries. Using the amended code below: if (($TheName = !NULL) or ($TheComment = !NULL)) { echo 'Quick error check running:<BR>' } echo "Name: $TheName<BR>"; echo "Comment: $TheComment"; I get the result that both the echoed lines are displayed as blank (no "1").
PHP & CURL Installation Error (checking For Curl_easy_perform In-lcurl)
I'm trying to install the latest PHP4 version from the scratch. The configure string is following: ../configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql --with-curl --enable-exif --enable-mbsting=all --with-gd --with-openssl --with-zlib-dir=/usr --with-zlib Everything goes well until the cURL should be configured. At that point, I will encounter an error like this: checking for CURL support... yes checking for CURL in default path... found in /usr checking for cURL 7.9.8 or greater... libcurl 7.12.1 checking for curl_easy_perform in -lcurl... no configure: error: There is something wrong. Please check config.log for more information. OK, let's check out the config.log: [root@finnpower php-4.3.10]# tail config.log #line 20458 "configure" #include "confdefs.h" /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 builtin and then its argument prototype would still apply. */ char curl_easy_perform(); int main() { curl_easy_perform() ; return 0; } Following cURL packages are installed: curl-7.12.1-1 curl-devel-7.12.1-1 In general, I have Fedora Core 3 installed with self-compiled Apache 2... almost with PHP 4.3.10 too.
Update If Unique User And Unique Id?
I have a site which lists some links on a page.Each link gets parsed to "/out.php?entryid=x" When they do this, my out.php updates the number of times that has been viewed It then pushes them on to the appropriate link. To prevent "gaming" of the link count, I want to try and use the IP or a session or something that will mean users can not inflate the count of any one link by more than 1. Code:
Table In Use Error
I have two tables in my DB that are marked "in use" and cannot be accessed. I have tried myself to get them cleared up, to no avail. If there's anyone here who can help, I will gladly pay via PayPal.
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?
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:
HTML Table Fetched From A Database
I want to generate a HTML table based on names fetched from a database. The tricky part is that I want to generate the table so that the names is written on both the top row and the left collumn. Should look something like this ---------------------------------------------- | ||NAME 1 | NAME 2| NAME3| |NAME 1| | | | ---------------------------------------------- |NAME2| | | | ---------------------------------------------- |NAME3| | | | ---------------------------------------------- Hope that anybody has a idea how to solve this.
Putting Database Results In A 5x1 Table
I have a db of tens of thousands of entries. It's not too hard to pull all the entries and build a table that displays them one at a time, but in my case, that will be a huge waste of space. What I want to do is put one record in each of the columns. I thinks it's possible to do because I have seen very elaborate thumbnail gallery scripts to do this. I just want to be able to put two or three strings of text from each record into each row, and a checkbox. Here's sample of what I mean: <table width="76%" border="1" cellspacing="1" cellpadding="1"> <tr> <td>$record1Line1<br>$record1$Line2<br> <input type="checkbox" name="$record1checkbox" value="checkbox"></td> <td>$record2Line1<br>$record2$Line2<br> <input type="checkbox" name="$record2checkbox" value="checkbox"></td> <td>$record3Line1<br>$record3$Line2<br> <input type="checkbox" name="$record3checkbox" value="checkbox"></td> <td>$record4Line1<br>$record4$Line2<br> <input type="checkbox" name="$record3checkbox" value="checkbox"></td> <td>$record5Line1<br>$record5$Line2<br> <input type="checkbox" name="$record5checkbox" value="checkbox"></td> </tr> </table> I want to pull about 200 records at a time from the db and display as described above. How can I tell php to take five records from my result set and display above, then loop through the result set until I'm done?
Table With Weekly Schedule From A Database?
I'm designing a site for a community radio station and the schedule needs to be generated from the list of programs that are in the database the shows table has the following colums show_id, show_name, day, start_time, end_time (i didn't list the non-relevant ones for this portion of the site) because a table has to be built left to right instead of top to bottom (cell for monday 8am then tuesday 8am instead of all the monday then tuesday etc) and not all the programs are the same length (i think i can use row span="x" depending on the length of the show) I'm quite lost. should i have other colums? how do i query the database to pull the data out in the proper order and build the table?
Deleting A Table From A MySQL Database
I've looked at the manual and a few other php resources, but yet I couldn't find a simple and easy way to delete a table using php. I noticed there is a destroy() function within the MySQL class, but I'm not sure how it's used.
|