Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Issues updating MySQL value

Codes here !

Moderators: macek, egami, gesf

Issues updating MySQL value

Postby AlienGhost » Mon Jul 09, 2012 4:58 pm

Hey, I have a MySQL database with the table 'users', and I want to allow users to post a description.
I have a form on another webpage, and I am sure that it is working.

The problem is that, in the following code, I am using the variable $text to update the MySQL. And, when the user submits, the value will not update unless I actually create a specific value to set.

Please excuse the terrible coding. I just want to make it functional before I organize/secure it.
Any help is appreciated, thanks :)

Code: Select all
<?PHP
session_start();
function upload() {


$text = $_POST['description'];
$userid = $_SESSION['user_id'];
$con = mysql_connect("localhost","**********","****");   //I starred these on purpose
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("1043896_db", $con);

mysql_query("UPDATE users SET description=$text
WHERE user_id=$userid");

}

if (isset($_POST['submit'])) {
upload();}
?>
AlienGhost
New php-forum User
New php-forum User
 
Posts: 2
Joined: Mon Jul 09, 2012 4:44 pm

Re: Issues updating MySQL value

Postby johnj » Mon Jul 09, 2012 7:29 pm

Please brush up you understanding on data manipulation language.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Issues updating MySQL value

Postby vinta » Mon Jul 09, 2012 10:08 pm

hi everyone!!!
i like it.thanks for sharing...
vinta
New php-forum User
New php-forum User
 
Posts: 2
Joined: Mon Jul 09, 2012 10:04 pm

Re: Issues updating MySQL value

Postby vinta » Mon Jul 09, 2012 10:17 pm

hiiiiiiiiii everyone!!!!
i like it.thanks for sharing....
Website Designer Los Angeles :D
vinta
New php-forum User
New php-forum User
 
Posts: 2
Joined: Mon Jul 09, 2012 10:04 pm

Re: Issues updating MySQL value

Postby rupali » Mon Jul 09, 2012 11:34 pm

hi,

there is an issue in the query as the description field is in text form so in query use '' to declare text variable,
code should be like this:

mysql_query("UPDATE users SET description='$text' WHERE user_id=$userid");
rupali
New php-forum User
New php-forum User
 
Posts: 140
Joined: Thu Oct 13, 2011 10:32 pm
Location: Chandigarh, INDIA

Re: Issues updating MySQL value

Postby johnj » Tue Jul 10, 2012 12:00 am

Another thing that you can try is:

change mysql_query("UPDATE users SET description=$text WHERE user_id=$userid");

to

$sql = "UPDATE users SET description=$text WHERE user_id=$userid";
echo $sql;
mysql_query($sql);

echo $sql will tell you whether $text and $userid has a value in it.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Issues updating MySQL value

Postby AlienGhost » Tue Jul 10, 2012 9:40 am

Both of those solutions had valid outcomes. Thanks a lot! :D
AlienGhost
New php-forum User
New php-forum User
 
Posts: 2
Joined: Mon Jul 09, 2012 4:44 pm


Return to mySQL & php coding

Who is online

Users browsing this forum: Bing [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.