having problems to adding data into DB from register.php

Hi There,

I am new to PHP and I am doing some school work and facing some issues. I am not able to add data from my register.php into my DB which is hosted in xampp. and the funny thing is that the register.php keeps refreshing. Kinly please help. Not sure where is there error.

This my code:

Register.php:

[php]<?php
include(“config.php”);
$title=$_REQUEST[‘sel1’];
$fname=$_REQUEST[‘t1’];
$lname=$_REQUEST[‘t2’];
$gen=$_REQUEST[‘r1’];
$id=$_REQUEST[‘t3’];
$pass=$_REQUEST[‘p1’];
$phone=$_REQUEST[‘t5’];
$add=$_REQUEST[‘t6’];
$city=$_REQUEST[‘t7’];
$coun=$_REQUEST[‘t8’];
$dob=$_REQUEST[‘t9’];
if(isset($_post[“sub”]))
{
$sel=mysqli_query("select id from register where id=’$id’ ");
$arr=mysqli_fetch_array($sel);

if($arr[‘id’]!=$id)
{
if(mysqli_query(“insert into register values(’$title’,’$fname’,’$lname’,’$gen’,’$id’,’$pass’,’$phone’,’$add’,’$city’,’$coun’,’$dob’)”))
{

     echo "<script>location.href='index.php?con=13 & wel=$id'</script>";
   }
 }

else
{
echo “user already exists”;
}

}
?>


Register Yourself










Title:
Mr. Ms. Mrs.
First Name:
    <input name="t1" type="text" id="t1" onChange="return fnam()">    </td>
Last name:
 Gender:
Male Female
 Enter Email :
 Choose a Password:
Phone no:
Address:
City:
Country:
Date of Birth:

config.php:

<?php mysqli_connect("localhost","root",""); mysqli_select_db("shop"); ?>[/php]

thank you

You need to display errors, and set error reporting to the max. This should be done in your php.ini. This is a must for a development server, and will point you to your errors.

If you don’t know where the php.ini is located, load up a script with [php]<?php phpinfo(); ?>[/php] and it will tell you.

I will point you in the right direction.
You need to check the manual on mysqli proper usage. You are passing the wrong number of arguments to the functions.

Hi jcbones,

thanks allot. I am attaching the php.ini in the attachment. Kindly plz help me on where i go wrong.


php.txt (70.1 KB)

Your code is vulnerable to an SQL Injection attack. You need to use prepared statements with parameterized queries. I recommend you use PDO instead of Mysqli.

https://phpdelusions.net/pdo

Get out of the habit now of writing all those useless variables and use the Php header to do your redirect.

Hi Kevin Rubio,

thanks allot for replying

I am new to php and was following the examples which on you tube. I not not sure which codes are causing the problem. Is it possible you could point out which are the wrong ones.

Thanks

Change line 445 in the provided .ini file to:

error_reporting=E_ALL

restart server.

Or just put this in your configuration file:

[php]/* Turn on error reporting */
ini_set(‘display_errors’, 1);
ini_set(‘display_startup_errors’, 1);
error_reporting(-1);[/php]

I am more in favor of changing the development server. If you add the code to a file, you have to modify that file when it is moved to production.

Hi jcbones, Strider64,

I done what you have told me. But there is no error but just keeps refreshing to the registration page. Kindly plz help. as i myself not sure where is the error is.

Thanks

You should most definitely be getting errors. As we can see here:
From the Manual

mixed mysqli_query ( mysqli $link , string $query [, int $resultmode = MYSQLI_STORE_RESULT ] )

We need at least two arguments to the mysqli_query function.

Yet, you don’t have two arguments, which is why I pointed you in that direction:
[php]$sel=mysqli_query("select id from register where id=’$id’ ");[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service