Jump to content

Mickeyatty

New Members
  • Content Count

    4
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Mickeyatty

  • Rank
    Newbie
  1. Hi, I am just getting a blank page and I am unable to figure out why such a simple concept is not working. Any help would be greatly appreciated. <?php //Error Check ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); try { $conn = new PDO("mysqli:host=$servername;dbname=$dbname", $username, $password); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $statement = $conn->prepare("UPDATE test SET title= ? WHERE id= ?"); $statement->bind_param('si', $title,$id); $statement->execute(); if ($statement->affected_rows >0) { echo "Record updated successfully"; } else { echo "Error updating record: " . $conn->error; } $statement->close(); ?>
  2. I found it online. Just wanted a simple code to use to test a sql update. I have created a prepared stmt script. No help is needed on this.
  3. yeah, i know. I am trying to learn how to create update scripts. I start with the basic concept then build off.
  4. Hi, I am stumped, my code just gives me the error "Could not update data". I can't see any issues with my code, so I need another set of eyes. I am not getting any syntax error. Can anyone help point me where I have missed something? -Thanks <?php if(isset($_POST['update'])) { $dbhost = 'mysql'; $dbuser = 'user'; $dbpass = 'pass'; $conn = mysqli_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Could not connect: ' . mysqli_error()); } $id = $_POST['id']; $title = $_POST['title']; $sqli = "UPDATE test ". "SET title = $title ". "WHERE id = $id" ; mysqli_select_db('test'); $retval = mysqli_query( $sqli, $conn ); if(! $retval ) { die('Could not update data: ' . mysqli_error()); } echo "Updated data successfully\n"; mysqli_close($conn); }else { ?> <form method = "post" action = "<?php $_PHP_SELF ?>"> <table width = "400" border =" 0" cellspacing = "1" cellpadding = "2"> <tr> <td width = "100">ID</td> <td><input name = "id" type = "text" id = "id"></td> </tr> <tr> <td width = "100">Title</td> <td><input name = "title" type = "text" id = "title"></td> </tr> <tr> <td width = "100"> </td> <td> </td> </tr> <tr> <td width = "100"> </td> <td> <input name = "update" type = "submit" id = "update" value = "Update"> </td> </tr> </table> </form> <?php } ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.