Cannot replace String with default value

PHP code

<?php
    header("Access-Control-Allow-Origin: *");
    require 'dbconnect.php';
    $conn=new mysqli($server,$user,$pass,$dbname);
    $m=$_POST['no2'];
    $sql = "INSERT INTO Users(no1,no2,Shop_id,Price) VALUES('".$_POST['no1']."','str_replace("+","0",'$m')','".$_POST['Shop_id']."','".$_POST['Price']."')";
    $result=mysqli_query($conn,$sql);
    if(!$result){
        /* check for error, die, etc */
        echo "string";
    }

    $conn->close();
 ?>

I want to replace the string received from the query POST($m)with a string that does not contain '+' ie remove '+' from the string.

I tried replacing it with "0" (after all hope), but still not showing what I intend to see

Say $m=+12345I want it to be $m=12345when pasted into the database

Help me that. I am a lot of newbie.

+4
source share
2 answers

This is a message that you can get + in value, otherwise you will receive SPACE in the query string.

Concatenation Problem

$m=str_replace("+","0",$_POST['no2']);
$sql = "INSERT INTO Users(no1,no2,Shop_id,Price) VALUES('".$_POST['no1']."','".$m."','".$_POST['Shop_id']."','".$_POST['Price']."')";
+3
source

$sql = "INSERT INTO Users(no1,no2,Shop_id,Price) VALUES('".$_POST['no1']."','str_replace("+","0",'$m')','".$_POST['Shop_id']."','".$_POST['Price']."')"; $sql = "INSERT INTO Users(no1,no2,Shop_id,Price) VALUES('".$_POST['no1']."','".str_replace("+","0",$_POST['no2'])."','".$_POST['Shop_id']."','".$_POST['Price']."')";. .

+1

Source: https://habr.com/ru/post/1616312/


All Articles