dennell Posted April 6, 2013 Share Posted April 6, 2013 Hi Everyone I have followed a tutorial online : http://www.phpeasystep.com/mysql/9.html However running from localhost it doesn't seem to UPDATE the values in my database and table. I have tried this twice now and cannot get it to work. anyone have any ideas? Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 6, 2013 Share Posted April 6, 2013 I see the problem... It's... In your code... Which none of us can see. Quote Link to comment Share on other sites More sharing options...
dennell Posted April 6, 2013 Author Share Posted April 6, 2013 Hi, The code is in the linked tutorial which i included in my post. here is my code(which is the same code as the tutorial by the way). Theres 3 files but i think the file that is causing the aggro is the following: <?php $host="localhost"; // Host name $username="root"; // Mysql username $password="root"; // Mysql password $db_name="ryandb"; // Database name $tbl_name="test_mysql"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // update data in mysql database $sql="UPDATE $tbl_name SET name='$name', lastname='$lastname', email='$email' WHERE id='$id'"; $result=mysql_query($sql); // if successfully updated. if($result){ echo "Successful"; echo "<BR>"; echo "<a href='list_records.php'>View result</a>"; } else { echo "ERROR"; } ?> Basically the code echos success but when i check my database the update hasn't happened. Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 6, 2013 Share Posted April 6, 2013 That tutorial is relying on register_globals, which is BAD. BAD. If you had PHP error reporting set to show notices, you'd see some issues. Abandon that site. Look for something that is using mysqli or PDO, that will be recent enough to be useful. Quote Link to comment Share on other sites More sharing options...
dennell Posted April 6, 2013 Author Share Posted April 6, 2013 hmm since i'm new and trying to undertand php and mysql I fail what i should be using instead of "register_globals". I just wanted to try and get it to work.. but regardless of whether it's bad it's not doing what i thought it would do and just simply update data in my database. Finding a tutorial thats more recent using mysqli or PDO(??) seems to be hard to come by as i would have no idea if i had found it? Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 6, 2013 Share Posted April 6, 2013 A. A tutorial using PDO would say so. Same for MySQLi. However, where your code does mysql_connect("$host", "$username", "$password")or die("cannot connect"); with mysql_* functions, It would use mysqli_* functions. PDO would look like like this: $dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass); B. Turn on error reporting, set to E_ALL or -1. See my signature. C. Use the $_POST superglobal array. See the manual. Quote Link to comment 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.