Hi,

The following script gives back bummer as print, so the storing to database hasn't worked. What is wrong?

<?php

function db_connect(){

	$connect = new MySQLi("localhost", "justinmijn_root", "***", "justinmijn_nba");

	// mysql_connect_errno() retourneert 0 als er geen fouten zijn
	if (!$connect || mysqli_connect_errno() != 0) {
		throw new Exception('Er kan geen connectie tot stand gebracht worden. De volgende fout heeft zich voorgedaan:' . mysqli_connect_errno().
		' ' . mysqli_connect_error() . '<br /><br /> Als zich dit blijft voordien, gelieve de site administrator te contacteren');
	} else {
		return $connect;
	}
}


$aantalsp1w = 1;
$aantalsp1l = 2;
$aantalsp1p = 3;
$aantalsp2l = 4;
$aantalsp2w = 5;
$aantalsp2p = 6;

$team = "Boston Terriers";
$experts = "timmi";
$season = "2007-2008";

$con = db_connect();

$sides = ("'" . $aantalsp1w . "-" . $aantalsp1l . "-" . $aantalsp1p);
$totals = ("'" . $aantalsp2w . "-" . $aantalsp2l . "-" . $aantalsp2p);

$query = $con->query("INSERT INTO nba (team,expert,season,sides,totals) VALUES ('$team', '$experts', '$season', '$sides', '$totals')");

if ($query){
	print("jippie");
}else{
	print("bummer");
}
?>

Grtz

}else{
   print($con->error);
}

This is the output:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1-2-3', ''5-4-6')' at line 1

You don't need the leading "'" . when setting $sides and $totals.

Ouch, didn't looked at that. I normally used it to write it to copy it in excel.

Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.