0

I have a problem displaying my information in the database using phpmyadmin. I have 2 files (form.php and connect.php), it says it's connected to the database but nothing shows up in my database.

Is there any solution for that? I spent almost a whole day trying to resolve that.

Here's connect.php:

<?php
$mysql_host='localhost';
$mysql_user='root';
$mysql_password=''; **i don't have a password.

mysql_connect($mysql_host,$mysql_user,$mysql_password)

echo"connection sucess";

$link = mysqli_connect("localhost","root","") or die ("Couldn't not connect");
mysqli_select_db($link, "cooperative_db");

if (!$link) {
    die('Could not connect: ' . mysql_error());
}

echo "Successfully connected \n";

$FIRST_NAME = $_POST['FIRST_NAME'];
$LAST_TIME = $_POST['LAST_NAME'];
$CIVIC_NUMBER = $_POST['CIVIC_NUMBER'];
$STREET = $_POST['STREET'];
$CITY = $_POST['CITY'];
$PROVINCE = $_POST['PROVINCE'];
$POSTAL_CODE = $_POST['POSTAL_CODE'];
$COUNTRY = $_POST['COUNTRY'];
//$TELEPHONE = $_POST['TELEPHONE'] . $_POST['TELEPHONE'] . $_POST['TELEPHONE'];
$INCOME = $_POST['INCOME'];
//$INCOME_SOURCE = $_POST['element_6_1'] . $_POST['element_6_2'] . $_POST['element_6_3'] . $_POST['element_6_4'] .
//$_POST['element_6_5'];

$sql = "INSERT INTO candidat(FIRST_NAME, LAST_NAME, CIVIC_NUMBER, STREET, CITY, PROVINCE, POSTAL_CODE, COUNTRY, INCOME) VALUES ('$FIRST_NAME', '$LAST_TIME', '$CIVIC_NUMBER', '$STREET','$CITY', '$PROVINCE', '$POSTAL_CODE', '$COUNTRY', '$INCOME')";

?>
sepehr
  • 17,110
  • 7
  • 81
  • 119
maro
  • 9
  • 2
  • try to echo your **$sql** and see if its true. – Denny Sutedja Nov 02 '16 at 07:00
  • is this all your insert query? see http://www.w3schools.com/php/func_mysqli_query.asp on how to Perform queries against the database: – Mueyiwa Moses Ikomi Nov 02 '16 at 07:01
  • Possible duplicate of [Inserting Data in mysqli is not working](http://stackoverflow.com/questions/11175061/inserting-data-in-mysqli-is-not-working) – Mueyiwa Moses Ikomi Nov 02 '16 at 07:04
  • mysql_query($sql) – Md Hasibur Rahaman Nov 02 '16 at 07:06
  • the image u attached says your table name to be cooperative_table and also, you've inserted into a table named candidat; note that last E is missing. Are you sure your query is correct? – Pragun Nov 02 '16 at 07:08
  • **WARNING**: When using `mysqli` you should be using [parameterized queries](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and [`bind_param`](http://php.net/manual/en/mysqli-stmt.bind-param.php) to add user data to your query. **DO NOT** use string interpolation or concatenation to accomplish this because you have created a severe [SQL injection bug](http://bobby-tables.com/). **NEVER** put `$_POST` or `$_GET` data directly into a query, it can be very harmful if someone seeks to exploit your mistake. – tadman Nov 02 '16 at 07:24
  • all your variables are insert as varchar, but i think some of them is int , shoud not be quote by ' , check your db fields type. – chenyb999 Nov 02 '16 at 07:40

1 Answers1

0

It seems like you may have many issues in your code. Let's start step by step.

I am not sure if that: "**i don't have a password." is actually inside your code, so change it first of all to //i don't have a password..
Now, in the second picture you showed us, it only echo 1 line instead of two, and inside your code you actually have two lines that should echo a result.
echo"connection sucess"; and echo "Successfully connected \n";

This could be due to the fact that you forgot a ; in the line right before the first echo.
mysql_connect($mysql_host,$mysql_user,$mysql_password);

May I ask you why are you using both mysql, and mysqli? If it's just for testing, there's no harm in it, plus you should know that mysql is deprecated and no longer supported or updated, you better just use mysqli, please refer to this post Why shouldn't I use mysql_* functions in PHP?.

The first picture shows that you don't have a table named candidat, yet in your code you have this: INSERT INTO candidat. Maybe you wanted this to be INSERT INTO cooperative_table instead?
Please make those small fixes, and tell us your result.

Edit: I forgot to mention, just like tadman commented, you better be aware of the SQL Injection bugs you have and fix them accordingly.

Community
  • 1
  • 1
Paul Karam
  • 4,052
  • 8
  • 30
  • 53