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




PHP Update Query Mysql: Query Succussful?


I can't seem to successfully test an update query. Below is a piece of code that updates a statistics table. If row today doesn;t exist, a new day must be created. But this doesn't work...

thank you for your reply.

$today= date("Y-m-d");

$qq="update totals_r set hits_r=(hits_r+1), lang_$lang=(lang_$lang+1), cat_$cat=(cat_$cat+1), rating_$rating=(rating_$rating+1), bussite_$bussite=(bussite_$bussite+1) where date='$today'";

$result_6 = mysql_query ("$qq");

if (!$result_6){ /// IF !ROW_TODAY ==> CREATE NEW DAY

$qq_2="insert into totals_r (hits_r, lang_$lang, cat_$cat, rating_$rating, bussite_$bussite, date) values(Ƈ',Ƈ',Ƈ',Ƈ',Ƈ','$today')";

$result_6_2 = mysql_query ("$qq_2");

if (!$result_6_2){
$err_msg_sql_6= mysql_error();
$err_loc_6="$PHP_SELF"." // Query6: update totals_r";
}
}




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
PHP: MySQL UPDATE Query
I need to have a page where the user can update his info and/or delete his record. I haven't tested the DELETE query yet.

When I open the page it shows all the info stored in the database. When I change something and hit the update button I get the message that the record was successfully updated, but nothing really hapens.

If you want to see what's happening go to URL , click on the 'directory' link
The user ID is 'scooby', and password 'dooby'. If it does not work, try the following combination: user ID: 'sunny', password: 'trout' . Then click on the 'edit profile' link and try to change something and see what happens. I am attaching a php file of the 'edit profile' page, the one I am having trouble with so you can see the entire code.

Update Query
I am having a problem with the update script. I making a group update and i keep on getting "cant execute query" error. I am wondering if its my SQL statement. PHP Code:

Update Query
I have wrote a system to mange revision guides for a school. The pages that assign a book to a student works fine. When a student returns the book i simply want to change the status to "Returned" from "With Student". Code:

Update Query
i wanted to update all my tables field value to "0", but the problem is i got 20 fields

the usual way "update table1 set field1=0,field2=0,field3=0....field20=0 where id='my_id'";

is there a way to update all fields without specifying the fields to update?

Query Update
i have a form wherein once submitted it:

1. update table 1
2. insert in table 2

the form has a "specialization" select box wherein you can select multiple items
and those items are updating "hits" row in table 1 adding 1 for every item that is being selected.

my codes are working if i only select 1 item from the "specialization" select box but the problem comes if i select more that 1 item on the select box.

this is the code for my form:

Can I Update 2 Tables In The Same Query?
I want to update 2 or more tables. Can I do this in the same query?

Databse Update Query
im trying to update a row PHP Code:

Update From Single Query
Anyone know if this script is capabale of doing a multiple update in MySQL from a single form? It basically pulls out all the players from a particular team and adds static list boxes for games played/games won. The script works... but am having troubles with this part. code:

Interesting Update Query
I have a column that contains names in upper case like:

JOE, LAST NAME
THOMAS JEFERSON MORS
MIKE LEE
..
..
..

and i wat it to be like:

Joe, Last Name
Thomas Jeferson Mors
Mike Lee

Get Update Query Working
I have always had a problem with updating rows in SQL, and now this is the best piece of update code I have and it wont work?!?

I send the url like this edit.php?id=$id

and this is my code, which just brings up a blank page weather ID is posted or even just edit.php Code:

PHP ODBC Update Query To Access
For some reason I am getting a datatype mismatch on the following SQL query and I do not understand why because the field datatype is number in the access database and the update query is using a number to update to that field? PHP Code:

Parse Error In Update Query
This is the first time I have ever used the update query. I am not having any luck figuring it out. Please post if you find my mistake,

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting

T_STRING or T_VARIABLE or T_NUM_STRING in
[bleeped] on line 46
here is the location of the problem:

$sql = "UPDATE $table
SET pagecontent = $_POST['T']
WHERE id = $_POST['id2']";

Using Record Identifier From Select In Update Query?
Just wondering if I can get a record identifier from a query. The basic idea is to process the data in a user-specified field in a user-specified table.. and write it back without modifying any other field. So the program would go something like this:

