PHP Update Query didnt works

I have one form text field in index.php and i fill 8080

http_port : <input size="5" name="http_port" value="3128">

and table 'squid' like this

no | tag | value

1 | http_port | 3128

when i click submit button its redirect to submit.php but the table didnt update the value or still 3128.

submit.php

<?php
include("conn.php");
$value = $_POST['http_port'];
$query = mysql_query("update squid set http_port='$value' where '$no'=1");
echo "Update was Succesful<br>
<a href=\"index.php\">Bac</a>";
?>

whats wrong with my script? Thanks and sorry for my bad english :)

Upvotes: 0

Views: 72

Answers (3)

Satyam Saxena
Satyam Saxena

Reputation: 571

$value is in single quotes so will not get the value of variable $value.

$sql = "update squid set http_port='".$value."'where no=1";

Upvotes: 0

Sunil Kumar
Sunil Kumar

Reputation: 1381

Try this:

index.html:

<html>
    <body>
        <form action="submit.php" method="post">
        http_port : 
            <input size="5" name="http_port" value="3128" />
            <input type="submit" />
        </form>
    </body>
</html>

submit.php:

<?php
    require("conn.php");
    if(isset($_POST['http_port']))
    {
        $value = $_POST['http_port'];

        //You should sanitize data before inserting into table
        $value = mysql_real_escape_string(htmlentities(strip_tags(trim($value))));
        $no="your table field name";
        $sql = "UPDATE squid SET http_port=".$value." where ".$no."=1";
        $query = mysql_query($sql) OR die("Err:".mysql_error());
        echo "Update was Successful<br /><a href=\"index.php\">Back</a>";
    }
    else
    {
        echo "Something else";
    }
?>

Upvotes: 0

CrazySabbath
CrazySabbath

Reputation: 1334

There's a mistake in your mysql_query call, it should be:

$query = mysql_query("update squid set tag ='$value' where no=1");

I haven't coded anything in PHP for ages, but there are plenty of tutorials for such simple MySQL/PHP forms. Code I provided updates tag column, and in similar way you can update other columns...

$query = mysql_query("update squid set value ='$value' where no=1 and tag = 'http_port'");

Upvotes: 1

Related Questions