Hazukiy Posted June 25, 2013 Share Posted June 25, 2013 (edited) Hi, I'm trying to make it so the user can enter some text into a text box and from there it will add a link and NOT override it. Here's my problem, I can't seem to get this statement to work correctly as I don't know how to put some kind of variable. Overall: I want it so it adds what ever has been entered into the INPUT tag and add into the correct user_id Please exuse my messy code, I'm just trying to get it to work before I tidy it up. Declared variables at the top of the document: class Users { public $user_id = null; public $username = null; public $email = null; public $password = null; public $salt = "Zo4rU5Z1YyKJAASY0PT6EUg7BBYdlEhPaNLuxAwU8lqu1ElzHv0Ri7EM6irpx5w"; public $links = null; public function __construct( $data = array() ) { if( isset( $data['user_id'] ) ) $this->user_id = stripslashes( strip_tags( $data['user_id'] ) ); if( isset( $data['username'] ) ) $this->username = stripslashes( strip_tags( $data['username'] ) ); if( isset( $data['email'] ) ) $this->email = stripslashes( strip_tags( $data['email'] ) ); if( isset( $data['password'] ) ) $this->password = stripslashes( strip_tags( $data['password'] ) ); if( isset( $data['links'] ) ) $this->links = stripslashes( strip_tags( $data['links'] ) ); } Here's what I've made: public function addLink() { $correct = false; try{ $con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD ); $con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); $sql = "UPDATE `a8906507_members`.`list_members` SET `links` = <SOME KIND OF VARIABLE HERE> WHERE `list_members`.`user_id` = <SOME KIND OF VARIABLE HERE> LIMIT 1"; $stmt = $con->prepare( $sql ); $stmt->bindValue( "links", $this->links, PDO::PARAM_STR ); $stmt->execute(); }catch( PDOException $e ) { return $e->getMessage(); } } Here's my HTML that connects to the public function and executes it. <form action="" method="post" name="add_link" id="add_link"> <table border="0" id="table-add"> <th colspan="2"> <h1>Add a livestream</h1> <?php if( !(isset( $_POST['add_link'] ) ) ) { ?> <?php } else { $usr = new Users; $usr->storeFormValues( $_POST ); $errorMessage = ""; $error = false; if( $usr->addLink() ) { echo 'Channel added!'; $error = false; } else { $errorMessage .= "<li class='error'>Link can't be added</li>"; $error = true; } if($error) { echo($errorMessage); } } ?> </th> <tr> <td> <p>Channel Name:</p> </td> <td> <input type="text" name="channel-name" class="frm-style" /> </td> </tr> <th colspan="2"> <input class="frm-submit-add" name="add_link" type="submit" value="Add" /> <th> </tr> </table> </form> Help will be appreciated, thanks. Edited June 25, 2013 by Hazukiy Quote Link to comment https://forums.phpfreaks.com/topic/279558-php-mysql-pdo-update-statement-problem/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.