I want to create a form that will update my database. I want the user to select name from the list and then enter the new values, on submission, in the table, the name will be modified which is selected.
FORM
<!DOCTYPE html>
<html>
<head>
<title>Logging | Warriors Elite</title>
<script src='https://code.jquery.com/jquery-2.1.3.min.js'></script>
</head>
<body><h1>Update Opposition War Details</h1>
<form method = "post" action = "updateopponent.php">
<p>Player Name: <select name="Name">
<?
$con = mysql_connect("localhost","db","pswd");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// Select database
mysql_select_db("978947") or die(mysql_error());
$cdquery="SELECT Name FROM opponent";
$cdresult=mysql_query($cdquery) or die ("Query to get data from firsttable failed: ".mysql_error());
while ($cdrow=mysql_fetch_array($cdresult)) {
$cdTitle=$cdrow["Name"];
echo "<option>
$cdTitle
</option>";
}
?>
</select>
</p>
<p>Clan Best Attacker
<input placeholder='#. Name' type='text' name='CBA' id='CBA' />
</p>
<p>Percentage(%)
<input type='text' name='percent' id='percent' />
</p>
<p>Stars Achieved
<input type='text' name='star' id='star' />
</p>
<button id='insert'>Submit</button>
<p id='result'></p>
</form>
<?php
}
?>
PHP
<?php
define('HOST','localhost');
define('USERNAME', 'db');
define('PASSWORD','pswd');
define('DB','');
$con = mysqli_connect(HOST,USERNAME,PASSWORD,DB);
$sql="UPDATE opponent SET Clan Best attack='".$_POST['CBA']."', Stars Achieved='".$_POST['star']."', Damage percentage='".$_POST['percent']."' WHERE Name='".intval($_REQUEST['Name'])."'";
$result=mysql_query($sql)or
die ("this stuffedup");
mysql_close($conn);
?>
I am able to connect to database but on clicking submit it fails(This stuffedup)
<button id='insert'>Submit</button>that does nothing unless you're using JS/Ajax, which you're not.mysqli_MySQL API, but later usingmysql_, and those do NOT intermix.Clan Best attack-Stars Achieved-Damage percentagecontain spaces and will throw a syntax error. edit:mysql_close($conn);referencing an undefined variable.