I'm making a profile updating page, and it doesn't work. To do it, I check if the table user_info
has already information; if yes, I update the info with the mysql UPDATE
query, else, I insert the new information.
I get the error "Error" all the time.
P.S:
- This is not a registration page, registration is made on another table.
- The $new_name variable I'm planning to answer it in another table, the basic table.
<?php
session_start();
include('include/connection.php');
if (isset($_SESSION['id']))
{
$id = $_SESSION['id'];
$new_name = (isset($_POST['name']) ? $_POST['name'] : null);
$location = (isset($_POST['location']) ? $_POST['location'] : null);
$bio = (isset($_POST['bio']) ? $_POST['bio'] : null);
$job = (isset($_POST['job']) ? $_POST['job'] : null);
$birthday = (isset($_POST['birthday_year']) ? $_POST['birthday_year'] : null) . '-' . (isset($_POST['birthday_month']) ? $_POST['birthday_month'] : null) . '-' . (isset($_POST['birthday_day']) ? $_POST['birthday_day'] : null);
$phone = (isset($_POST['phone']) ? $_POST['phone'] : null);
$result_info = mysql_query("SELECT * FROM user_info WHERE(id='".$id."')");
$n_info = mysql_num_rows ($result_info);
if ( $n_info = 0 )
{
$q = mysql_query ("INSERT INTO user_info (id , dateOfBirth , phoneNumber , bio , location , work) VALUES ('$id' , '$birthday' , '$phone' , '$bio' , '$location' , '$job' )")
;
}
else
{
$q = mysql_query ("UPDATE user_info (id , dateOfBirth , phoneNumber , bio , location , work) VALUES ('$id' , '$birthday' , '$phone' , '$bio' , '$location' , '$job' )")
;
}
$query = $q;
$req = $cnx->prepare($query);
$req->execute();
if ($query){
echo 'Yes';
}else{
echo 'Error';
}
}
else{
header('Location: index.php');
}
?>