Jump to content

not inserting into database


conan318

Recommended Posts

<form method="post" action="lastride.php" enctype="multipart/form-data">
<h2>Last ride report<h2>
<textarea name="last" rows="10" cols="100">
Add your last ride report here
</textarea>

 

<?php

mysql_connect("localhost", "", "")or die("cannot connect"); 
mysql_select_db("main")or die("cannot select DB");
$data=$_POST['last']; 
$data = mysql_real_escape_string($data);
$mk=date("Y/m/d");
$insert_nextride=mysql_query("INSERT INTO main.last  (id,ridereport,date) VALUES ('','$data','$mk')");
if($insert_nextride)

{
echo "Next Ride updated";
header("location:mb-admin.html");
die();}
else {
echo "error in registration".mysql_error(); 
}
?>

 

ridereport not inserting data into the database but the date is. thinking its something to do with that data not being passed from the from. had it working yesterday and now its broken lol

 

Link to comment
https://forums.phpfreaks.com/topic/244084-not-inserting-into-database/
Share on other sites

do you not have a form submit button? you will want to check if the form has been passed before you execute the insertion code, also you cannot output data before calling the header() function

 

<?php

mysql_connect("localhost", "", "")or die("cannot connect"); 
mysql_select_db("main")or die("cannot select DB");
$data=$_POST['last']; 
if(!empty($data){
$mk=date("Y/m/d");
$data = mysql_real_escape_string($data);
$insert_nextride=mysql_query("INSERT INTO last  (id,ridereport,date) VALUES ('','$data','$mk')");
if($insert_nextride){
header("location:mb-admin.html");
exit;
}
else {
echo "error in registration".mysql_error(); 
}
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.