Jump to content

php UPDATE code


dennell

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

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.

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