Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 1 of 1
  1. #1
    Junior Member
    Join Date
    Dec 2020
    Posts
    1
    Member #
    62323

    MySQL & PHP Search form

    I have a problem with my project acctualy everithing works but when I put the reserch city who is not in the database at the place to have a messege I got this : Notice: Trying to access array offset on value of type null in C:\xampp\htdocs\index.php on line 59. Please someone help! Thanks
    HTML Code:
    <?php
    require('inc_connexion.php');
    
    ?>
    <!doctype html>
    <html>
        <head>
            <title>acceuil</title>
            <link rel="stylesheet" type="text/css" href="css/style.css" />
        </head>
        <body>
            <div class="content">
                <center>
                    <h1>Formulaire de recherche de villes</h1>
    <?php
    if(isset($_GET['submit']))
    {
    //On recupere les valeurs du formulaire : on utilise mysqli_real_escape_string pour se proteger legerement des injections sql (meme si il faudrait plutot des requetes preparés)
    print_r($_GET);
    
    $first_name =  $mysqli->real_escape_string($_GET['first_name']);
    $name =  $mysqli->real_escape_string($_GET['name']);
    $city_name =  $mysqli->real_escape_string($_GET['user_city_name']);
    
    if(empty($first_name) OR empty($name) OR empty($city_name)){
    
        $message = '<p>veuillez remplir tous les champs</p>';
    
        }else{
    
            if($mysqli->query('INSERT INTO users(first_name, name, city_name_user) VALUES (" '.$first_name. ' ", " ' .$name . ' ", " ' .$city_name . ' ") ')){
    
                $message = '<p>votre prénom ' .$first_name.' et votre nom ' .$name . ' ont ete enregistre.</p>';
    
                    }else{
    
                        $message = '<p>votre prénom ' .$first_name.' et votre nom ' .$name . ' n ont pas ete enregistre.</p>';
                    }
            }
    
                if($name AND $city_name ){
    
                    $req = $mysqli->query('SELECT*FROM users WHERE first_name = " ' .$first_name . ' " AND name = " ' .$name. ' " ');
    
                        $message = '<p>votre ville n est pas dans la liste.</p>';
    
                        print_r($req);
    
                    $row = $req->fetch_array();
    
                    $id_name = $row['user_id'];
    
                      if($result = $mysqli->query("SELECT city_id FROM city WHERE city_name = '" . $city_name . "'"));
    
                    print_r($result);
    
                    $row = $result->fetch_array();
    
                        $id = $row['city_id'];
    
                            if($mysqli->query ('INSERT INTO user_searchs(user_id, city_id) VALUES (" '.$id_name. ' " , " ' .$id. ' " ) ')){
    
                                $message = '<p>vos informations ont ete enregistre.</p>';
    
                                    }else{
    
                                        $message = '<p>vos informations n ont pas ete enregistre.</p>';
                                    }
                            }
            }       
    ?>
    
    <?php if(isset($message)) echo $message; ?>
    
                    <form action="index.php" method="GET">
                        <p>quel est votre prenom : <input type="text" name="first_name" placeholder="votre prénom" /></p>
                        <p>quel est votre nom : <input type="text" name="name" placeholder="votre nom" /></p>
                        <p>quel ville recherchez vous : <input type="text" name="user_city_name" placeholder="votre ville" /></p>
                        <p><input type="submit" name="submit" value="recherche" /></p>
                    </form>
                </center>
    
             </div>
    
        </body>
    
    </html>

  2.  


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:25 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com