473,320 Members | 1,946 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

have to "actions" or run two types of queries (select,and update) on the same form?

Hello PHP programmers.

I had a brilliant idea on one of my pages that selects some data from
my mysql database.
I first set the page up to display some info and an image, just one
item, with a row of data, etc.

then I thought it would be nice to do a select, and perhaps an update
(the title of the image) on the same page.

I am wondering if I am having the wrong idea. I have a form, with two
submit buttons, one selects an image, and some info. the other will
update the image title for the given image (id, and p).
I am seeing that I have a mistake here, since it seems the update
query will run as well as when the select query is run (select button
clicked). this overwrites my image titles in the db.

I have the wrong idea, but have not seen how to do this "right". I
could use another php page for update, but I am guessing this can be
done from the same page.

Below is my poor code - i am not an expert programmer!!! any help,
suggestions will be helpful.

<?php

$img = $_REQUEST["img"];
$p = $_REQUEST["p"];

echo '<div class="input">'."".'</div>';
//connection files for mysql
@include 'c:/php/includes/db.inc';
@include 'c:/php/includes/error.inc';
//***@include '/usr/local/php/include/db.inc';
//***@include '/usr/local/php/include/error.inc';
//@require_once '/usr/local/php/include/size_image.php';

global $dbconnect, $query;

here is the select stuff...

if ($_REQUEST['img'] != 0 && $_REQUEST['p'] 99 ) {
echo $_REQUEST['updatetitle'];

$dbconnect = @db_connect('portfolios') or
trigger_error("Error Connecting to Database: ". mysql_error(),
E_USER_ERROR);

$result = @mysql_query("SELECT * FROM images3 WHERE id=" . $img . "
AND p=" .$p. "");

if (!$result)
{
echo("Error performing query: " . mysql_error() . "");
exit();
}

$row = @mysql_fetch_array($result);

$imgid = $row["id"];
$title = $row["title"];
$mod = $row["modfolder"];
$name = $row["name"];
$height = $row["resize_height"];
$width = $row["resize_width"];
$image = $row['modfolder'].'/'.$row['name'];

}
?>
<center><h2>Image Database Query View</h2>
<a><?php echo "Database Image Browser" ?></a>
<body>
<hr>
<div id="entry">
<h3>Enter ID for image...<!--input type="hidden" name="MAX_FILE_SIZE"
value="150000"-->
<input type="hidden" name=updatetitle value=<?php $update ?>>
</h3>
<form enctype=multipart/form-data action="display_orders.php"
method=post>
<?php
//here is the update stuff
if ($_REQUEST['title'] != '' )

{

$img = $_REQUEST["img"];
$p = $_REQUEST["p"];
$update = 1;

$query = 'UPDATE images3 SET title =\' ' . TRIM($_REQUEST['title']).
'\' WHERE id = ' . $_REQUEST['img'] .
' AND p=' . $_REQUEST['p'] .';';

//echo $query;
$dbconnect = @db_connect('portfolios') or
trigger_error("Error Connecting to Database: ". mysql_error(),
E_USER_ERROR);

$result = @mysql_query($query);

if (!$result)
{
echo("Error performing query: " . mysql_error() . "");
exit();
}

if ($result 0) echo '<div class="input">'."Title Updated".'</div>';

mysql_free_result($result);
mysql_close($dbconnect);
}
?>
<div id="imgid" class="input" >Enter Image ID: <input name=img
type=text size="6"></div>
<!--br-->
<div class="input">Enter Portfolio Number: <input name=p type=text
size="6"></div>
<!--br-->
<div id="btn" class="input">Then Click: <input type="submit"
value="Select Image"></div>
<div id="udate">
<div id="imgtitle" class="input" >Enter or Change Title: <input
name=title type=text size="55"
value=" <?php echo $title ?>" ></div>
<div id="btn" class="update">Click to Update: <input type="submit"
value="Update Title"></div>
</div>
</form>
</div>
<hr>
<table class="maintable" border=1>
<tr class="rowbar"><th>Image ID</th><th>Modfolder</th><th>Name</
th><th>Title</th><th>Resize(h)</th><th>Resize(w)</th></tr>
<?php
// get the data again??? no , move the pointer!!
//*** $result = @mysql_query("SELECT * FROM images3 WHERE id=" .
$img . " AND p=" .$p. "");
// generate the table
//while ( $row = @mysql_fetch_array($result) )
//{
?>
<tr>
<td><?php echo $imgid ?></td>
<td><?php echo $mod ?></td>
<td><?php echo $name ?></td>
<td><?php echo $title ?></td>
<td><?php echo $height ?></td>
<td><?php echo $width ?></td>
</tr>
<tr><td valign="middle" align="center" class="mainbox" colspan="6">
<?php
//$image = $row['modfolder'].'/'.$row['name'];
echo '<img class="mainimage" src="'. "$image" .'"'. ' alt=""
'.'height="'.$height.'"'.' width="'.$width.'"' .'/>';

