Adding a row to a user

Hey guys,

I need some help with my php script. Actually my problem is, i have create a login that directs users to their profile page where they can see their data, in the user profile they can edit/delete and add a row to his data. Everything is working well but my add script is not working. everything you click add would add the new entry but create a id 0 (i have 2 tables user id and account) where in the user table id is primary key in each user is assign a int but no zero, example i log in with [email protected] (user id 3) log in -> home page add a row (would work but in my database table create (userd id 0) that info that i add would go to this user, would i like to get if a user id 3 add a row should this play the row right back to user. I know this is a silly problem or maybe my query its wrong PLEASE HELP
[php]

<?php session_start(); include('connect.php'); if(isset($_SESSION['logged_in'])){ $email = $_SESSION['email']; }else{ header("Location: index.php"); exit(); } function renderForm($id, $title, $note, $date_time, $alarm_type, $repeat_event, $error) { ?> New Reminder

Add a New Reminder

<?php // if there are any errors, display them if ($error != '') { echo '
'.$error.'
'; } ?>

Title: *

Note: *

Date & Time: *

Alarm Type: *

Repeat: *

* required

<?php } include "connect.php"; if(isset($_POST['submit'])){ if (is_numeric($_POST['id'])) { $id = $_POST['id']; $title = $_POST['title']; $note = $_POST['note']; $date_time = $_POST['date_time']; $alarm_type =$_POST['alarm_type']; $repeat_event = $_POST['repeat_event'];

if ($title == ‘’ || $note == ‘’ || $date_time ==’’ || $alarm_type ==’’ || $repeat_event ==’’)
{
// generate error message
$error = ‘ERROR: Please fill in all required fields!’;

// if either field is blank, display the form again
renderForm($id, $title, $note, $date_time, $alarm_type, $repeat_event, $error);
}
else
{
// save the data to the database
$result = $db->query(“INSERT INTO event (title, note, date_time, alarm_type, repeat_event) VALUES
(’”.$title."’,’".$note."’,’".$date_time."’,’".$alarm_type."’,’".$repeat_event."’)WHERE id =’".$id."’" )
or die(mysql_error());

$_SESSION[‘email’] = $email;
header(“Location: $email”);
exit();
}
}
else
// if the form hasn’t been submitted, display the form
{
renderForm(’’,’’,’’,’’,’’,’’,’’);
}}
?>
[/php]

Not sure what you are asking! I looked at your PHP code, and you have a function that includes HTML… This does not make sense because the HTML inside of PHP is just HTML. So, I do not understand your FUNCTION setup… PHP is server-side code. So, all PHP-FUNCTIONS are completely done inside one <?PHP...?> and not mixed up with HTML… Please rewrite your code to include any PHP functions as one item…

So, this means one function in PHP is like this:

<?PHP function name-of-function(arguments){ code that does the function calculations... } ?>

And, in some other PHP code later on, you use this code with $xyz=name-of-function(1,$xyz);
So, there is never any type of text or HTML in the middle of a function unless it is assigned into
a string…

Not sure of your code…

Let me explain my problem, let say you have registered into a reminder website after register (you’re assign a id ex: you are user id = 3) then you login and being direct to your home page where you can view all the list of your reminders and has the ability to add edit or delete a reminder. my script is working but the add script is not. When you (user id = 3) click add reminder you fill out the reminder form what it does it take the info and creates a user id = 0. So what actually i was working is when user id = 3 is in his profile page & add a reminder, this reminder should view create and display in the user id =3 home page.
Your Reminders
Hi [email protected], welcome back. Log out

Add a new reminder

Title Note Date & Time Alarm Type Repeat Action
Dinner at apple bees 01/01/2012 01:02:15 1 1 Edit Delete
Soccer Premier league 01/01/2012 02:02:02 2 2 Edit Delete

If you click add new reminder and fill out the form then submit and it should display something like:
Your Reminders
Hi [email protected], welcome back. Log out

Add a new reminder

Title Note Date & Time Alarm Type Repeat Action
Dinner at apple bees 01/01/2012 01:02:15 1 1 Edit Delete
Soccer Premier league 01/01/2012 02:02:02 2 2 Edit Delete
New Re This your new 05/05/2012 02:02:02 1 1 Edit Delete

But my add script
grab this info (New Re This your new 05/05/2012 02:02:02 1 1 Edit Delete)
and creates in my user table database user id 0

Okay, that makes sense. Now I understand…

Well, in your code:
// save the data to the database
$result = $db->query(“INSERT INTO event (title, note, date_time, alarm_type, repeat_event) VALUES
(’”.$title."’,’".$note."’,’".$date_time."’,’".$alarm_type."’,’".$repeat_event."’)WHERE id =’".$id."’" )
or die(mysql_error());

You did NOT include the $id in the INSERT. You will need to add that to the fields that you are writing into the new record. All data NOT included in the INSERT are set to default, which I would guess is zero. Also, since you are creating a new records in the EVENT table, you do not need the WHERE option. Just the INSERT! You need to be inserting the id, too… SO, it should be something like this:
[php]
// save the data to the database
$result = $db->query(“INSERT INTO event (id, title, note, date_time, alarm_type, repeat_event) VALUES
(’”.$id."’,’".$title."’,’".$note."’,’".$date_time."’,’".$alarm_type."’,’".$repeat_event."’)" )
or die(mysql_error());
[/php]
That should help you figure it out…

Thank you for your replied good catch but i guess i modified some because i’m getting a blank page after a click ADD umhhhhh

Sponsor our Newsletter | Privacy Policy | Terms of Service