$qid=mysql_query("SELECT $field FROM $table");
WHILE ($list($field_value)=mysql_fetch_row($qid)) {
new_field = process($field_value);

and then the tricky part - how do I write back $field to $table? If I use an update query (eg: UPDATE $table SET $field=$new_field WHERE $field='$field_value') it will update all the fields where $field is $field_value.

Is there a way of getting a (unique) record identifier from the select query and using it in the update query? Since the table is user-specified, I have no way of knowing what the primary index is.

REGEX: Can't Seem To Replace LIMIT Clause In Query Using Preg_replace ($pattern, $replacement, $query)
Want to replace the limit clause in a query, but can't get it right.
What's wrong with this:

$pattern = "(.*)limit (.*)";
$replacement = '$1'
$replacement .= "LIMIT $limit";
$replacement .= '$2'
$query = preg_replace ($pattern, $replacement, $query);

Speeding Up Query/code (query Within Result Set)
I'm looking for ideas on how to speed up this script. Basically it finds all the zip codes in a zipcode table, then looks for all the records in another table with those zip codes.

Right now it finds all the zips then within that WHILE, it looks for a record in another table with that zip: PHP Code:

Using Query Result To Do Another Query In Loop
I have 2 tables, one called users2 and one called books. Books has a field called UserId, which is the ID of the user that added the book to the database.

My problem, is that i need to take this ID from the book table, and use it to get some information from the user table. Here is my code to get the ID from the book table: Code:

Empty Query, Query Fail
i am doing a user authentication but my problem is that when i type in user name and password it is Code:

PHP Saying Error In Mysql Syntax, But Written My Mysql Query Browser!
I have a basic db that I access with MySQL query browser. Everything
seems fine to me but I am using this db as part of a php shopping
basket and when I try to add an item I get:

Notice: Query failed: You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near '>function.extract]: First argument should be an
array in functions.inc.php on line 31
Notice: Undefined variable: price in functions.inc.php on line 36
Notice: Undefined variable: price in functions.inc.php on line 39
Notice: Undefined variable: total in unctions.inc.php on line 39

I'm assuming the last three are caused by this problem as price should
be passed to the cart, and total is worked out using it. However
although I know mySQL code it was the MySQL query browser that
actually generated the code and I cannot see a way to view or debug
the code.

The db has one table in it which is made up of id, name, subname,
desc, and price.

The code in the php file that is being referred to is:

SQL Query "UPDATE" Question
I want to write a query something like this:

"UPDATE database SET data='data + 1'"

but I'm not quite sure of the syntax I should use. I want to do it like this so I can minimize the number of SQL queries I have to execute. Also, would I be able to use division and multiplication and such instead of a +/- sign?

Query MySql Using PHP
I've created my first search form and it seems everything is working pretty well. However, since I am very novice in scripting in general, I'm having one problem that I can't seem to unearth an answer to. Perhaps someone could easily offer the answer:

my query asks to select a 2 char state code or a 5 digit zip code in order to obtain results desired. In testing, if I enter a state code, it brings up only the state requested. However, when I enter a zipcode, I get the wrong results. I'm sure its the "LIKE" that is throwing this off. Here is the query portion of the script:

$result = mysql_query ("SELECT * FROM fish_dealers
WHERE Zip = ´$Zip%´

OR State LIKE ´$State%´
");


Can anyone give me a clue?

Mysql Query
I have wrote a Select statement, that checks if the user and password and returns a value, however can i add something to the statement that would allow me to get the userID from the table users, so that i can write the value to a cookie, is it possible. PHP Code:

MySQL Query
I want to have a field where I store a list of what categories that
particular row falls under, I don't know which format to do or how I
would query it.

For example, row1 might belong to categories 1, 3 & 7 - I'd want to be
able to query all rows belonging to 3 and get row1.

AND And OR In MySQL Query
I've build a query from a php form where people van select more results for a cell wich can only contain one value Here's my query:

SELECT * FROM person WHERE color_eye = ('brown') OR color_eye = ('black') AND color_hair = ('Blonde')

Everything after the "OR" will be ingnored. So how can I tell MySQL I want all the brown and blacked eye?? Without the AND it works fine, but in real the query is way longer with multiple AND's.

Mysql Query
I have a code that installs some tables into a mysql database. Heres the code, but it keeps coming up with the error "Install failed (ID 1)" I have tried tons of things, even looking at other installers and mimicking them, but nothing. PHP Code:

Php/mysql Query
I want to display the users name on the pages when they have logged into my site. i have done it one way that is to take what they type in the login form and post it on the page and that works fine. only one problem and its more of a preference than a problem but the way i did it takes exactly what they type say "username" and posts that so if they type "UsErNaMe" it will post it like that. i want to show the name exactly as they make it when signing up. im guessing i have to query the data base... mine being MYsql. PHP Code:

Mysql Query
How can I get rownum using MySQL queries ,
In Oracle one can you in this way SELECT rownum as srno, fname FROM
tablename
suppose If there are 45 records and if i use while for the

srno should display 1, 2, 3, ... 45

query like SELECT rownum as srno, fname FROM tablename

I dont want to use php counter, i want it from query

Mysql Query
I'm running a sports pool and I'm trying to display stats from the
results of the picks.

The table is 'results' and the fields are 'pick_number', 'game_number',
'user_id', 'points' and 'date'

There is one record for each users' pick. 0 points are given for a loss
and 1-4 points are given for a win. I've already created a query that
gives me the top players by overall points but I'd like to expand that
to include the number of points won just this week, overall winning %
and winning % this week. Can I do this in one query and then display in
an HTML table?

$query = "SELECT user_id, SUM(points) AS points FROM results GROUP BY
user_id ORDER BY points DESC";

Mysql Query
1) i have a database divinelive_messages table with a sessid column
2) i need to find out rows from the database, which only show that sessid in there once.

