/    Sign up×
Community /Pin to ProfileBookmark

Problems with my PHP and MySQL combination

Okay, I am trying to log into my website using PHP and MySQL, and I keep getting an error… Hopefully someone can help. Here is the info

[B]index.php[/B]

[QUOTE]

<?php

include ‘dbconnect.php’;
//include ‘destroy.php’;
session_start();

?>
<html>
<head>
<title>Bowling Questionnaire</title>
<link type=”text/css” href=”bowling.css” rel=”stylesheet”>
</head>
<body>
<div class=”body”>
<img src=”topbanner.jpg”>
<h1>Thank you very much for participating in this research. Your information will be kept private, and only for use in any future projects that SFWD may be conducting. Again, thank you, and please proceed.</h1>
<form action=”passwordcheck.php” method=”POST”>
Please enter your invitation number, which can be found in the subject line of the letter you received in the mail:
<br />Invitation Number:<input type=”text” name=”invnum”><br />
Password:<input type=”text” name=”pass” />
<br /><input type=”submit” value=”Submit” />&nbsp;&nbsp;<input type=”reset” value=”Reset” />
</form>
<a href=”admin.php”>Admin</a>
</div>
</body>
</html>

[/QUOTE]

[B]dbconnect.php[/B]

[QUOTE]

<?php

//establishing connection to db
$host=hostname;
$user=username;
$pass=password;
mysql_connect($host, $user, $pass);

//making sure the database created is used
mysql_select_db(“semperf4_bowling”);

?>

[/QUOTE]

[B]questionnaire.php[/B]

[QUOTE]

<?php
session_start();
include’dbconnect.php’;
$sql=”SELECT * FROM bowling WHERE alley_id= ‘” . $_SESSION[‘user’] . “‘ . “;
$result=mysql_query($sql);
$row=mysql_fetch_row($result);
$alleyname=$row[‘alley_name’];

?>

<html>
<head>
<title>Welcome <?php echo $alleyname; ?></title>
<link href=”bowling.css” type=”text/css” rel=”stylesheet” />
<script language=”JavaScript” src=”javascript/gen_validatorv31.js” type=”text/javascript”> </script>
</head>
<body>
<div name=”body”>
<h1>This questionnaire is part of a market research being conducted by Semper Fidelis Web Design (SFWD). Any and all information is voluntary, and will only be used in conjunction with SFWD and their future projects. </h1>
Welcome <?php echo $alleyname ?>
<div name=”question”>
<form action=”insertdata.php” method=”POST” name=”myform”>
<h3>Questions Regarding Current Operations</h3>
How many days per week do you run leagues:<br />
<input type=”radio” name=”days” value=”1-2″ />
1-2
<input type=”radio” name=”days” value=”3-4″ />
3-4
<input type=”radio” name=”days” value=”5-7″ />
5-7<br />
How many lanes are in your building:<br />
<input type=”text” name=”lanes” />
<br />
What is the average number of leagues you run, per week, year round:<br />
<input type=”text” name=”leagues” />
<br />
What is the average number of bowlers per team:<br />
<input type=”text” name=”bowlers” />
<br />
How many results sheets do you have printed per team:<br />
<input type=”text” name=”sheets” />
<br />
<h3>Questions Regarding Current Equipment Usage</h3>
What type of printer do you currently use:<br />
<input type=”radio” name=”printer” value=”LaserJet” />
LaserJet
<input type=”radio” name=”printer” value=”InkJet” />
InkJet
<input type=”radio” name=”printer” value=”Copier” />
Copier<br />
What category does your printer fall into:<br />
<input type=”radio” name=”pcategory” value=”Commercial” />
Commercial
<input type=”radio” name=”pcategory” value=”Consumer” />
Consumer<br />
How many ink/toner cartridges do you go through in one month:<br />
<input type=”text” name=”inktoner” />
<br />
<h3>Questions Regrading SFWD’s Future Project</h3>
<p id=”projdescrip”>
</p>
Do you currently have internet access:<br />
<input type=”radio” name=”internet” value=”yes” />
Yes
<input type=”radio” name=”internet” value=”no” />
No<br />
Do you have the ability to project websites onto the screens above the lanes or onto televisions:<br />
<input type=”radio” name=”project” value=”screens” />
Screens
<input type=”radio” name=”project” value=”tvs” />
Televisions
<input type=”radio” name=”project” value=”both” />
Both
<input type=”radio” name=”project” value=”neither” />
Neither<br />
Would you consider installing the technology needed in order to do this:<br />
<input type=”radio” name=”install” value=”yes” />
Yes
<input type=”radio” name=”install” value=”no” />
No<br />
Given the description above, how likely would you be to use this service:<br />
<input type=”radio” name=”useservice” value=”Very Likely” />
Very Likely
<input type=”radio” name=”useservice” value=”Somewhat Likely” />
Somewhat Likely
<input type=”radio” name=”useservice” value=”Undecided” />
Undecided
<input type=”radio” name=”useservice” value=”Not Likely” />
Not Likely
<input type=”radio” name=”useservice” value=”Not at all” />
Not At All<br />
Based on the description above, how likely do you think your bowlers would be interested in this service:<br />
<input type=”radio” name=”bowlerservice” value=”Very Likely” />
Very Likely
<input type=”radio” name=”bowlerservice” value=”Somewhat Likely” />
Somewhat Likely
<input type=”radio” name=”bowlerservice” value=”Undecided” />
Undecided
<input type=”radio” name=”bowlerservice” value=”Not Likely” />
Not Likely
<input type=”radio” name=”bowlerservice” value=”Not At All” />
Not At All<br />
Based on the description above, what price would you expect to pay for the service (per month):<br />
<input type=”radio” name=”amount” value=”40″ />
$40
<input type=”radio” name=”amount” value=”50″ />
$50
<input type=”radio” name=”amount” value=”60″ />
$60<br />
<br />
</form>
Thank you for your time, your participation is greatly appreciated.
<?php echo mysql_error(); ?>
</body>
</html>

