Hi,
I have a form that a registered user needs to fill out to upload pricing or update pricing. The form is processed by a php script that connects to my database and then needs to check to see if the user has pricing already stored or if it needs to just insert it as new. So far I've got what I thought would work, but nothing is going into the row and I'm getting no error messages. My code thus far is as follows:
session_start ();
require_once ('mysql_connect.php'); // Connect to the database.
extract($_POST);
$user_id = ($_SESSION['user_id']);
$result = mysql_query("SELECT * FROM users WHERE user_id = '$user_id'");
if(mysql_num_rows($result)) {
$sql = "UPDATE $user_id
SET city_1 = '".($_POST['city'])."".($_POST['city2'])."".($_POST['pair_1_price'])."',
city_2 = '".($_POST['city'])."".($_POST['city2'])."".($_POST['pair_2_price'])."',
city_3 = '".($_POST['city'])."".($_POST['city2'])."".($_POST['pair_3_price'])."',
city_4 = '".($_POST['city'])."".($_POST['city2'])."".($_POST['pair_4_price'])."',
WHERE user_id = $user_id";
if (!mysql_query($sql)) {
$confirm = "Update failed:".mysql_error();
} else {
$confirm = "Update successful";
}
} else {
$sql = "INSERT INTO $user_id
SET city_1 = '".($_POST['city'])."".($_POST['city2'])."".($_POST['pair_1_price'])."',
city_2 = '".($_POST['city'])."".($_POST['city2'])."".($_POST['pair_2_price'])."',
city_3 = '".($_POST['city'])."".($_POST['city2'])."".($_POST['pair_3_price'])."',
city_4 = '".($_POST['city'])."".($_POST['city2'])."".($_POST['pair_4_price'])."',
WHERE user_id = $user_id";
if (!mysql_query($sql)) {
$confirm = "Submission failed:".mysql_error();
} else {
$confirm = "Submission successful";
}
}
I've been trying to figure this out for days now utilizing forums and books and have not been able to get past this problem. I am new to MySql and PHP so I appreciate any help I can get.
Thanks!