MySQL Forums
Forum List  »  PHP

PHP and HTML combo single page for MySQL Record Update
Posted by: Eric Hilding
Date: May 25, 2019 03:28PM

I have hacked together several script examples attempting to get a single page HTML and PHP combo for updating a single MySQL Record with multiple columns to be used as a Configuration Master for displaying or not displaying data on some other webpages.

Being somewhat of a "NOOB", I've embedded several // ///NOTES/// where I am not sure what to do. I may have also put too many 'require' duplicates in the code. Right now, pressing the SUBMIT (Update the Record) button does not work.

Thanks for any assistance!

--------------------------

<?php

require '/home/xxxx/yyyy/zzzz_mysqli.php'; // db pwd info etc.

if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}

if(isset($_POST['Submit'])){ //if the submit button is clicked

$showit = $_POST['showit'];
$text1 = $_POST['text1'];
$text2 = $_POST['text2'];
$text3 = $_POST['text3'];
$text4 = $_POST['text4'];
$text5 = $_POST['text5'];

// /////////////////////////////////////////////////////////////////////////
// TESTING - the actual values to be used need to come from the FORM choices

$sql = "UPDATE leshow SET showit='$showit', text1='$text1', text2='$text2', text3='$text3', text4='$text4', text5='$text5'";

// /////////////////////////////////////////////////////////////////////////////////

$result = mysqli_query($con,$sql);

mysqli_close($con);

}
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title></title>
</head>
<body>

<?php

require '/home/xxxx/yyyy/zzzz_mysqli.php'; // db pwd info etc.

if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}

//Create a query

$sql="SELECT * FROM leshow";

//submit the query and capture the result
$result = mysqli_query($con,$sql);

while ($db_field = mysqli_fetch_assoc($result) ) {

$showit = $db_field['showit'];
$text1 = $db_field['text1'];
$text2 = $db_field['text2'];
$text3 = $db_field['text3'];
$text4 = $db_field['text4'];
$text5 = $db_field['text5'];

mysqli_close($con);

}

?>
<h2>Update leshow Table Records</h2>

<br />


<form action="" method="post">
<?php

require '/home/xxxx/yyyy/zzzz_mysqli.php'; // db pwd info etc.

if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}

$sql="SELECT * FROM leshow";

$result = mysqli_query($con,$sql);

while ($row = $result->fetch_assoc()) {

?>

<table border="0" cellspacing="10">


<!--
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
What I want to use first instead of a single text input field is a DDL option list with 2 choices: YES (or) NO
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
-->
<tr>
<td>showit column value:</td> <td><input type="text" name="showit" value="<?php echo $row['showit']; ?>"></td>
</tr>
<!-- //////////////////////////////////////////////////////////////////////////////////////////////////////// -->

<tr>
<td>Text1 column value:</td> <td><input type="text" name="text1" value="<?php echo $row['text1']; ?>"></td>
</tr>

<tr>
<td>Text2 column value:</td> <td><input type="text" name="text2" value="<?php echo $row['text2']; ?>"></td>
</tr>

<tr>
<td>Text3 column value:</td> <td><input type="text" name="text3" value="<?php echo $row['text3']; ?>"></td>
</tr>

<tr>
<td>Text4 column value:</td> <td><input type="text" name="text4" value="<?php echo $row['text4']; ?>"></td>
</tr>

<tr>
<td>Text5 column value:</td> <td><input type="text" name="text5" value="<?php echo $row['text5']; ?>"></td>
</tr>

<tr>
<td><INPUT TYPE="Submit" VALUE="Update the Record" NAME="Submit"></td>
</tr>
</table>
<?php

}

mysqli_close($con);

?>
</form>

<?php
// //////////////////////////////////////////////////////////////////////
// THIS SHOULD *NOT* DISPLAY UNTIL AFTER THE SUBMIT BUTTON IS PRESSED !!!
// //////////////////////////////////////////////////////////////////////
if($result !== FALSE)
{
echo("The record has been updated.");
}else{
echo("The record has NOT been updated.");
}
?>

</body>
</html>

Options: ReplyQuote


Subject
Written By
Posted
PHP and HTML combo single page for MySQL Record Update
May 25, 2019 03:28PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.