I have php page that you can type in a number and then click the submit button and it should update the column in the table. The problem I have is that it isn't updating the value but just leaving an empty field.
Something seems to be wrong with this line.
$update = mysql_query("UPDATE sip SET callerid = '$new' WHERE name = $trial");
If I just change the $new to a number it works fine. If I echo $new I get a number. Also the $trial bit works fine.
The full code I have is below.
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<link href="/../site.css" rel="stylesheet">
</head>
<body>
<? include("../header.php") ?>
<div id="main">
<?php
session_start();
$trial = $_SESSION['random'];
echo "Random: ".$trial;
if(empty($_SESSION['random'])) {
header("Location:/site/home.php");
}
echo "<br />";
?>
<form action="customer_details.php" method="post">
Number: <input type="number" name="phone" id="phone" maxlength="4" min="1000" max="9999" />
<br /><br />
<input type="Submit" />
</form>
<?php
$link = mysql_connect('localhost', 'root', '');
mysql_select_db('test' , $link) or die("Unable to select database: asterisk" . mysql_error());
if(isset($_POST['phone']))
{
$phone = $_POST['phone'];
$result = mysql_query("SELECT * FROM table where number = '$phone'");
while ($row = mysql_fetch_array($result))
{
$data = $row['callerid'];
}
echo $phone;
if($phone = $data)
{
print '<script type="text/javascript">';
print 'alert("Number is already in database")';
print '</script>';
}
else {
$new = $phone;
$update = mysql_query("UPDATE sip SET callerid = '$new' WHERE name = $trial");
if(! $update )
{
die('Could not update data: ' . mysql_error());
}
else
{
print '<script type="text/javascript">';
print 'alert("New Data added");';
print 'window.location.href = "../home.php";';
print '</script>';
}
}
}
?>
<? include("../footer.php") ?>
</div>
</body>
</html>