-1

I trying to make a registration form. At this moment I'm trying to insert the input data into database. I got syntax error, unexpected '{' in..i cant find where the error is.. Please kindly help to look at my code. Btw this the code i edited from question i post before about blank page error.. Sorry for my broken english. :D

partner_registration.php:

<?PHP
error_reporting(0);
include ('connect.php');


if(isset($_POST['submit']))
{

// The form is submitted

$c_name = ($_POST['txtName']);
$c_type = ($_POST['selType']);
$c_no = ($_POST['txtNo']);
$c_address = ($_POST['txtAddress']);
$c_city = ($_POST['txtCity']);
$c_postcode = ($_POST['txtPostcode']);
$c_state = ($_POST['selState']);
$c_country = ($_POST['selCountry']);
$c_email = ($_POST['txtEmail']);
$c_phone = ($_POST['txtPhone']);
$c_fax = ($_POST['txtFax']);


$c_name = $mysqli->real_escape_string($c_name);
$c_type = $mysqli->real_escape_string($c_type);
$c_no = $mysqli->real_escape_string($c_no);
$c_address = $mysqli->real_escape_string($c_address);
$c_city = $mysqli->real_escape_string($c_city);
$c_postcode = $mysqli->real_escape_string($c_postcode);
$c_state = $mysqli->real_escape_string($c_state);
$c_country = $mysqli->real_escape_string($c_country);
$c_email = $mysqli->real_escape_string($c_email);
$c_phone = $mysqli->real_escape_string($c_phone);
$c_fax = $mysqli->real_escape_string($c_fax);



// attempt insert query execution
if ( $insert = $mysqli->query ( "INSERT INTO tblpartner (companyName,   companyRegistration, companyNo, companyAddress, companyCity, companyPostCode, companyState, companyCountry, companyEmail, companyPhone, companyFax) VALUES ('$c_name', '$c_type', '$c_no', '$c_address', '$c_city','$c_postcode', '$c_state', '$c_country', '$c_email', '$c_phone', '$c_fax')")
{
echo("Success", $mysqli->affected_rows);
}

}

?>

connect.php:

<?php
$hostname="localhost"; //local server name default localhost
$username="root";  //mysql username default is root.
$password="1234";       //blank if no password is set for mysql.
$database="intrasystem";  //database name which you created

//Open a new connection to the MySQL server
$mysqli = new mysqli('localhost','root','1234','intrasystem');

//Output any connection error
if($mysqli->connect_errno)
{
     die('Cannot connect to database');
 }

?>
Alip Rosli
  • 11
  • 5
  • Can you see the error logs? – raygo Nov 04 '15 at 20:30
  • `$con` is an object. Use OOP in all instances. This `$c_name = mysqli_real_escape_string($con, $_POST['txtName']);` is procedural. – chris85 Nov 04 '15 at 20:33
  • 1
    Read `bind_param` manual and check it's first argument. Which is a string like `'sssi'` or similar. – u_mulder Nov 04 '15 at 20:33
  • no..nothing displays even i put the error reporting – Alip Rosli Nov 04 '15 at 20:39
  • That's why indentation was invented.. to avoid such `problems` – Mihai Matei Nov 05 '15 at 13:37
  • `error_reporting()` doesn't help. It is a runtime directive. It has effect during the runtime but your code doesn't run because it doesn't compile. PHP doesn't even attempt to run it. More, it tells where where is the error (in line 40). – axiac Nov 05 '15 at 13:45

2 Answers2

2

In this line:

if ( $insert = $mysqli->query ( "... your sql query ...")

You have two opening brackets, but only one closing. Just add another closing bracket at the end:

if ( $insert = $mysqli->query ( "... your sql query ...") )
Gerald Schneider
  • 17,416
  • 9
  • 60
  • 78
  • does it look like this ( ....... '$c_email', '$c_phone', '$c_fax')")) coz i got new systax unexpected ',' – Alip Rosli Nov 05 '15 at 13:51
  • I don't see any misplaced `,` in the code you posted. Maybe this helps: http://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them – Gerald Schneider Nov 05 '15 at 14:11
  • the unexpected ',' is in the line echo("Success", $mysqli->affected_rows); what is the proper way to write this? i tried echo("success") only but i got blank page after submit – Alip Rosli Nov 05 '15 at 14:19
  • [According to the documentation](http://php.net/manual/en/function.echo.php) the notation `echo ( string $arg1 [, string $... ] )` is perfectly valid. You can concatenate using `.` instead: `echo("Success: " . $mysqli->affected_rows);` – Gerald Schneider Nov 05 '15 at 14:23
  • never mind..my fault..i left " at the button HTML..thnx for the help :D – Alip Rosli Nov 05 '15 at 14:40
0
if ( $insert = $mysqli->query( "INSERT INTO tblpartner (companyName,   companyRegistration, companyNo, companyAddress, companyCity, companyPostCode, companyState, companyCountry, companyEmail, companyPhone, companyFax) VALUES ('".$c_name."', '".$c_type."', '".$c_no."', '".$c_address."', '".$c_city."','".$c_postcode."', '".$c_state."', '".$c_country."', '".$c_email."', '".$c_phone."', '".$c_fax."')"))
{
    echo("Success", $mysqli->affected_rows);
}

Use PDO next time.