Mysql Query With * And +
im trying to return all results that come from or went to certain extensions on our phone logging system but i don't want to return any that have a src or dst that contain a * or a +. This is the where statement i have that is not working Code:

Getting MySQL Query
I took some info out of my database.  I want to display an error page if their are no rows in the database.  How would I go about doing that. I have this:

$query = I execute my query here.  Taken it out so you don't connect to my database Muahahahhaah

$row = mysql_fetch_row($query)

if ($row == '')
{
echo 'Their is nothing in the database!';
}else{
echo 'Yes, the database does home info in it.';}

What would I put to make this work?

MySQL Query
Whats wrong with this query:

SELECT from, subject, message, time FROM user_messages WHERE username='$username' ORDER BY timestamp DESC

I get this error:
QuoteYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from, subject, message, time FROM user_messages WHERE username='Drezard' ORDER B' at line 1

MySql Query
I'm having some difficulty formulating  query that will allow me to retrieve the details of a specific user in the database. The user's information is stored in one table called Users and another called UserProfile. Both tables are linked by the UserID field.

My current query returns a Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource and my knowledge of Mysql is not great(Still learnng)

Here is my code:

Need Help With Basic Php Mysql Query
$z = "goodBMW"; the word goodBMW is no where to be found in in the table times. but it will echo every single row thats in that table and it doesend sort between Group 1 and Group 2 where the hell is my query wrong.

Problematic MySQL Query
Would anyone be able to help me with the following MySQL problem. I am
trying to extract all of the users who are not on vacation for a given
date. I am using a NOT IN statement, however, I need to have a more
advanced query than a simple one. What I need to do is as follows
SELECT users.user_id,...

MySQL Query Quandry
I have a simple need to go into a 4 column table and based on the content of the first 3 print the content of the 4th. In other words if column1 = a, column2 = b, and column3 = c then print "dog" from column4. This will be the action for a short form that allows the user to make 3 choices that will determine a link. I have this from another script that I'm trying to modify:

mysql_select_db('search_links');
$query = "select * from links ";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
echo '<p>Number of books found: '.$num_results.'</p>'
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo '<p><strong>'.($i+1).'. Title: '
echo htmlspecialchars(stripslashes($row['type_prop']));
echo '</strong><br />Author: '
echo stripslashes($row['area_code']);
echo '<br />ISBN: '
echo stripslashes($row['price_range']);
echo '<br />Price: '
echo stripslashes($row['saved_link']);
echo '</p>'
}

The above query prints the entire table and I would like a query that limits to the form choices indicated above.

Getting Variable From Mysql Query
what's the best way to set a variable = to a result from a mysql query?

Advanced Mysql Query
There are currently two queries in one of my scripts. One is:

SELECT * FROM foo

the other is:

SELECT var FROM bar WHERE something = 'somethingelse'

Is is possible to use a join statement and combine these two into one query? My reason is that I'm trying to speed up the script, and hopefully combining the queries will do that.

Mysql Date Query
I need to check if one script was run later than one hour ago - I had a problem with cron and want to put in a safety code.

On successful running of the script I remember the date in db
CREATE TABLE log(id INT NOT NULL auto_increment, ttime DATETIME, other_info TEXT, PRIMARY KEY(id));

The sql query that I use now is:
SELECT HOUR(CURDATE() - ttime) as h FROM log ORDER BY h LIMIT 1;

However I have a problem - it returns sometimes value NULL (which is always first).

If I use the following syntax:
SELECT HOUR(CURDATE() - ttime) as h FROM log WHERE h IS NOT NULL ORDER BY h LIMIT 1;

I get the error: Unknown column `h` in `where clause`. What can I do?

Mysql Query - Select Any
I have the following sql statemant to search a mysql database that gets
if values from a form with combo box's in.

