forms and $_Post (I know you've never heard this one b4)

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply

How easy is it to transition from Visual Basic to PHP?

Effortless
0
No votes
Easy
0
No votes
Not Bad
4
100%
Difficult
0
No votes
NEVER
0
No votes
 
Total votes: 4

DickWeed
Forum Newbie
Posts: 3
Joined: Tue Jan 05, 2010 6:16 pm

forms and $_Post (I know you've never heard this one b4)

Post by DickWeed »

Hello Board,

I’m new here and sort of new to php. I’m just getting my head around it now and have, what I think is, such a common problem.

Here's the scoop:
Latest PHP
Latest MySQL DB
trblticket.php is where my form resides.
db_config.php is where my connection string resides.
trbltckinsert.php is where my insert statement and handlers reside.

Successfully created a form and script to process/handle it, insert it...... when passing only text.
Then I adjusted my new table to work with the rest of my database.
PROBLEM is I neglected to think about the need to insert allot of my form data as datetime, int(10), tinyint, and varchar and I can't for the life of me get them all handled.

I assume thats what I need..... a handler. I got a checkbox to work by using
$RushJob_opts = $_POST['RushJob'][0];

I don't even want to mention everything I;ve tried.

Could someone kindly tell me how to "handle" passing
1.) m-d-Y datetime to format Y-m-d H:m:s
2.) insert todays date
3.) insert todays date + 2 days
4.) a number to int(10)
5.) 0 or 1 to tinyint
6.) number to smallint

Here is a small sample of my form. And a small sample of my code

From FORM:

Code: Select all

<li class="mainForm" id="fieldBox_8">
<label class="formFieldQuestion">start_date</label><input type=text  name=start_date id=start_date value="">
<button type=reset class=calendarStyle id=fieldDateTrigger_8></button>
<SCRIPT type='text/javascript'>   Calendar.setup({
        inputField     :    "start_date",   
        ifFormat       :    "%m/%d/%Y",   
        showsTime      :    false,          
        button         :    "fieldDateTrigger_8",
        singleClick    :    true,           
        step           :    1                
});</SCRIPT></li>
 

Code: Select all

 
From FORM: Need this to be int(10)
 <input type=hidden  name=parent_id id=parent_id value="0"> 


And here is some of the trbltckinsert.php

Code: Select all

 
 
include("db_config.php");
$link = mysql_connect($db_host,$db_user,$db_pass);
if(!$link) die ('Could not create ticket.  Could not connect to DB: '.mysql_error());
mysql_select_db($db_name,$link);
$query = "INSERT into `".$db_table."` (Name,Email,Phone,parent_id,title,text,due_date,start_date,assigned_to_company_id,assigned_to_user_id,assigned_on,assigned_by_id,time_estimate,completed_on,completed_by_id,created_on,created_by_id,updated_on,updated_by_id,trashed_on,trashed_by_id,archived_on,archived_by_id,started_on,started_by_id,priority,state,order,milestone_id,is_private,is_template,from_template_id,repeat_end,repeat_forever,repeat_num,repeat_d,repeat_m,repeat_y,repeat_by,object_subtype, RushJob) VALUES ('" . $_POST['Name'] . "','" . $_POST['Email'] . "','" . $_POST['Phone'] . "','" . $_POST['parent_id'] . "','" . $_POST['title'] . "','" . $_POST['text'] . "','" . $_POST['due_date'] . "','" . $_POST['start_date'] . "','" . $_POST['assigned_to_company_id'] . "','" . $_POST['assigned_to_user_id'] . "','" . $_POST['assigned_on'] . "','" . $_POST['assigned_by_id'] . "','" . $_POST['time_estimate'] . "','" . $_POST['completed_on'] . "','" . $_POST['completed_by_id'] . "','" . $_POST['created_on'] . "','" . $_POST['created_by_id'] . "','" . $_POST['updated_on'] . "','" . $_POST['updated_by_id'] . "','" . $_POST['trashed_on'] . "','" . $_POST['trashed_by_id'] . "','" . $_POST['archived_on'] . "','" . $_POST['archived_by_id'] . "','" . $_POST['started_on'] . "','" . $_POST['started_by_id'] . "','" . $_POST['priority'] . "','" . $_POST['state'] . "','" . $_POST['order'] . "','" . $_POST['milestone_id'] . "','" . $_POST['is_private'] . "','" . $_POST['is_template'] . "','" . $_POST['from_template_id'] . "','" . $_POST['repeat_end'] . "','" . $_POST['repeat_forever'] . "','" . $_POST['repeat_num'] . "','" . $_POST['repeat_d'] . "','" . $_POST['repeat_m'] . "','" . $_POST['repeat_y'] . "','" . $_POST['repeat_by'] . "','" . $_POST['object_subtype'] . "','" . $_POST[‘RushJob’] . "')";
VALUES ('" . $_POST['Name'] . ";
mysql_close($link);
 


THANKS IN ADVANCE!
DickWeed
Forum Newbie
Posts: 3
Joined: Tue Jan 05, 2010 6:16 pm

Re: forms and $_Post (I know you've never heard this one b4)

Post by DickWeed »

Still looking for some help on this....

Need to pass the following in the respective mysql format from a forms string of data using $_Post
How do I create an array / handler to do this?
1.) m-d-Y datetime to format Y-m-d H:m:s
2.) insert todays date
3.) insert todays date + 2 days
4.) a number to int(10)
5.) 0 or 1 to tinyint
6.) number to smallint

Thanks in advance!
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: forms and $_Post (I know you've never heard this one b4)

Post by AbraCadaver »

DickWeed wrote:Still looking for some help on this....

Need to pass the following in the respective mysql format from a forms string of data using $_Post
How do I create an array / handler to do this?
1.) m-d-Y datetime to format Y-m-d H:m:s
2.) insert todays date
3.) insert todays date + 2 days
4.) a number to int(10)
5.) 0 or 1 to tinyint
6.) number to smallint

Thanks in advance!
I'm not sure I understand but I'll take a stab at it:

1.) pass the var to strtotime() and then pass the time to date() to format
2.) date() with format
3.) strtotime('+2 days') then pass the time to date() to format

For 4, 5, and 6 I guess you would have to lookup what are the restrictions on those field types and check the var if it is within those constraints and if not chop it, but that seems weird. All $_POST values come in as a string, so I would just cast them to an integer: (int)$_POST['whatever']. BTW, you really need to run all of those vars through mysql_real_escape_string().
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply