Best way to design a question based ordering system for a home service application

I am working on a home service application with laravel and react where users can submit orders for different services.
When a user is going to submit an order, the application is going to ask him/her some questions about the service details (like how many pipes are broken, what time does he/she like the service to be done and so on.)
So I need to create a services table:

+---------+--------------+------+-----+---------+----------------+
| Field   | Type         | Null | Key | Default | Extra          |
+---------+--------------+------+-----+---------+----------------+
| id      | int unsigned | NO   | PRI | NULL    | auto_increment |
| name    | varchar(200) | NO   |     | NULL    |                |
+---------+--------------+------+-----+---------+----------------+

And an orders table:

+------------+--------------+------+-----+---------+----------------+
| Field      | Type         | Null | Key | Default | Extra          |
+------------+--------------+------+-----+---------+----------------+
| id         | int unsigned | NO   | PRI | NULL    | auto_increment |
| service_id | int unsigned | NO   |     | NULL    |                |
| user_id    | int unsigned | NO   |     | NULL    |                |
| address_id | int unsigned | NO   |     | NULL    |                |
+------------+--------------+------+-----+---------+----------------+

Then I have to create a service_questions table:

+------------+--------------+------+-----+---------+----------------+
| Field      | Type         | Null | Key | Default | Extra          |
+------------+--------------+------+-----+---------+----------------+
| id         | int unsigned | NO   | PRI | NULL    | auto_increment |
| service_id | int unsigned | NO   |     | NULL    |                |
| type       | varchar(30)  | NO   |     | NULL    |                |
| name       | varchar(200) | NO   |     | NULL    |                |
+------------+--------------+------+-----+---------+----------------+

Questions may or may not have options. So the type attribute can have multiple values, like: single_select, multi_select, timestamp (for dates), text, file and … .
So I need a service_question_options table:

+-------------+--------------+------+-----+---------+----------------+
| Field       | Type         | Null | Key | Default | Extra          |
+-------------+--------------+------+-----+---------+----------------+
| uuid        | uuid         | NO   | PRI | NULL    | auto_increment |
| question_id | int unsigned | NO   |     | NULL    |                |
| content     | varchar(255) | NO   |     | NULL    |                |
+-------------+--------------+------+-----+---------+----------------+

I created a uuid field as identifier for this table so I would be able to store it in a varchar type field in the following table. For storing user’s answers to the questions, I create an order_answers table, like this:

+-------------+----------------+------+-----+---------+----------------+
| Field       | Type           | Null | Key | Default | Extra          |
+-------------+----------------+------+-----+---------+----------------+
| id          | int unsigned   | NO   | PRI | NULL    | auto_increment |
| order_id    | int unsigned   | NO   |     | NULL    |                |
| question_id | int unsigned   | NO   |     | NULL    |                |
| option      | varchar(255)   | YES  |     | NULL    |                |
+-------------+----------------+------+-----+---------+----------------+

Now that I explained all the tables, I need to mention the problems that I encountered. First, I receive user’s answers in an array like this:

[
    'first_question_id' => [
                               'an_option_id',
                               'another_option_id',
                           ],
    'second_question_id' => 'a_long_text',
    'third_question_id' => 'a_timestamp',
    ...
]

As you can see above, because there are different types of questions, the users answers may include question option uuid, a text, a timestamp and so on. So my first problem is that I need to validate all the question ids and option ids that user has sent, but I think that takes a lot of reading from database and may take a long time.

My second problem is the option attribute field type in order_answers table. What field type should it have, so I can store different types of data in it (uuid, text, datetime, urls for files and …)? Is it the best way or should I create different columns for different types of user answers? for example:

+-------------+----------------+------+-----+---------+----------------+
| Field       | Type           | Null | Key | Default | Extra          |
+-------------+----------------+------+-----+---------+----------------+
| id          | int unsigned   | NO   | PRI | NULL    | auto_increment |
| order_id    | int unsigned   | NO   |     | NULL    |                |
| question_id | int unsigned   | NO   |     | NULL    |                |
| option_id   | uuid           | YES  |     | NULL    |                |
| text        | text           | YES  |     | NULL    |                |
| datetime    | timestamp      | YES  |     | NULL    |                |
+-------------+----------------+------+-----+---------+----------------+

But, in this way, I will have lots of null cells in the table.
My third question is how should I read user orders from database, so I do not have to make lots of joins? Should I create a view?
Actually, a solution came to my mind that I’m not sure of. Lets assume we create the order_answers table like this:

+-------------+----------------+------+-----+---------+----------------+
| Field       | Type           | Null | Key | Default | Extra          |
+-------------+----------------+------+-----+---------+----------------+
| id          | int unsigned   | NO   | PRI | NULL    | auto_increment |
| order_id    | int unsigned   | NO   |     | NULL    |                |
| question    | varchar(200)   | NO   |     | NULL    |                |
| option      | varchar(255)   | YES  |     | NULL    |                |
+---------+---------------+----+-----+---------+-----------------------+

Then I receive questions and user answers content and not uuid or id. So I will not need to validate them and When reading from database, there is no need for any joins. Is it a good solution?
What is your best design for an application like this?

PHP code not connecting HTML to MYsql database

hey there im new to php ……so i wanted to make a program in which my html form inputs are stored in the data base I followed a youtube tutorial to do this this is the link to it enter link description hereand heres the code i have written for the php file `<?php

$firstname = $_POST ['firstname'] ;
$email = $_POST ['email'];
$admin = $_POST ['admin'];
$school = $_POST ['school'];
$gender = $_POST ['gender'] ;

//DATABASE CONECTION
$conn = new mysqli('localhost', 'root', '', 'register');
if ($conn-> connect_error){
die ('connection error    :  ' . $conn-> connect_error);
}else{
$stmt = $conn->prepare("INSERT INTO register(firstname, email, admin, gender)
values(?, ?, ?, ?, ?)");
$stmt-> bind_param("ssiss", $firstname, $email, $admin, $gender);
$stmt-> execute();
echo"Registration succesfull";
$stmt-> close();
$conn-> close();
}`

and here is my database
enter image description here
and my html program
enter image description here
but when i run it the html form runs fine but the php program is just displayed on the screen without any output pls help me thanks

Getting menu value from MySQL

I added user register & login system into my website with PHP jQuery and MySQL. I want if the user logged in, at the main page menu change the login buttons value to the user’s name from MySQL.
I tried some sources from the internet but it didn’t work

by the way here’s the project : https://zafernci.xyz/uploadd/

1

My Menu:

    <a class="active" href="#">Home</a>
    <a href="#">Contact</a> 
    <a href="#">Products</a> 
    <a id="sign-up" href="#" onclick="SignUp()">Sign Up</a> 
       <?php if(isset($_SESSION["username"])): ?>
    <a href="logout.php">Logout  ///.$_SESSION["username"]. I tried this code but that too didn't work//// </a>
       <?php else: ?>
    <a id="log-in" href="#" onclick="LogIn()">Log In</a>
       <?php endif; ?> 
       </div>  

The Login System with MySQL:

if(isset($_POST["username"]) && isset($_POST["password"]))
{
 $username = mysqli_real_escape_string($connect, $_POST["username"]);
 $password = md5(mysqli_real_escape_string($connect, $_POST["password"]));
 $sql = "SELECT * FROM users WHERE username = '".$username."' AND Password = '".$password."'";
 $result = mysqli_query($connect, $sql);
 $num_row = mysqli_num_rows($result);
 if($num_row > 0)
 {
  $data = mysqli_fetch_array($result);
  $_SESSION["username"] = $data["username"];
  echo $data["username"];
 }
}

Dynamically generated PDFs not showing in certain browser

I use Ezpdf to generate invoices in pdf format. Last year everything was fine. Nothing has changed from the ezpdf code. Pdfs showed up on PC and Macs with no problem. This year, on certain browsers, a white page is shown instead of a pdf. To show how picky this is. On two macs (safari and Google) pdfs are generated perfectly. On another Mac the pdfs only show in Firefox. On certain Pcs they only show in Firefox but with misaligned margins at the top of page. I was wondering is anyone had come across something similar. Thank you.

Restrict live an input field comparing it to another field

I have a php page and these two inputs fields. My goal is to check if the second input is equal to first input (live) and make an error msg. The code i have so far is this:

<div class="input-group date" id="timepicker1"  
                                                                
    data-target-input="nearest">
    <input type="text" 

    class="form-control datetimepicker-input"
    data-target="#timepicker1"

    name="FirstDate" id="FirstDate"  />

</div>
<div class="input-group date" id="timepicker2"  
                                                                
    data-target-input="nearest">
    <input type="text" onclick="CheckForErrors()"

    class="form-control datetimepicker-input"
    data-target="#timepicker2"

    name="SecondDate" id="SecondDate"  />

</div>

In the end of the php i have a Javascript checking:

<script type="text/javascript">
    function CheckForErrors() {
      // Check if First Time is equal with second Time
      if (FirstDate == SecondDate) {
        alert("Error MSG!");
      }
      return false;
    }
</script>

Its not working, as u understand. Any help ?
PS. I’m a begginer so please be patient 😀

Why would wp_mail think it’s succeeding, but not actually send mail?

I am using the wp_mail function within WordPress, but it only works sometimes. When I look at the error log, it says that mail is succeeding. This function is also being used for another email being sent – but that one works (at least sometimes, anyway).

if ( wp_mail( $emailTo, $subject, $body, $headers ) ) {
    error_log('mail success');
} else {
    error_log('mail fail');
}

What am I missing?

Twilio Reject Call and Send to Voicemail

I have a simple call structure folder with PHP and XML on my server. To handle my incoming calls for my business.

I can’t seem to get it to forward to voicemail without errors.

Here is how the call gets triggered.

Customer Calls -> Routes to Webhook -> Handle-Incoming-Call.XML

    <?xml version="1.0" encoding="UTF-8"?>
<Response>
    
    <Redirect>handle-extension.php</Redirect>
</Response>

Then Handle-Extension.PHP looks like this

<?php
    header('Content-type: text/xml');
    echo '<?xml version="1.0" encoding="UTF-8"?>';

    echo '<Response>';

    
        # @start snippet
        echo '<Say>Thank you for calling, My Business</Say>';
        echo '<Dial record="true" timeout="15" action="voicemail.php">';
        echo '<Number url="screen-caller.xml">+10000000000</Number>';
        echo '</Dial>';
        # @end snippet
    
    echo '</Response>';
?>

Then Screen-Caller.XML looks like this (This is what me as a business will hear when I pick up)

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Gather action="handle-screen-input.php" numDigits="1">
        <Say>Call for Your Business</Say>
        <Say>To accept the call, press 1.</Say>
        <Say>To reject the call, press 2.</Say>
    </Gather>

</Response>

When I press 1 I get the call, but when I press 2 I want it to go to voicemial.

Here is the Handle-Screen-Input.PHP

<?php
    header('Content-type: text/xml');
    echo '<?xml version="1.0" encoding="UTF-8"?>';

    echo '<Response>';

    $user_pushed = (int) $_REQUEST['Digits'];

    if ($user_pushed == 1)
    {
        echo '<Say>Connecting, say hello.</Say>';
    }
    else {
        echo '<Hangup />';
    }

    echo '</Response>';
?>

I did a bypass for now so I created another Webhook to go to a TwimLets Forwarding Voicemail to Email when it fails.

Here is the fail message I get from LOGS

An attempt to retrieve content from https://website.com/callsystem/voicemail.php returned the HTTP status code 500. Falling back to http://twimlets.com/voicemail?Email=email%40email.com&Message=Please%20leave%20a%20message%20after%20the%20beep.&Transcribe=true&

So when it gets to the error it goes to my fallback WebHook, I still get the voicemail but I get tons of error logs at the end of the day.

I am trying to figure out what I am missing to get the voicemail.php to work.

Here is the voicemail.php code I found in one of the posts here in Stack.

header("content-type: text/xml");
    echo '<?xml version="1.0" encoding="UTF-8"?>';
    $email = $_REQUEST['email'];
?>
<Response>
    <?php if ($_REQUEST['DialCallStatus'] == 'completed') { ?>
            <Hangup/>
    <?php } else { ?>
            <Say>Sorry Our Business is not available at this time, Please leave a message at the tone.  Press the star key when finished.</Say>
            <Record transcribe="true" action="goodbye.php" transcribeCallback="voicemail-send.php?email=<?php echo $email; ?>" maxLength="120" finishOnKey="*" />
            <Say>I did not receive a recording.</Say>
            <Redirect>voicemail.php</Redirect>
    <?php } ?>
</Response>

Do I need to add a file name “voicemail-send.php” if so what is that structure look like?

Any help would be greatly appreciated. Thank you

What is the right way to add a new product property in WooCommerce?

I’ve just started learning about WordPress and WooCommerce. My problem is that products there lack properties like expiration date, origin or similar that I might think of in the future (for every single product these fields are probably going to be different, not that many duplicates). I know that it might be possible to achieve this functionality with attributes (?) but I’m not entirely sure. My idea is to create a module with a separate database which would have a relationship with each product (or post). Is that the right approach? What I am trying to achieve at the end of the day is to create a dashboard in the front end where some users will be able to add or edit certain products and those fields are necessary to be in that dashboard. Or maybe you have any other suggestions? Thank you.

PHP Get price from span

Im new in PHP. Can you tell me how can I get price from span named “wordCounterPrice”. I have something like this:

class getPrice {
    public $price;
    public function __construct($data){
        $this->price = addslashes($data['wordCounterPrice']);
    }
}
...
if(isset($_POST['count'])){
    echo '<script>location.href="#test"</script>';
    $price = new getPrice($_POST);
...
}

HTML:

<span id="wordCounterPrice" name="wordCounterPrice">0</span>
<button type="submit" name="count" id="count" class="btn btn-primary">Get it</button>

So much thanks

Create Tweet API not working for other users

I’ve created a Twitter developer account with my profile and passing cosumer_key, consumer_secret, token_id, and token_secret and If I’m hitting create-tweet 'https://api.twitter.com/1.1/statuses/update.json' API then I’m getting a proper response but if I’m creating tweets with other users credentials I’m getting an error
([errors]=> Array([code] => 32, [message] => Could not authenticate you.)). I’ve given read & write permission to my app as well.

    public function createTweet(Request $req) {
    Log::channel('twitterwebhook')->info($req->all());

    $access_token = $req->require('token_id');
    $acess_token_secret = $req->require('token_secret');
    $message = $req->require('message');
    $twitter = new TwitterAPI($access_token, $acess_token_secret);

    $response = $twitter->createTweet($message);
    
    if(isset($response->errors)){
        return error($response->errors, 4099);
    }
    $data = [
        'tweet_id'=> $response->id,
        'tweet_str_id' =>$response->id_str,
        'message' =>$response->text,
        'user_twitter_id'=>$response->user->id,
        'user_twitter_name'=>$response->user->name,
        'user_twitter_screen_name'=>$response->user->screen_name
    ];
    return success($data);
}

public function createTweet($tweet_message) {
    $postfields = [
        'status' => $tweet_message, 
        'trim_user' => false
    ];

    $twitterResponse =  $this->buildOauth($this->_update_url, 'POST')
                             ->setPostfields($postfields)
                             ->performRequest();
    return json_decode($twitterResponse);

}

@php tag in blade template can’t reach inline variable

I am looping through products which has all my configurable options available. Inside that i am looping through my items, when i get a match in product i want to display this product and item.

To do so i want to create a variable called $currentProduct.

@foreach($order['products'] as $product) // Configurable products
    @foreach($order['items'] as $item)  // Simple products
        @if ($item['product_type'] == 'simple')
            @if ($product['id'] === $item['product_id'])
                @php($currentProduct = $product) // error here $product undefined
                @php($currentItem = $item) // error here $item undefined
            @endif
        @elseif ($item['product_type'] == 'configurable')
            @if ($product['id'] == $item['parent_item']['product_id'])
                @php($currentProduct = $product) // error here $product undefined
                @php($currentItem = $item) // error here $item undefined
            @endif
        @endif
    @endforeach
@endforeach

I am new to laravel and blade templates and can’t seem to wrap my head around, why $product and $item is undefined when they are defined right above in same template.

Any help appreciated

how to display and hide the watermark on a video using ffmpeg

i’m new to ffmpeg i want to add any animation to the watermark
this is my php code:

$source=$_SERVER['DOCUMENT_ROOT']."/content/uploads/".$row['source'];
            $command = "ffmpeg -i ".$source." -i medada.png";
            $command .= " -filter_complex "[0:v][1:v]";
            $command .= " overlay=25:150""; 
            $str = rand();
            $result = hash("sha256", $str);
            $path_info = pathinfo($source);
            $extension=$path_info['extension'];
            $command .= " -c:a copy ".$_SERVER['DOCUMENT_ROOT']."/content/downloads/".$result.".".$extension."";