SELECT * FROM hottubs, manufacturers WHERE manufacturers.manid =
hottubs.manid AND hottubs.type = '%s' AND hottubs.dimlength <= '%s' AND
hottubs.dimwidth <= '%s' AND hottubs.dimhight <= '%s' AND
hottubs.seatsto <= '%s' AND hottubs.shape = '%s' ORDER BY
$thesearchtype_search.

Everything works fine except I want to add a select "any" from the
shape combo box. I really need a way of cutting out the last " AND
hottubs.shape = '%s' " if the $_GET['shape'] = 'any'
Will this work using a variable as shown below??

IF ($_GET['shape'] != 'any' )
{
$shape = AND hottubs.shape = '%s'
}

SELECT * FROM hottubs, manufacturers WHERE manufacturers.manid =
hottubs.manid AND hottubs.type = '%s' AND hottubs.dimlength <= '%s' AND
hottubs.dimwidth <= '%s' AND hottubs.dimhight <= '%s' AND
hottubs.seatsto <= '%s' $shape ORDER BY $thesearchtype_search

I have only been doing php about a month so go gentle!

MySQL Query On The Same Page.
here it is: i have a table with lets say 2 fields, first_name and last_name. When user enters index.php he gets database records sort by first_name (ORDER BY first_name). Now i ave made two links above those records. They are: sortb by firts name and sort by last_name.

My question is, what code should be written for the link sort by last name if i wanna show the same records already displayed but sorted by last_name???

And how do i make that if user has clicked sort by last name that thislink is disabled (not underlined, just bold text) and if he clicks on sort by first name that this link becomes text.

MySQL Query With PHP Variables
My Query is like this I have two dates inter in by the user and set to $x(lower) and $z(higher). I want to pull all entries that are between these 2 dates.

This does not work (Why?):

$result = @mysql_query("SELECT id, maincourse, veggie, veggie2, fruit, bread, dessert, drink, DATE_FORMAT(day, '%a %b, %D') as date_string FROM $fromwhere WHERE day<=$x AND day<=$z");

note: "WHERE day>$x" does work.

Query Inconsistency (MySQL Vs PHP)
I have the following query:

select DATE_FORMAT(accountingdate,"%c") as month,sum(totalprice -
freightcost - insurancecost - vat2 - vat3 - vat4) as totalprice from
invoice where cancelled=0 and deliveryagentid=0 and (employeeid=0 or
employeeid=37 or employeeid=53 or employeeid=50) and
DATE_FORMAT(accountingdate,"%Y")="2005" group by month order by month;

Giving the following result in MySQL (correctly):
+--------+--------------+
| month | totalprice |
+--------+--------------+
| 1 | 540274351.00 |
| 10 | 119601657.00 |
| 11 | 118712994.00 |
| 12 | 109391926.00 |
| 2 | 112606305.00 |
| 3 | 99175084.00 |
| 4 | 101754796.00 |
| 5 | 120049120.00 |
| 6 | 138227787.00 |
| 7 | 166565653.00 |
| 8 | 136475650.00 |
| 9 | 133242379.00 |
+--------+--------------+

When I run the same query in PHP (on a web site, I get):

4 538068.00
4 538068.00
4 538068.00
4 538068.00
4 538068.00
4 538068.00
4 538068.00
4 538068.00
4 538068.00
4 538068.00
4 538068.00
4 538068.00

Mysql Search Query
Is there a way to search for a word in any of the fields of a row using simple sql for my sql?

I have a rather complex search function on my site and right now, I dump all the text of all fields (that are text fields) in a
special field. The search function then searches this "keyword" field.

Is there a smarter way of doing this.

To recoup

I have an mysql database with about 500 records, each containing over 20 text fields (address, name, etc.... etc....). I want the
user to be able to search for a particular word (e.g. fishing or rock climbing) in all records and all fields and I would like Mysql
to return the IDs of the fields that match.

Along the lines of

SELECT ID FROM TABLE WHERE * LIKE "%test%";

