Jump to content

User input not being added/updated to SQL database


AshleighCo

Recommended Posts

I have searched over 1500 posts over the last 2 weeks and have not found the solution to make my code work. My registration and login forms work correctly but when the user logins to add or edit information the  sql database does not update with the users input and the error/updated message does not echo. My users register with name, surname, email and password but once they login they need to add to their personal information and later be able to edit the personal information. But nothing I've tried has worked... my code is as follows:

 

<?php
include_once "connect_to_mysql.php";
$id = $_SESSION['id'];

if ($_POST['username']) {
$title = $row["title"];
$username = $row["username"];
$surname = $row["surname"];
$identityno = $row["identityno"];
$gender = $row["gender"];
$birthdate = strftime("%d %b %Y", strtotime($row["birthdate"]));
$ethnicity = $row["ethnicity"];
$nationality = $row["nationality"];
$homeaddress = $row["homeaddress"];
$province = $row["province"];
$suburb = $row["suburb"];
$hometele = $row["hometele"];
$celltele = $row["celltele"];
$creditclear = $row["creditclear"];
$criminalrecord = $row["criminalrecord"];
$driverslicense = $row["driverslicense"];
$owntransport = $row["owntransport"];
$medicalconditions = $row["medicalconditions"];

$sql = mysql_query("UPDATE cic_candidates SET title='$title', username='$username', surname='$surname', identityno='$identityno', gender='$gender', birthdate='$birthdate', ethnicity='$ethnicity', nationality='$nationality', homeaddress='$homeaddress', province='$province', suburb='$suburb', hometele='$hometele', celltele='$celltele', creditclear='$creditclear', criminalrecord='$criminalrecord', driverslicense='$driverslicense', owntransport='$owntransport', medicalconditions='$medicalconditions' WHERE id='$id'");
    echo 'Your account info has been updated, you will now see the new info.<br /><br />
To return to your profile edit area, <a href="edit_personal_details.php">click here</a>';
exit();
}
?>

Link to comment
Share on other sites

<?php
include_once "connect_to_mysql.php";
$id = $_SESSION['id'];

if ($_POST['username']) {
$title = $row["title"];
$username = $row["username"];
$surname = $row["surname"];
$identityno = $row["identityno"];
$gender = $row["gender"];
$birthdate = strftime("%d %b %Y", strtotime($row["birthdate"]));
$ethnicity = $row["ethnicity"];
$nationality = $row["nationality"];
$homeaddress = $row["homeaddress"];
$province = $row["province"];
$suburb = $row["suburb"];
$hometele = $row["hometele"];
$celltele = $row["celltele"];
$creditclear = $row["creditclear"];
$criminalrecord = $row["criminalrecord"];
$driverslicense = $row["driverslicense"];
$owntransport = $row["owntransport"];
$medicalconditions = $row["medicalconditions"];

$sql = mysql_query("UPDATE cic_candidates SET title='$title', username='$username', surname='$surname', identityno='$identityno', gender='$gender', birthdate='$birthdate', ethnicity='$ethnicity', nationality='$nationality', homeaddress='$homeaddress', province='$province', suburb='$suburb', hometele='$hometele', celltele='$celltele', creditclear='$creditclear', criminalrecord='$criminalrecord', driverslicense='$driverslicense', owntransport='$owntransport', medicalconditions='$medicalconditions' WHERE id='$id'");
    echo 'Your account info has been updated, you will now see the new info.<br /><br />
To return to your profile edit area, <a href="edit_personal_details.php">click here</a>';
exit();
}
?>

Link to comment
Share on other sites

Yep, that's the same code you posted earlier alright. Congratulations on that?

What is $row supposed to be? The new values from the form? Then shouldn't it be $_POST instead?

 

I'm going to bed. If someone picks up from where I'm leaving off, remember to mention the SQL injection too.

Link to comment
Share on other sites

Okay....I have checked many online options and now have the following code with the following error: Fatal error: Function name must be a string....this refers to this line of my code: $query("UPDATE cic_candidates SET title='$title'

 

Code:

<?php
include_once "connect_to_mysql.php";

$id = $_SESSION['id'];

$title=$_POST['title'];
$username=$_POST['username'];
$surname=$_POST['surname'];
$identityno=$_POST['identityno'];
$gender=$_POST['gender'];

$birthdate=$_POST['birthdate'];
$ethnicity=$_POST['ethnicity'];
$nationality=$_POST['nationality'];
$homeaddress=$_POST['homeaddress'];
$province=$_POST['province'];
$suburb=$_POST['suburb'];
$hometele=$_POST['hometele'];
$celltele=$_POST['celltele'];
$creditclear=$_POST['creditclear'];
$criminalrecord=$_POST['criminalrecord'];
$driverslicense=$_POST['driverslicense'];
$owntransport=$_POST['owntransport'];
$medicalconditions=$_POST['medicalconditions'];

$query("UPDATE cic_candidates SET title='$title', username='$username', surname='$surname', identityno='$identityno', gender='$gender', birthdate='$birthdate', ethnicity='$ethnicity', nationality='$nationality', homeaddress='$homeaddress', province='$province', suburb='$suburb', hometele='$hometele', celltele='$celltele', creditclear='$creditclear', criminalrecord='$criminalrecord', driverslicense='$driverslicense', owntransport='$owntransport', medicalconditions='$medicalconditions' WHERE id='$id'");
mysql_query($query);

    echo 'Your account info has been updated, you will now see the new info.<br /><br />
To return to your profile edit area, <a href="edit_personal_details.php">click here</a>';
exit();
mysql_close();

?>

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.