LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-19-2010, 07:32 AM   #1
dannyabbott89
LQ Newbie
 
Registered: Apr 2010
Location: St.Helens, UK
Posts: 3

Rep: Reputation: 0
PHP Parse Error using WAMP Server


Hi there. I hope somebody can help me with this.

I have a basic HTML file set up which allows my to input some data. I have a MySql database set up behind the scenes with a table for this information to go in. When I click the submit button in my HTML file this PHP file opens and it comes up with

"Parse error: parse error in C:\wamp\www\comp39x\insert_student.php on line 32"

Here is my code I am using in the PHP file:-

<html>
<head>
<title>COMP 39x FInal Year Project - Student Added?</title>
</head>

<body>
<h1>Student Addition Results</h1>
<?php
//create short variable names
$studid=$_POST['studentid'];
$fname=$_POST['firstname'];
$sname=$_POST['surname'];
$projid=$_POST['projectid'];
$mail=$_POST['emailaddress'];

if (!$studid || !$fname || !$sname || !$projid || !$mail)
{
echo 'You have not entered all the required information.<br />'
.'Please go back and try again.';
exit;
}

@ $db = new mysqli('localhost', 'root', '', 'comp39x');

if (mysqli_connect_errno())
{
echo 'Error: Could not connect to database. Please try again later.';
exit;
}

$query = "insert into student values
('".$studid"', '".$fname"', '".$sname"', '".$projid"', '".$mail"')";
$result = $db->query($query);

if ($result)
echo $db->affected_rows. 'student inserted into the database.';
$db->close();
?>
</body>
</html>


I have created short variable names at the top of the code to make things for myself.

Hope somebody can help.
 
Old 04-19-2010, 07:43 AM   #2
dannyabbott89
LQ Newbie
 
Registered: Apr 2010
Location: St.Helens, UK
Posts: 3

Original Poster
Rep: Reputation: 0
by the way I am using the textbook and the examples contained within "PHP and MySQL Web Development" as an outline for my code
 
Old 04-19-2010, 09:08 AM   #3
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
It would help to indicate which is line 32.

Having said that the line(s)

PHP Code:
$query "insert into student values
('"
.$studid"', '".$fname"', '".$sname"', '".$projid"', '".$mail"')"
you need to use the string concatenation operator after the variables, hence:

PHP Code:
$query "insert into student values
('"
.$studid."', '".$fname."', '".$sname."', '".$projid."', '".$mail."')"
Having said that string literals with double quotes will automatically expand simple variables so you can write it as:

PHP Code:
$query "insert into student values('$studid', '$fname', '$sname', '$projid', '$mail')"
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Parse Error!! hiddenmirageads Programming 2 08-25-2009 05:59 AM
What's the meaning of "PHP Parse error: parse error, unexpected $ in..." frandalla Programming 23 03-04-2009 12:34 PM
PHP Error Parse error: parse error, unexpected $ in /home/content/S/k/i/SkinCare4U/h CowanServices Programming 2 12-09-2008 08:26 PM
PHP parse error in config.inc.php.in Confusedious Linux - Software 2 11-03-2005 05:08 AM


All times are GMT -5. The time now is 03:59 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration