Run SQL Update on button click in PHP
Posted: Wed Mar 25, 2009 6:26 pm
Hi, I was wondering if it is possible to run an Update sql statement after a user clicks a button? For example, when a button is clicked, I want to run the following query:
mysql_query("UPDATE tech SET name='newName', email='newEmail', phone='newPhone', pass='NewPass' WHERE $usr_id = $row[techid];");
Is this possible, and is that how I get my input values to be used in the update?
My code is below:
<?php
$link = mysql_connect('localhost', 'root', 'root');
if (!$link){
die('Could not connect' . mysql_error());
}
echo 'Connected Successfully <br />';
$selectdb = mysql_select_db ('chfa', $link);
if(!$selectdb){
die('Could not select database' . mysql_error());
echo 'Did not select database';
}
echo 'Database Selected <br />';
$usr_id = $_GET["id"];
echo $usr_id;
$result = mysql_query("SELECT * FROM tech WHERE techid = '$usr_id';");
echo "<table border='1'>
<tr>
<th>Name</th>
<th>E-mail Address</th>
<th>Phone Number</th>
<th>Password</th>
</tr>";
while($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td><input type='text' name='newName' value=" . $row['name'] . "/></td>";
echo "<td><input type='text' name='newEmail' value=" . $row['email'] . "></td>";
echo "<td><input type='text' name='newPhone' value=" . $row['phone'] . "></td>";
echo "<td><input type='text' name='newPass' value=" . $row['pass'] . "></td>";
echo "</tr>";
}
mysql_close($link)
?>
mysql_query("UPDATE tech SET name='newName', email='newEmail', phone='newPhone', pass='NewPass' WHERE $usr_id = $row[techid];");
Is this possible, and is that how I get my input values to be used in the update?
My code is below:
<?php
$link = mysql_connect('localhost', 'root', 'root');
if (!$link){
die('Could not connect' . mysql_error());
}
echo 'Connected Successfully <br />';
$selectdb = mysql_select_db ('chfa', $link);
if(!$selectdb){
die('Could not select database' . mysql_error());
echo 'Did not select database';
}
echo 'Database Selected <br />';
$usr_id = $_GET["id"];
echo $usr_id;
$result = mysql_query("SELECT * FROM tech WHERE techid = '$usr_id';");
echo "<table border='1'>
<tr>
<th>Name</th>
<th>E-mail Address</th>
<th>Phone Number</th>
<th>Password</th>
</tr>";
while($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td><input type='text' name='newName' value=" . $row['name'] . "/></td>";
echo "<td><input type='text' name='newEmail' value=" . $row['email'] . "></td>";
echo "<td><input type='text' name='newPhone' value=" . $row['phone'] . "></td>";
echo "<td><input type='text' name='newPass' value=" . $row['pass'] . "></td>";
echo "</tr>";
}
mysql_close($link)
?>