[/QUOTE]

[B]passwordcheck.php[/B]

[QUOTE]

<?php
session_start();
include ‘dbconnect.php’;

$myusername=$_POST[‘invnum’];
$mypassword=$_
POST[‘pass’];

$myusername=stripslashes($myusername);
$mypassword=stripslashes($mypassword);

$myusername=mysql_real_escape_string($myusername);
$mypassword=mysql_real_escape_string($mypassword);

$sql=”SELECT * FROM bowling WHERE alley_id=’$myusername’ AND alley_pass=’$mypassword’ AND infosubmit<>’yes'”;
$result=mysql_query($sql);
if($count=mysql_num_rows($result)) {

for ($i=0; $i <$count; $i++)
{
$row=mysql_fetch_array($result);
$infosubmit=$row[‘infosubmit’];
}

if($infosubmit!=’yes’) {
if($count==1) {
$_SESSION[‘user’]=$myusername;
header(“location:questionnaire.php”);
}
else {
echo “Wrong Username or Password <br />”;
echo “Or your information has already been submitted”;
}

}
else {
echo “Information has already been submitted. If this is not correct, please contact us at the number listed on the bottom of the invitation.”;
exit;
}
}
else
{
print(mysql_error());
}
?>

[/QUOTE]

The error I get is as follows:

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/…/questionnaire.php on line 6

And the mysql_error() command shows the following:

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 ‘.’ at line 1

Any help would be appreciated!!
Reply With Quote

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@criterion9Feb 18.2010 — 
$sql="SELECT * FROM bowling WHERE alley_id= '" . $_SESSION['user'] . "' . ";

[/quote]


Should be:

[code=php]
$sql="SELECT * FROM bowling WHERE alley_id= '" . $_SESSION['user'] . "'";
[/code]


Additionally you should be checking that the query succeeded before trying mysql_fetch_*. mysql_query will return false if the query failed you can have a more graceful error handler.
×

Success!

Help @usmccampbell spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...