1

I am having an issue, I am trying to create a form registration but this page will be accessible only by staff people. So I have: <?php if($_SESSION['id']) to verify the users if they are logged in and display the echo to this users.

I am having trouble to insert the Birthday registration as I use PHP to calculate the years, months and days. Here is the part of the code

if($_POST['submit']=='Rregjistro')
                {
// If the Register form has been submitted

$err = array();

if(strlen($_POST['emri'])<4 || strlen($_POST['emri'])>32)
{
    $err[]='Emri duhet te permbaje nga 3 deri 32 karaktere!';
}

if(preg_match('/[^a-z0-9\-\_\.]+/i',$_POST['emri']))
{
    $err[]='Emri juaj permban karakter te palejueshme!';
}
if(strlen($_POST['atesia'])<4 || strlen($_POST['atesia'])>32)
{
    $err[]='Atesia duhet te permbaje nga 3 deri 32 karaktere!';
}

if(preg_match('/[^a-z0-9\-\_\.]+/i',$_POST['atesia']))
{
    $err[]='Atesia juaj permban karakter te palejueshme!';
}

if(strlen($_POST['mbiemri'])<4 || strlen($_POST['mbiemri'])>32)
{
    $err[]='Mbiemri duhet te permbaje nga 3 deri 32 karaktere!';
}

if(preg_match('/[^a-z0-9\-\_\.]+/i',$_POST['mbiemri']))
{
    $err[]='Mbiemri juaj permban karakter te palejueshme!';
}

if(strlen($_POST['vendlindja'])<4 || strlen($_POST['vendlindja'])>32)
{
    $err[]='Vendlindja duhet te permbaje nga 3 deri 32 karaktere!';
}

if(preg_match('/[^a-z0-9\-\_\.]+/i',$_POST['vendlindja']))
{
    $err[]='Vendlindja juaj permban karakter te palejueshme!';
}
if(strlen($_POST['vendbanimi'])<4 || strlen($_POST['vendbanimi'])>32)
{
    $err[]='Vendbanimi duhet te permbaje nga 3 deri 32 karaktere!';
}

if(preg_match('/[^a-z0-9\-\_\.]+/i',$_POST['vendbanimi']))
{
    $err[]='Vendbanimi juaj permban karakter te palejueshme!';
}
if(strlen($_POST['telefon'])<4 || strlen($_POST['telefon'])>10)
{
    $err[]='Telefoni duhet te permbaje nga 5 deri 10 numra!';
}

if(preg_match('/[^a-z0-9\-\_\.]+/i',$_POST['telefon']))
{
    $err[]='Telefoni juaj permban karakter te palejueshme!';
}


if(!count($err))
{


    $_POST['emri'] = mysql_real_escape_string($_POST['emri']);
    $_POST['atesia'] = mysql_real_escape_string($_POST['atesia']);
    $_POST['mbiemri'] = mysql_real_escape_string($_POST['mbiemri']);
    $_POST['vendlindja'] = mysql_real_escape_string($_POST['vendlindja']);
    $_POST['vendbanimi'] = mysql_real_escape_string($_POST['vendbanimi']);
    $_POST['telefon'] = mysql_real_escape_string($_POST['telefon']);
    $_POST['zona'] = mysql_real_escape_string($_POST['zona']);
    // Escape the input data


    mysql_query("INSERT INTO antaret(ID,emri,atesia,mbiemri,ditelindja,vendlindja,vendbanimi,telefon,zona,regtime)
                    VALUES('".$_POST['emri']."','".$_POST['atesia']."','".$_POST['mbiemri']."','".$date."','".$_POST['vendlindja']."','".$_POST['vendbanimi']."','".$_POST['telefon']."','".$_POST['zona']."',NOW())");


}
                } 

I guess I have something wrong in the code but is missing to my eyes and also I have no error response so I guess is something with the query.

Thank you

4
  • 1
    mysql is deprecated since PHP 7 you should really use alternatives like mysqli or PDO Commented Apr 4, 2017 at 10:04
  • if($_POST['submit']=='Rregjistro') is not opening any brackets but you're closing an extra one at the end. That would normally be a syntax error which any IDE would be very vocal about. Commented Apr 4, 2017 at 10:04
  • actually I had this old secure login script and I was trying to adopt somehow, the original script works fine I have no error in the Dreamweaver IDE and neither on server side the only thing is that I am not able to put data in DB (MariaDB).I have php 5.5 in my server Commented Apr 4, 2017 at 10:12
  • You SQL query is incorrect, you are trying to insert into 10 columns but you are providing only 9 values, you are missing 'ID' value in your query. Commented Apr 4, 2017 at 10:30

2 Answers 2

1

You SQL query seems incorrect, the column count doesn't match, you are trying to insert into 10 columns but you are providing only 9 values, you are missing 'ID' value in your query.

Sign up to request clarification or add additional context in comments.

Comments

0

"I am having trouble inserting ..." is not a useful diagnostic. The mysql extension (and its replacements) provide an API to capture why something has failed:

$qry=("INSERT INTO antaret
(ID, emri,
 atesia, mbiemri,
 ditelindja, vendlindja,
 vendbanimi, telefon,
 zona, regtime) 
VALUES
('".$_POST['emri']."','".$_POST['atesia']."','"
  .$_POST['mbiemri']."','".$date."','"
  .$_POST['vendlindja']."','".$_POST['vendbanimi']."','"
  .$_POST['telefon']."','".$_POST['zona']."',
  NOW()
)");
$result = mysql_query($qry);
if (false===$result) {
   print "Query failed: " . mysql_error() . "<br /><br />" . $qry;
}

This might have given you a clue that there is a difference in the number of columns declared in the statement and the number of values. Formatting your SQL so it is readable might have given you a clue.

BTW you should read up on SQL injection before you expose this on the internet.

1 Comment

Thank You! I just solved my issue using mysqli and not mysql

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.