简体   繁体   中英

update MySQL using PHP

Dear friends i am not an expert in php and need your help to solve an issue.

I am trying to create a page where i can call data from MySql and can edit/update it. The first part to display the data is done but i am unable to update it ... friends kindly help me solve this.

function Get_pages($mysql) {
$PageQuery = $mysql->query("SELECT * FROM pages WHERE PageID = '$pageID'");

    while (($row = $PageQuery->fetch_assoc()) !== null) 
        {
            echo '<form action="page.php" method="post">';
            echo '<span class="lbl">Page Title</span>';
            echo '<input name="PageTitle" type="text" value="' . $row["PageTitle"] . '" />';
            echo '<span class="lbl">Page Content</span>';
            echo '<textarea class="txt-area" name="PageContent" cols="" rows="18">' . $row["PageContent"] . '</textarea>';
            echo '<input name="UpdateBtn" value="Update Page" type="submit" class="submit_btn"></form>';
        }

  // WHEN BUTTON CLICKED
if ($_REQUEST['UpdateBtn'])
    {

        $pageID = $_REQUEST["$pageID"];             
        $PageTitle = addslashes($_REQUEST['PageTitle']);
        $PageContent = addslashes($_REQUEST['PageContent']);


        $sql = mysql_query ("UPDATE pages SET PageTitle='$PageTitle', PageContent='$PageContent' WHERE pageID='$pageID'") or die ("Not Updating");  
    }
}
$sql = mysql_query ("UPDATE

should be

$sql = $mysql->query("UPDATE

You are making connection with mysqli_* function and using mysql_* function for update , because of that your UPDATE is failing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM