By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,786 Members | 2,241 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,786 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
"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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.