•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 374,010 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,872 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 3000 | Replies: 6
![]() |
•
•
Join Date: Oct 2004
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
Hi all,
This is my first post and first attempt at PHP so sorry if this sounds daft. I'm about a fifth of the way through the php bible and a quarter through php/mysql for dummies, so it can only get better.
Anyway I'm getting this error when I try to run a form which takes the data from the form fields and inserts it into a mysql database I set up on my hosting account.
Parse error: parse error, unexpected T_STRING, expecting ']' in /home/peilife/public_html/phpform.php on line 32
Here's the code:
<HTML>
<HEAD>
<TITLE>PHP Form submit</TITLE>
<META NAME="GENERATOR" CONTENT="MAX's HTML Beauty++ 2004">
</HEAD>
<BODY>
<form action="<?php echo $SERVER['PHP_SELF]?>" method="post">
">
<p> Please enter the name of the business: <BR>
<input type="text" name="$busname" size=40 value="<?php echo $PHP_SELF?>">
<p> Please enter the phone number of the business: <BR>
<input type="text" name="$busphone" size=40 value="<?php echo $PHP_SELF?>">
<p> Please enter the primary key: <BR>
<input type="text" name="$primkey" size=40 value="<?php echo $PHP_SELF?>">
<p> Please enter the image location where the business image is stored: <BR>
<input type="text" name="$imageloc" size=40 value="<?php echo $PHP_SELF?>"> <BR>
<input type="submit" value="submit"><input type="reset" value="clear values">
<?php
$user = "peilife_admin";
$host = "localhost";
$password = "*******";
$database = "peilife_busdir"
$connection = mysql_connect($host, $user, $password) or die ("Could not make connection to server");
**line 32**mysql_select_db ('peilife_admin') or die ("Couldn't select database");
$query1 = "INSERT INTO name(busname) VALUES ($busname)"
$query2 = "INSERT INTO phone(busphone) VALUES ($busphone)"
$query3 = "INSERT INTO primary(primkey) VALUES ($primkey)"
$query4 = "INSERT INTO images(imageloc) VALUES ($imageloc)"
$result1 = mysql_query($query1);
$result2 = mysql_query($query2);
$result3 = mysql_query($query3);
$result4 = mysql_query($query4);
echo "Record updated";
?>
</BODY>
</HTML>
I just added line 32 there to show where its going wrong. I've been googling for a while trying to find a solution but I can't figure it out. I'd be really grateful if anyone could help.
Thanks
Andy Seaton
This is my first post and first attempt at PHP so sorry if this sounds daft. I'm about a fifth of the way through the php bible and a quarter through php/mysql for dummies, so it can only get better.
Anyway I'm getting this error when I try to run a form which takes the data from the form fields and inserts it into a mysql database I set up on my hosting account.
Parse error: parse error, unexpected T_STRING, expecting ']' in /home/peilife/public_html/phpform.php on line 32
Here's the code:
<HTML>
<HEAD>
<TITLE>PHP Form submit</TITLE>
<META NAME="GENERATOR" CONTENT="MAX's HTML Beauty++ 2004">
</HEAD>
<BODY>
<form action="<?php echo $SERVER['PHP_SELF]?>" method="post">
">
<p> Please enter the name of the business: <BR>
<input type="text" name="$busname" size=40 value="<?php echo $PHP_SELF?>">
<p> Please enter the phone number of the business: <BR>
<input type="text" name="$busphone" size=40 value="<?php echo $PHP_SELF?>">
<p> Please enter the primary key: <BR>
<input type="text" name="$primkey" size=40 value="<?php echo $PHP_SELF?>">
<p> Please enter the image location where the business image is stored: <BR>
<input type="text" name="$imageloc" size=40 value="<?php echo $PHP_SELF?>"> <BR>
<input type="submit" value="submit"><input type="reset" value="clear values">
<?php
$user = "peilife_admin";
$host = "localhost";
$password = "*******";
$database = "peilife_busdir"
$connection = mysql_connect($host, $user, $password) or die ("Could not make connection to server");
**line 32**mysql_select_db ('peilife_admin') or die ("Couldn't select database");
$query1 = "INSERT INTO name(busname) VALUES ($busname)"
$query2 = "INSERT INTO phone(busphone) VALUES ($busphone)"
$query3 = "INSERT INTO primary(primkey) VALUES ($primkey)"
$query4 = "INSERT INTO images(imageloc) VALUES ($imageloc)"
$result1 = mysql_query($query1);
$result2 = mysql_query($query2);
$result3 = mysql_query($query3);
$result4 = mysql_query($query4);
echo "Record updated";
?>
</BODY>
</HTML>
I just added line 32 there to show where its going wrong. I've been googling for a while trying to find a solution but I can't figure it out. I'd be really grateful if anyone could help.
Thanks
Andy Seaton
•
•
Join Date: Sep 2004
Location: in the j00-kay
Posts: 114
Reputation:
Rep Power: 4
Solved Threads: 5
$database = "peilife_busdir"
That line requires an ; (semicolon) at the end of it.
As do these lines..
$query1 = "INSERT INTO name(busname) VALUES ($busname)"
$query2 = "INSERT INTO phone(busphone) VALUES ($busphone)"
$query3 = "INSERT INTO primary(primkey) VALUES ($primkey)"
$query4 = "INSERT INTO images(imageloc) VALUES ($imageloc)"
Also line:
<form action="<?php echo $SERVER['PHP_SELF]?>" method="post">
">
shouldnt have the additional "> at the end of it...
That line requires an ; (semicolon) at the end of it.
As do these lines..
$query1 = "INSERT INTO name(busname) VALUES ($busname)"
$query2 = "INSERT INTO phone(busphone) VALUES ($busphone)"
$query3 = "INSERT INTO primary(primkey) VALUES ($primkey)"
$query4 = "INSERT INTO images(imageloc) VALUES ($imageloc)"
Also line:
<form action="<?php echo $SERVER['PHP_SELF]?>" method="post">
">
shouldnt have the additional "> at the end of it...
I'm pink, therefore, im spam.
http://www.vivaci.net - Quality Webhosting
http://gaming.vivaci.net - FAST UK Gaming servers
http://www.getsigned.org - Free Image Uploads
http://www.vivaci.net - Quality Webhosting
http://gaming.vivaci.net - FAST UK Gaming servers
http://www.getsigned.org - Free Image Uploads
•
•
Join Date: Sep 2004
Location: in the j00-kay
Posts: 114
Reputation:
Rep Power: 4
Solved Threads: 5
In the line:
mysql_select_db ('peilife_admin') or die ("Couldn't select database");
You are selecting a database with named after your username, not the database name..
Should it not be:
mysql_select_db ('peilife_busdir') or die ("Couldn't select database");
?
mysql_select_db ('peilife_admin') or die ("Couldn't select database");
You are selecting a database with named after your username, not the database name..
Should it not be:
mysql_select_db ('peilife_busdir') or die ("Couldn't select database");
?
I'm pink, therefore, im spam.
http://www.vivaci.net - Quality Webhosting
http://gaming.vivaci.net - FAST UK Gaming servers
http://www.getsigned.org - Free Image Uploads
http://www.vivaci.net - Quality Webhosting
http://gaming.vivaci.net - FAST UK Gaming servers
http://www.getsigned.org - Free Image Uploads
•
•
Join Date: Jul 2004
Posts: 187
Reputation:
Rep Power: 4
Solved Threads: 2
[PHP]$query1 = "INSERT INTO name(busname) VALUES ($busname)";
$query2 = "INSERT INTO phone(busphone) VALUES ($busphone)";
$query3 = "INSERT INTO primary(primkey) VALUES ($primkey)";
$query4 = "INSERT INTO images(imageloc) VALUES ($imageloc)";[/PHP]
Make sure to put single quote if $busname, $busphone, $primkey and $imageloc are varchar type in mysql.
Hope it helps.
$query2 = "INSERT INTO phone(busphone) VALUES ($busphone)";
$query3 = "INSERT INTO primary(primkey) VALUES ($primkey)";
$query4 = "INSERT INTO images(imageloc) VALUES ($imageloc)";[/PHP]
Make sure to put single quote if $busname, $busphone, $primkey and $imageloc are varchar type in mysql.
Hope it helps.
•
•
Join Date: Sep 2004
Posts: 25
Reputation:
Rep Power: 4
Solved Threads: 0
You should have to change the extension from *.html to *.php to execute the code that I have edited.....
You forgot to put semicolones. fix it.
Just Folow this code..
I think using PHP extension is a good approach. thank you
[PHP]
<HTML>
<HEAD>
<TITLE>PHP Form submit</TITLE>
<META NAME="GENERATOR" CONTENT="MAX's HTML Beauty++ 2004">
</HEAD>
<BODY>
<?php
echo "
<form action=\"$SERVER[PHP_SELF]\" method=post>
<p>Please enter the name of the business: <BR>
<input type=text name=busname size=40 value=$PHP_SELF>
<p> Please enter the phone number of the business: <BR>
<input type=text name=busphone size=40 value=$PHP_SELF>
<p> Please enter the primary key: <BR>
<input type=text name=primkey size=40 value=$PHP_SELF>
<p> Please enter the image location where the business image is stored: <BR>
<input type=text name=imageloc size=40 value=$PHP_SELF><BR>
<input type=submit value=submit name =submit><input type=reset value=clear name=reset>
</form>";
if ($submit=="submit"){ //$reset = reset type name and $ submit = submit type name
$user = "peilife_admin";
$host = "localhost";
$password = "*******";
$database = "peilife_busdir";
//if (!($connection = mysql_connect("localhost","","")))
if (!($connection = mysql_connect($user,$host,$password)))
{
print "<h3>could not connect to database</h3>\n";
exit;
}
//$connection = mysql_connect($host, $user, $password) or die ("Could not make connection to server");
mysql_select_db ('peilife_admin') or die ("Couldn't select database");
$query1 = "INSERT INTO name(busname) VALUES ('$busname')";
$query2 = "INSERT INTO phone(busphone) VALUES ('$busphone')";
$query3 = "INSERT INTO primary(primkey) VALUES ('$primkey')";
$query4 = "INSERT INTO images(imageloc) VALUES ('$imageloc')";
$result1 = mysql_query($query1);
$result2 = mysql_query($query2);
$result3 = mysql_query($query3);
$result4 = mysql_query($query4);
echo "Record updated";
}
?>
</BODY>
</HTML>
[/PHP]
You forgot to put semicolones. fix it.
Just Folow this code..
I think using PHP extension is a good approach. thank you
[PHP]
<HTML>
<HEAD>
<TITLE>PHP Form submit</TITLE>
<META NAME="GENERATOR" CONTENT="MAX's HTML Beauty++ 2004">
</HEAD>
<BODY>
<?php
echo "
<form action=\"$SERVER[PHP_SELF]\" method=post>
<p>Please enter the name of the business: <BR>
<input type=text name=busname size=40 value=$PHP_SELF>
<p> Please enter the phone number of the business: <BR>
<input type=text name=busphone size=40 value=$PHP_SELF>
<p> Please enter the primary key: <BR>
<input type=text name=primkey size=40 value=$PHP_SELF>
<p> Please enter the image location where the business image is stored: <BR>
<input type=text name=imageloc size=40 value=$PHP_SELF><BR>
<input type=submit value=submit name =submit><input type=reset value=clear name=reset>
</form>";
if ($submit=="submit"){ //$reset = reset type name and $ submit = submit type name
$user = "peilife_admin";
$host = "localhost";
$password = "*******";
$database = "peilife_busdir";
//if (!($connection = mysql_connect("localhost","","")))
if (!($connection = mysql_connect($user,$host,$password)))
{
print "<h3>could not connect to database</h3>\n";
exit;
}
//$connection = mysql_connect($host, $user, $password) or die ("Could not make connection to server");
mysql_select_db ('peilife_admin') or die ("Couldn't select database");
$query1 = "INSERT INTO name(busname) VALUES ('$busname')";
$query2 = "INSERT INTO phone(busphone) VALUES ('$busphone')";
$query3 = "INSERT INTO primary(primkey) VALUES ('$primkey')";
$query4 = "INSERT INTO images(imageloc) VALUES ('$imageloc')";
$result1 = mysql_query($query1);
$result2 = mysql_query($query2);
$result3 = mysql_query($query3);
$result4 = mysql_query($query4);
echo "Record updated";
}
?>
</BODY>
</HTML>
[/PHP]
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
Similar Threads
- Setting up a form in PHP (PHP)
- Need help with changing the index.php file (Existing Scripts)
- Can we execute command line cmds from a php file?? (PHP)
- Problems with PHP and the mysql_connect() command. (PHP)
- PHP file calling html control names (PHP)
- PHP5x,Apache2.2 : Apache not reading php file (PHP)
- PHP file displaying wrongly ??? (PHP)
- Get the name of the current php file (PHP)
- What is the purpose of the "lib.php" file?? (PHP)
Other Threads in the PHP Forum
- Previous Thread: ftp help
- Next Thread: uber newbie :(


Linear Mode