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

Updating mySQL field from form post is blank

Codes here !

Moderators: macek, egami, gesf

Updating mySQL field from form post is blank

Postby KonkorFour » Wed Feb 20, 2013 2:13 am

So I have a login page that once logged in sets your username as a session variable, once logged in it takes me to "me.php" this is a test page. I have a form where I have one text field and one button, the text fields id and name are "status" and I have this code in the "status-update.php" that it calls.

Code: Select all
<?php
SESSION_START();

//WAMP Login Details
$host = "localhost";
$username="root";
$password="";
$db_name="database";
$tbl_name="members";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("Database doesn't exist.");

//When a user logs in on the login page it sets the session for Username
$username=$_SESSION['myusername'];

//This grabs the data from the form on the settings page and updates
$sql="UPDATE $tbl_name SET status='$status' WHERE username='$username'";
$result=mysql_query($sql);

//if true then redirect else echo error
if($result){
header("location:me.php");
}

else {
echo "ERROR";
}
?>


Now it seems to work fine the only problem is, is that it updates the field with an empty variable. Am I doing something wrong here? The column name is "status".
KonkorFour
New php-forum User
New php-forum User
 
Posts: 3
Joined: Wed Feb 20, 2013 2:09 am

Re: Updating mySQL field from form post is blank

Postby KonkorFour » Fri Feb 22, 2013 1:20 am

Anyone?
KonkorFour
New php-forum User
New php-forum User
 
Posts: 3
Joined: Wed Feb 20, 2013 2:09 am

Re: Updating mySQL field from form post is blank

Postby KonkorFour » Fri Feb 22, 2013 2:27 am

Nevermind, I fixed it.
KonkorFour
New php-forum User
New php-forum User
 
Posts: 3
Joined: Wed Feb 20, 2013 2:09 am

Re: Updating mySQL field from form post is blank

Postby php9 » Fri Feb 22, 2013 2:49 am

The problem is you haven't defined $status anywhere, so it will always be blank.
php9
New php-forum User
New php-forum User
 
Posts: 13
Joined: Fri Feb 22, 2013 2:20 am


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 1 guest

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