Page 1 of 1
insert statement
Posted: Tue Feb 01, 2005 11:48 am
by twb
Hi, If someone could help me it would be appreciated,
I have a form that has 4 textboxes anda function that takes the input from these and adds it to a mysql db. My problem is my INSERT statement dosen't seem to work:
The code is as follows
Code: Select all
function Add_new_details($task_name,$task_description,$task_date,$task_time){
$query = "INSERT INTO calander (task_name, task_description, task_date, task_time) ";
$query .= "VALUES ('$task_name', '$task_description','$task_date','$task_time') ";
echo $query;//this prints out a empty set for the VALUES
$result = mysql_query($query);
echo $result; //this prints out "1"
if(!$result){
echo "Error in search for results:".mysql_error();
//exit();
}
}
The function call is as follows:
Code: Select all
Add_new_details($task_name,$task_description,$task_date,$task_time);
The function when called dosen't recieve the values of the variables...I'M not sure why?
I can manually insert into the db, so I know it can be done.
Thank you for your time
twb
Posted: Tue Feb 01, 2005 11:58 am
by magicrobotmonkey
try echo-ing out the query and seeing what its actually doing
Posted: Tue Feb 01, 2005 12:00 pm
by feyd
how are the varibles set up that are being passed into this function? that's where the error probably lies.
insert statement
Posted: Tue Feb 01, 2005 12:04 pm
by twb
Yes I did do that already and it returns empty values. I also echoed out the variables in the function call and they also have empty values, so I gather thats where my problem is. I declared the variables as follows
//get variables
Code: Select all
$task_name = isset($_POSTї'task_name'])? $_POSTї'task_name'] : "";
$task_date = isset($_POSTї'task_date'])? $_POSTї'task_date'] : "";
$task_time = isset($_POSTї'task_time']) ? $_POSTї'task_time'] : "";
$task_description = isset($_POSTї'task_description']) ? $_POSTї'task_description'] : "";
I'm not sure why the variables arn't being set from the text boxes
thanks
twb
Posted: Tue Feb 01, 2005 12:06 pm
by magicrobotmonkey
var_dump($_POST) and see what that tells you
Posted: Tue Feb 01, 2005 12:07 pm
by feyd
you wrote //get variables.. yet you use $_POST, are you sure they are being posted?
Posted: Tue Feb 01, 2005 12:11 pm
by magicrobotmonkey
i think he meant like "Get the variables" not "these are the GET variables"
Insert Statement
Posted: Tue Feb 01, 2005 12:15 pm
by twb
I am sure that is where my problem is, that these variables arn't being POSTED, that what I can't figure out why. Althought I am new to this I can't see the difference to what Iv'e done in the past.
Thanks twb
Posted: Tue Feb 01, 2005 12:26 pm
by feyd
what's the html form that submits to this script/codepath?
Posted: Tue Feb 01, 2005 1:05 pm
by magicrobotmonkey
if that was your inset statement in that other thread:
Code: Select all
tr><td>Date:
<input name="task_date" type="text" size="10"></td></tr>
<tr><td>Time:
<input type="text" name="task_time" size="20"></td></tr>
<tr><td>Task Name:
<input type="text" name="task_name" size="50"> </td></tr>
<tr></tr><td>Description:
<input type="text" name="task_description" size="50"></td></tr>
you have no <form> tags - and if you just left them off, that would be the part we need to see and if you actually don't have them, that's your problem
insert statement
Posted: Tue Feb 01, 2005 2:26 pm
by twb
magicrobotmonkey
sorry for the confusion..
the full html is as follows
Code: Select all
<body>
<table width="800" border="1">
<tr><td align="center"><p><strong> Calander Details:</strong></p>
</tr>
<tr><td>Date:
<input name="task_date" type="text" size="10"></td></tr>
<tr><td>Time:
<input type="text" name="task_time" size="20"></td></tr>
<tr><td>Task Name:
<input type="text" name="task_name" size="50"> </td></tr>
<tr></tr><td>Description:
<input type="text" name="task_description" size="50"></td></tr>
<td><table border="1" width="261">
<form name="form1" method="post" action="">
<tr>
<td width="100"><input type="submit" name="Submit" value="Submit"></td>
<td width="100"><input type="submit" name="Submit" value="null"></td>
<td width="50"><input type="hidden" name="action" id="action" value="CHECK"></td>
</form>
</tr>
</table></td>
</table>
</body>
the function call above this is as follows:
//Get ACTION Variable
Code: Select all
$action = isset($_POSTї'action']) ? $_POSTї'action'] : '';
Code: Select all
//If action equal 'CHECK' then the user has submitted data to checking
if (strtoupper($action) == 'CHECK') {
//function call to insert into the db
Add_new_details($task_name,$task_description,$task_date,$task_time);
}//CLOSE IF
thanks
twb
Posted: Tue Feb 01, 2005 2:36 pm
by magicrobotmonkey
right you have no <form> tags on your page. You need some.
http://www.w3.org/TR/REC-html40/interact/forms.html
insert statement
Posted: Tue Feb 01, 2005 2:42 pm
by twb
hmmmm I thought that
Code: Select all
<form name="form1" method="post" action="">
<tr>
<td width="100"><input type="submit" name="Submit" value="Submit"></td>
<td width="100"><input type="submit" name="Submit" value="null"></td>
<td width="50"><input type="hidden" name="action" id="action" value="CHECK"></td>
</form>
was my form tag... however I will read up on the link you supplied,
thanks
twb
Posted: Tue Feb 01, 2005 3:02 pm
by magicrobotmonkey
oh i didnt even see that there. d'oh. the problm is that all inputs need to be within the form tag and i think you are going to need something in action, but I'm not sure
insert statement
Posted: Tue Feb 01, 2005 3:12 pm
by twb
magicrobotmonkey
THATS IT!!!
I moved the form tag to include the the input and it works like a charm
Thanks for your help and patients
TWB