You are here: have to "actions" or run two types of queries (select,and update) on the same form? « PHP Programming Language « IT news, forums, messages
have to "actions" or run two types of queries (select,and update) on the same form?

Posted by eholz1 on 02/12/07 23:09

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация