Jump to content

PHP / MySQL PDO Update statement problem...


Recommended Posts

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;
				$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 );
			}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'] ) ) ) { ?>
		} 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;
	    <p>Channel Name:</p>
	    <input type="text" name="channel-name" class="frm-style" />
	   <th colspan="2">
	   <input class="frm-submit-add" name="add_link" type="submit" value="Add" />

Help will be appreciated, thanks.

Edited by Hazukiy
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.