?>
</td></tr>
<?php
mysql_free_result($result);
mysql_close($dbconnect);
?>
</table>
</body>
</html>
thanks for your suggestions, etc
ewholz

Feb 12 '07 #1
3 2641
"eholz1" <ew****@gmail.comwrote in message
news:11**********************@p10g2000cwp.googlegr oups.com...
Hello PHP programmers.

I had a brilliant idea on one of my pages that selects some data from
my mysql database.
I first set the page up to display some info and an image, just one
item, with a row of data, etc.

then I thought it would be nice to do a select, and perhaps an update
(the title of the image) on the same page.

I am wondering if I am having the wrong idea. I have a form, with two
submit buttons, one selects an image, and some info. the other will
update the image title for the given image (id, and p).
I am seeing that I have a mistake here, since it seems the update
query will run as well as when the select query is run (select button
clicked). this overwrites my image titles in the db.

I have the wrong idea, but have not seen how to do this "right". I
could use another php page for update, but I am guessing this can be
done from the same page.

Below is my poor code - i am not an expert programmer!!! any help,
suggestions will be helpful.

Too long code, didn't read it all, but here's a tip for you: Have two submit
buttons, but name them differently. On server-side you test which button was
clicked based on which submit was sent. (Of several submit buttons, only the
one that was clicked is sent in the form)
<input type="submit" name"select" value="select-a-mundo!" />
<input type="submit" name"update" value="update-a-mundo!" />

on server-side this code will tell you which was clicked:
<?php
if(isset($_POST['select'])){
// Now you run the select query
} else if(isset($_POST['update'])){
// Now run the update query
}
?>
--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net | rot13(xv***@bhgbyrzcv.arg)
Feb 13 '07 #2
On Feb 12, 10:45 pm, "Kimmo Laine" <s...@outolempi.netwrote:
"eholz1" <ewh...@gmail.comwrote in message

news:11**********************@p10g2000cwp.googlegr oups.com...
Hello PHP programmers.
I had a brilliant idea on one of my pages that selects some data from
my mysql database.
I first set the page up to display some info and an image, just one
item, with a row of data, etc.
then I thought it would be nice to do a select, and perhaps an update
(the title of the image) on the same page.
I am wondering if I am having the wrong idea. I have a form, with two
submit buttons, one selects an image, and some info. the other will
update the image title for the given image (id, and p).
I am seeing that I have a mistake here, since it seems the update
query will run as well as when the select query is run (select button
clicked). this overwrites my image titles in the db.
I have the wrong idea, but have not seen how to do this "right". I
could use another php page for update, but I am guessing this can be
done from the same page.
Below is my poor code - i am not an expert programmer!!! any help,
suggestions will be helpful.

Too long code, didn't read it all, but here's a tip for you: Have two submit
buttons, but name them differently. On server-side you test which button was
clicked based on which submit was sent. (Of several submit buttons, only the
one that was clicked is sent in the form)
<input type="submit" name"select" value="select-a-mundo!" />
<input type="submit" name"update" value="update-a-mundo!" />

