0

So I have a form and the form action= the file that contains the code below. I am getting a connection but the data is not saving. I formatted my form with input type textarea and the database with long text because I want to give the user as much space as they need to write their information. I think this might be my issue and have been searching the web to see if it is but I can't find anything that says it is or not. The weird part is that one time i did see an increase in the row of the database but when I checked it the row didn't contain the info I sent, it was blank.

 <?php 
    session_start();

    if (strlen($_POST['recipe'])|| strlen($_POST['usrtext'])||strlen($_POST['usrtxt'])    ='0')
    {header('location:shareerror.php');}  
    else
    {
     $connection = mysql_connect("localhost","root","")
    or die("no connection");
    $db_select=mysql_select_db("smqr",$connection)
    or die("no connection to db");


    $query=mysql_query("INSERT INTO seafood(`recipe`,`usrtext`,'usrtxt')
    VALUES('$recipe','$usrtext''$usrtxt')");

    header ('location:thanks.php'); }

    ?>
Anish
  • 4,262
  • 6
  • 36
  • 58

4 Answers4

1

By mistake you are assigning instead of checking corrected statement is:

if (strlen($_POST['recipe'])|| strlen($_POST['usrtext'])||strlen($_POST['usrtxt']) ==0)
Vipin Kumar Soni
  • 826
  • 10
  • 18
0

There is an error in your query

 $query=mysql_query("INSERT INTO seafood(`recipe`,`usrtext`,'usrtxt')
    VALUES('$recipe','$usrtext''$usrtxt')");

change this to

 $query=mysql_query("INSERT INTO seafood(`recipe`,`usrtext`,`usrtxt`)
    VALUES('$recipe','$usrtext','$usrtxt')");
Anish
  • 4,262
  • 6
  • 36
  • 58
0

You are not setting the values for $recipe, $usrtext and $usrtxt

You are missing a comma in the values.

You are using strlen instead of isset

Also please take a look at How can I prevent SQL injection in PHP?. Your code is vulnerable to sql injection.

Here is the fixed code (with sql injection vulnerability intact!!)

 <?php 
    session_start();

    if (!isset($_POST['recipe'])|| !isset($_POST['usrtext'])||!isset($_POST['usrtxt']))
    {
        header('location:shareerror.php');
    }  
    else
    {
        $connection = mysql_connect("localhost","root","")
        or die("no connection");

        $db_select=mysql_select_db("smqr",$connection)
        or die("no connection to db");

        $recipe = $_POST['recipe'];
        $usrtext = $_POST['usrtext'];
        $usrtxt = $_POST['usrtxt'];

        $query=mysql_query("INSERT INTO seafood(`recipe`,`usrtext`,'usrtxt')
        VALUES('$recipe','$usrtext','$usrtxt')");

        header('location:thanks.php'); 
    }
?>
Community
  • 1
  • 1
Kinjal Dixit
  • 7,777
  • 2
  • 59
  • 68
0

Also you didn't assign the variables used in the query.

$query=mysql_query("INSERT INTO seafood(`recipe`,`usrtext`,`usrtxt`)
VALUES('$recipe','$usrtext','$usrtxt')");

do that like this:

$recipe = $_POST['recipe'];
$usrtext = $_POST['usrtext'];
$urstxt = $_POST['usertxt'];

Then you can use the variables in the query

Kevinvhengst
  • 1,672
  • 4
  • 27
  • 40