Jump to content

[SOLVED] query database not working


mbrown

Recommended Posts

    <?php

	include 'dbconnect.php';

	$Query = "SELECT ID, Age, Month, Day, Year, Hometown, State, Graduation, Certificate, Associates, Bachelors, Study, GPA FROM survey WHERE = Age = '21'";

	$Result = mysqli_query ($db $Query) or die("<p>Unable to execute the query.</p>"
	. "<p>Error Code</p>" . mysqli_errno($db) . ": " . mysqli_error($db)) . "</p>";

	echo "<p>Successfully executed the query.>/p>";
	mysqli_close($db);


?>

 

it is throwing this error: Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\CIT250\Project\assignment3\age.php on line 15

 

All I want is to display the information in a table. Yes I know I dont have the table set up yet but thats life at the moment. One step at a time.

Link to comment
https://forums.phpfreaks.com/topic/124865-solved-query-database-not-working/
Share on other sites

Don't know if this is it, but give it a shot:

 

<?php
include('dbconnect.php');

$Query = "SELECT ID, Age, Month, Day, Year, Hometown, State, Graduation, Certificate, Associates, Bachelors, Study, GPA FROM survey WHERE Age = '21'";

$Result = mysqli_query ($db $Query) or die("<p>Unable to execute the query.</p>" . "<p>Error Code</p>" . mysqli_errno($db) . ": " . mysqli_error($db) . "</p>");

echo "<p>Successfully executed the query.>/p>";
mysqli_close($db);
?>

It's in your WHERE clause:

 

 

    <?php

	include 'dbconnect.php';

	$Query = "SELECT ID, Age, Month, Day, Year, Hometown, State, Graduation, Certificate, Associates, Bachelors, Study, GPA FROM survey WHERE Age = '21'";

	$Result = mysqli_query ($db $Query) or die("<p>Unable to execute the query.</p>"
	. "<p>Error Code</p>" . mysqli_errno($db) . ": " . mysqli_error($db)) . "</p>";

	echo "<p>Successfully executed the query.>/p>";
	mysqli_close($db);


?>

 

same error: Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\CIT250\Project\assignment3\age.php on line 15

 

Yelling at the following code

 

	$Result = mysqli_query ($db $Query) or die("<p>Unable to execute the query.</p>"

[code]

[/code]

Yeah, there's a lot of typos and stuff in your code. You should really look more closely at it. Here's my fix:

 

    <?php

	include 'dbconnect.php';

	$Query = "SELECT ID, Age, Month, Day, Year, Hometown, State, Graduation, Certificate, Associates, Bachelors, Study, GPA FROM survey WHERE Age = '21'";

	$Result = mysql_query ($Query,$db) or die("<p>Unable to execute the query.</p>"
	. "<p>Error Code</p>" . mysql_error($db) . ": " . mysql_error($db) . "</p>");

	echo "<p>Successfully executed the query.</p>";
	mysql_close($db);


?>

Sorry...use this...

 

<?php
include('dbconnect.php');

$Query = "SELECT ID, Age, Month, Day, Year, Hometown, State, Graduation, Certificate, Associates, Bachelors, Study, GPA FROM survey WHERE Age = '21'";

$Result = mysqli_query ($db, $Query) or die("<p>Unable to execute the query.</p>" . "<p>Error Code</p>" . mysqli_errno($db) . ": " . mysqli_error($db) . "</p>");

echo "<p>Successfully executed the query.>/p>";
mysqli_close($db);
?>

Here's a list of all the errors I saw:

 

an extra "=" in the where clause

using "mysqli_..." instead of "mysql_..." (added an "i")

")" in the wrong place in the die() statement

used ">" instead of "<" in the successful echo statement

 

mysqli() is a new PHP extension.  Look it up before you go correcting people.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.