Jump to content

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(); 
}
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.