script in file 1

<?php
// Check if he wants to register
// - Make sure that param exists
// - Check length 
if (isset($_POST['username']) && strlen($_POST['username']) > 0) {

    // Check if passwords match.
    // - Make sure that params exist
    // - Check length 
    // - Check matching
    if (!isset($_POST['password']) || 
        !isset($_POST['password2']) ||
        strlen($_POST['password']) === 0 || 
        $_POST['password'] !== $_POST['password2']) {
           die("Error - Passwords don't match. Please go back and try again.");
    }

    require_once("connect.php");

    // Set array of params
    $fields = array(
        'username' => $_POST['username'],
        'yname' => isset($_POST['yname']) ? $_POST['yname'] : '',
        'password' => $_POST['password'],
        'comments' => $_POST['comments'],
        'date' => $_POST['date'],
    );

    // Escape fields agains sql injection
    $fields = array_map('mysql_real_escape_string', $fields);

    // Check if member exists
    $exists = mysql_num_rows(mysql_query("SELECT * FROM tylted WHERE username='" . $fields['username'] . "'"));
    if ($exists === 0) {

        // Insert member in DB
        if (mysql_query("INSERT INTO `tylted` (`" . implode('`,`', array_keys($fields)) . "`) VALUES ('" . implode("','", array_values($fields)) . "')") !== false) {
            echo "Thanks " . $_POST['username'] . " Has Been Added To The Password Bank!<br />
            <a href='home.htm'>Click Here To Go Back</a>";
            exit();
        } else {
            die("Error - Couldn't register user.<a href='sub.htm'>Click Here To Go Back And Edit This</a>");
        }
    } else {
        die("Error - Member exists!<a href='home.htm'> Some One Beat You To It Click Here To Go Back</a>");
    }
}
?>

script in file 2

<?php
$host="mysql14.000webhost.com"; // Host name 
$username="a7864418_Users"; // Mysql username 
$password="javascript00"; // Mysql password 
$db_name="a7864418_Pass"; // Database name 
$tbl_name="tylted"; // 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");

// get value of id that sent from address bar
$id=$_GET['id'];

// Retrieve data from database 
$sql="SELECT * FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo $row['id']; // replace with real field name
    echo $row['username']; // replace with real field name
}
?>
<?php
mysql_close();
?>

<?php
$host="mysql14.000webhost.com"; // Host name 
$username="a7864418_Users"; // Mysql username 
$password="javascript00"; // Mysql password 
$db_name="a7864418_Pass"; // Database name 
$tbl_name="tylted"; // 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`.`$username` 
SET `works` = `works` + 1 WHERE `$db_name`.`id` = '".$id."'mysql_error()";
$result=mysql_query($sql);

// if successfully updated. 
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='list_records.php'>View result</a>";
}
?>
<?php
mysql_close();
?>

all i am
getting is "4test" back no "" and the table wtill wont update im trying to make it add +1 to a collum on my table named works the default value is 0 and i cant get it to add +1 say the value is 1 and someone clicks the image link the value changes to 2 adn another click it goes to 3 so on and so forth

yes this is my real connection info but its not my real mysql database its just to test code

why did you add this mysql_error() to $sql variable at line 40

Your query is formatted incorrectly, it should be

$sql="UPDATE `$tbl_name` SET `works` = `works` + 1 WHERE `id` = '".$id."'" or die(mysql_error());
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.