on server-side this code will tell you which was clicked:
<?php
if(isset($_POST['select'])){
// Now you run the select query} else if(isset($_POST['update'])){

// Now run the update query}

?>

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpkhttp://outolempi.net/ahdistus/- Satunnaisesti päivittyvä nettisarjis
s...@outolempi.net | rot13(x...@bhgbyrzcv.arg)
Thanks for the tip - I will try your suggestion, thanks again
ewholz

Feb 13 '07 #3
On Feb 12, 10:45 pm, "Kimmo Laine" <s...@outolempi.netwrote:
"eholz1" <ewh...@gmail.comwrote in message

news:11**********************@p10g2000cwp.googlegr oups.com...
Hello PHP programmers.
I had a brilliant idea on one of my pages that selects some data from
my mysql database.
I first set the page up to display some info and an image, just one
item, with a row of data, etc.
then I thought it would be nice to do a select, and perhaps an update
(the title of the image) on the same page.
I am wondering if I am having the wrong idea. I have a form, with two
submit buttons, one selects an image, and some info. the other will
update the image title for the given image (id, and p).
I am seeing that I have a mistake here, since it seems the update
query will run as well as when the select query is run (select button
clicked). this overwrites my image titles in the db.
I have the wrong idea, but have not seen how to do this "right". I
could use another php page for update, but I am guessing this can be
done from the same page.
Below is my poor code - i am not an expert programmer!!! any help,
suggestions will be helpful.

Too long code, didn't read it all, but here's a tip for you: Have two submit
buttons, but name them differently. On server-side you test which button was
clicked based on which submit was sent. (Of several submit buttons, only the
one that was clicked is sent in the form)
<input type="submit" name"select" value="select-a-mundo!" />
<input type="submit" name"update" value="update-a-mundo!" />

on server-side this code will tell you which was clicked:
<?php
if(isset($_POST['select'])){
// Now you run the select query} else if(isset($_POST['update'])){

// Now run the update query}

?>

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpkhttp://outolempi.net/ahdistus/- Satunnaisesti päivittyvä nettisarjis
s...@outolempi.net | rot13(x...@bhgbyrzcv.arg)
Hello Ohjelmoija,

thanks, this worked fine.

ewholz

Feb 13 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Klaus Neuner | last post by:
Hello, as I am desperately searching for a (straightforward) solution of the following problem, I'll give it another try: How can I tell Python to do things of the following kind: for n...
4
by: Laura | last post by:
Hello, I'm pretty sure that this can be done, but I am unable to find documentation on it. Presently I have a plain HTML survey form where users check multiple checkboxes, then submit. The...
1
by: Jon | last post by:
I wonder if anyone can help me with an answer for this, the question seems well covered in the achieves, but a lot of the answers disagree with each other and I couldn't find no real solution. I...
8
by: Mike N. | last post by:
Hello: I am new to T-SQL programing, and relativly new to SQL statements in general, although I have a good understanding of database theory. I'm a little confused as to the fundamental...
2
by: pete moss | last post by:
I finally tried got around to converting an old access 2.0 databases to Access 2000 (these are backend front end databased with the back end tables still in 2.0) Most everything seems to work...
5
by: Kiki | last post by:
Hello all. Probably I should be sending this to a different group so apologies if this seem out of place. We have an Access db in which people change data - as they do. When they do that, our SQL...
5
by: SunnyDrake | last post by:
HI! I wrting some program part of it is XML config parser which contains some commands(for flexibility of engenie). how do i more simple(if it possible not via System.Reflection or...
18
by: desktop | last post by:
I have 3 types of objects: bob1, bob2 and bob3. Each object is identified by a unique ID which gets returned by the function getId(). All bobs are descendants from class BaseBob which is an...
3
by: Mark Shroyer | last post by:
I guess this sort of falls under the "shameless plug" category, but here it is: Recently I used a custom metaclass in a Python program I've been working on, and I ended up doing a sort of write-up...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.