MySQL Query And Arrays
I have a 'links' category on Table A and I want to retrieve the links from the Table and display them in a list-like fashion when the page is called upon. How would I go about seperating the links from one another (there a space inbetween each link.. EXAMPLE: http://asdf.com http://asdasd.com http://asdfff.com), loading them into an array (or using the best possible method to acces them easily) and then displaying them in a list like fashion..?

Date/MySQL Query
I am making an event calendar that allows users to add events. An event can possibly span multiple days so I made two fields for start date and end date. This all works fine.

I want to be able to grab the data out of the database through a query and display it on the webpage in order of date. So I'm ordering by the start date. However if the event is 3 days long I want to show the event on the page 3 times, with all other events in between also show. I have not been able to figure out the logic on how to get the event to show up 3 times with other events in between them?

Sample Data:
Event 1 Dec 31 2002
Event 2 Dec 31 2002
Event 1 Jan 01 2002

Oddball MySQL Query
What I'm trying to do is take php variables i got from user input, and
pass them as the MySQL query terms.

$query = "select * from ident where ".$searchtype1."=".$searchterm1."";

ERROR: Invalid query: You have an error in your SQL syntax near '=' at
line 1

I have also tried,

$query = "select * from ident where ".$searchtype1." like
'%".$searchterm1."%'";

ERROR: Invalid query: You have an error in your SQL syntax near 'like
'%%'' at line 1

both return similar errors as you can see. I have o idea if the problem
lies with the variable (i try echo-ing, and printing them and i get
nothing) or if it actually is with my sql syntax (i enter the first query
above in mysql from the shell without variable obviously and it returns
the results perfectly). Here is the rest of my code and any help is
greatly appreciated.

Form for getting variables:

<form action="searchrsiident.php" method="post" align="center">
Choose Search Type:<br>
<select name="searchtype1">
<option value="NSN">NSN
<option value="NIIN">NIIN
<option value="NOMENCLATURE">NOMENCLATURE <option value="CAGE">CAGE
<option value="Field5">Field5
<option value="REV">REV
<option value="EQUIP">EQUIP
<option value="RSI_P/N">RSI_P/N
<option value="WAITING_IN">WAITING_IN <option value="NOTES">NOTES
<option value="SOS_CODE">SOS_CODE
<option value="WORK_ORDER">WORK_ORDER <option value="L_QUOTE">L_QUOTE
<option value="A_QTY">A_QTY
<option value="A_PRICE">A_PRICE
<option value="L_WO">L_WO
<option value="L_NOTE">L_NOTE
</select>
<br>
Enter value to search by:<br>
<input name="searchterm1" type=text>
<br>
<input type=submit value="Search">
</form>


Relevent part of my php code (i hope):

$searchtype1 = addslashes($searchtype1); $searchterm1 =
addslashes($searchterm1);

$db = mysql_connect("localhost", "browseuser", "");

if (!$db)
{
echo "Error: Could not connect to database. Please try again
later."; exit;
}
}
mysql_select_db("rsi_ident");
$query = "select * from ident where ".$searchtype1." like
'%".$searchterm1."%'";

$result = mysql_query($query, $db) or die("Invalid query:
".mysql_error()); $num_results = mysql_num_rows($result);

Mysql Query Question
I have a database that stores in a field the number of views for a product.

I want to write a query that gets the two highest views, so I can then
output the result.

I have this so far, but not sure how to adapt it to get the two highest
views.

mysql_query("SELECT max(views) FROM stock WHERE status='enabled' AND photo1
!= ''");

I then plan to loop through the results and echo the photo value for each
result.

I am sure this is easy, but just can't figure out the correct syntax.

Layout Of MySQl Query
Only thing i cannot seem to
grasp yet is that !$column is the first, and then
you close it when it's not the first anymore.
To me this would seem like it would only give one collumn.

[Why didn't you quote the previous posts?]
[Yes, I know Google groups suck]

knoak wrote:[color=blue]
> Yes, that works great! Thanks a bunch!
> Too bad i don't understand this (yet) completely...[/color]

[previous posts pasted back in]
[color=blue]
> $result = mysql_query("SELECT * FROM datatable WHERE item=$searchterm
> ORDER BY item ASC",$db);[/color]

## start the table
echo '<table class="search_result" summary="search result">'

## initialize control variable
## $control will either be 0 or 1
## 0 means we're about to output the first column
## 1 means we're about to output the second column
$column = 0;

## for every record selected
while ($row = mysql_fetch_array($result)) {

## start a table row if it is the first column
if (!$column) echo '<tr>'
## print the data
echo '<td>', $row['whatever'], '</td>'
## end the row if it is not the first column
if ($column) echo '</tr>'

## swap between 1 and 0 every time this line executes
$column = !$column;
}

## if there were an odd number of records selected we will
## be left with an empty last cell -- fill it
if ($column) echo '<td>(empty cell)</td></tr>'

## end the table
echo '</table>'

Mysql Parameterised Query
I'm using mysql 4.1 and php5.0.4. Since (AFAIK) this version of mysql
supports parameterised queries, is there a way to accomplish that using
mysql_... functions (looks like mysql client library is unaware of this
feature), I need it to avoid sql injection in a "right" way... :))


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