PHP and SQL one page insert into database -
i have written php page form on submit button set action php form page.
<form id="form1" method="post" action="../control_lbs/lbs_trace.php">
the insert basic sql load information database.
the problem have every time open page sends blank information rows. there away can prevent happening?
$sql = "insert lbs_trace_etrack (lbs_msisdn, lbs_req_by, lbs_date_req, lbs_reason, lbs_station, lbs_cas, lbs_traced_by) values ('$_post[lbs_msisdn]','$_post[lbs_req_by]','$_post[lbs_date_req]','$_post[lbs_reason]' ,'$_post[lbs_station]','$_post[lbs_cas]','$_post[lbs_traced_by]')";
the above php action code
this new code , full code use
if ($con = mysql_connect($host, $username, $password)) { if ( !empty($_post["send"])) { $sql = "insert lbs_trace_etrack (lbs_msisdn, lbs_req_by, lbs_date_req, lbs_reason, lbs_station, lbs_cas, lbs_traced_by) values ('$_post[lbs_msisdn]','$_post[lbs_req_by]','$_post[lbs_date_req]','$_post[lbs_reason]','$_post[lbs_station]','$_post[lbs_cas]','$_post[lbs_traced_by]')"; if (mysql_query($sql, $con)) { $insertsuccessful = true; } else { echo $sql; echo "\n" . mysql_error($con); echo "mysql err no : " . mysql_errno($con); }
on refresh or page entry still gives me blank info on database
you need use isset()
see if $_post variables set. i've use $_post
in example below, suggest give submitbutton name (like example
) , use isset($_post['example'])
:
if( isset($_post) ){ $sql = "insert lbs_trace_etrack (lbs_msisdn, lbs_req_by, lbs_date_req, lbs_reason, lbs_station, lbs_cas, lbs_traced_by) values( '".$_post['lbs_msisdn']."', '".$_post['lbs_req_by']."', '".$_post['lbs_date_req']."', '".$_post['lbs_reason']."', '".$_post['lbs_station']."', '".$_post['lbs_cas']."', '".$_post['lbs_traced_by']."' )"; echo $sql; // echo see if has values // print_r($_post); // in case query still empty, uncomment this. show values in post array }
Comments
Post a Comment