Web Hosting Talk







View Full Version : little help debugging


Jouninshinobi
08-29-2004, 05:52 PM
I keep having this error come up on my form

Parse error: parse error, unexpected T_STRING in /home/jounin/public_html/adding.php on line 11

This is the program, what am I doing wrong?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>PHP Form Test</title>
</head>
<body>
<?php
$db = mysql_connect("localhost", "jounin", "b112288")
or die("couldn't connect to server")
mysql_select_db("jounin_users")
or die("couldn't connect to database")
$query=INSERT INTO user_information (name1, name2, pass, email)
VALUES('".$_POST['name1']."','".$_POST['name2']."','".$_POST['pass']."','".$_POST['email'])";
$result = mysql_query($query);
echo 'Link entered.';

?>

</body>
</html>

armstrongecom
08-29-2004, 08:49 PM
Looks like you may be missing semi-colons at the end of some of your PHP lines.

EXOWorks
08-29-2004, 08:55 PM
Yes, you are missing semicolons...
$db = mysql_connect("localhost", "jounin", "b112288")
or die("couldn't connect to server") // semicolon missing
mysql_select_db("jounin_users")
or die("couldn't connect to database") // semicolon missing

Burhan
08-30-2004, 03:34 AM
$query=INSERT INTO user_information (name1, name2, pass, email)

You are missing the beginning "

Along with missing ; as others suggested.

Jouninshinobi
08-30-2004, 08:38 AM
oops forgot some of the simplest things :blush:

I understand the ; and now that part works but where exactly do I put the "

azizny
08-30-2004, 09:01 AM
When you make queries you encap them in "":


$mysql_query = "SELECT * FROM USERS";

or
$mysql_query = @mysql_query("SELECT * FROM USERS");

Peace,

Jouninshinobi
08-30-2004, 09:12 AM
thanks, but now I'm getting that T_STRING error in line 15

$query="INSERT INTO" user_information("name1", "name2", "pass", "email");

kneuf
08-30-2004, 10:00 AM
use this instead:
$query="INSERT INTO user_information ('name1', 'name2', 'pass', 'email')
VALUES('".$_POST['name1']."','".$_POST['name2']."','".$_POST['pass']."','".$_POST['email'].")";

Jouninshinobi
08-30-2004, 10:43 AM
Its still not workin heres the entire code for anyone to correct

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>PHP Form Test</title>
</head>
<body>
<?php
$db = mysql_connect("localhost", "jounin", "b112288")
or die("couldn't connect to server");
mysql_select_db("jounin_users")
or die("couldn't connect to database");



$query="INSERT INTO user_information ('name1', 'name2', 'pass', 'email');
VALUES('".$_POST['name1']."','".$_POST['name2']."','".$_POST['pass']."','".$_POST['email'])";
$result = mysql_query($query);
echo 'Link entered.';

?>

</body>
</html>

armstrongecom
08-30-2004, 11:02 AM
Try this...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>PHP Form Test</title>
</head>
<body>
<?php
$db = mysql_connect("localhost", "jounin", "b112288") or die("couldn't connect to server");

mysql_select_db("jounin_users") or die("couldn't connect to database");

$query="INSERT INTO user_information (name1, name2, pass, email) VALUES ('".$_POST['name1']."', '".$_POST['name2']."', '".$_POST['pass']."', '".$_POST['email']')";

$result = mysql_query($query);

echo 'Link entered.';

?>

</body>
</html>

azizny
08-30-2004, 11:21 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>PHP Form Test</title>
</head>
<body>
<?php
$db = mysql_connect("localhost", "jounin", "b112288");
or die("couldn't connect to server");
mysql_select_db("jounin_users")
or die("couldn't connect to database");


$query = @mysql_query("INSERT INTO user_information ('name1', 'name2', 'pass', 'email') VALUES('$_POST[name1]','$_POST[name2]','$_POST[pass]','$_POST[email]')");
if($query){
echo 'Link entered.';
} else {
echo 'error while entering link';
}

?>
</body>
</html>


As you can see your error when making the query was that you ending the statement ; before you finished querying, the ; comes when the line ends. so if it is 20 lines long (the query) there will only be one ; at the end.

Peace,

Jouninshinobi
08-30-2004, 12:21 PM
ok the php file is working thanks to all your help. Thx alot, but for some reason I keep getting error while entering link, I think its because of my password question on my html form. Am I right? Can someone help me? Heres the html (its nothing special):

<html>
<head>
<title>PHP Form Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="php form" action="adding.php" method="post">
<p>
<input type="text" maxlength="20" value="" name="name1"> Insert First Name </p>
<p>
<input type="text" maxlength="20" value="" name="name2"> Insert Last Name </p>
<p>
<input type="password" maxlength="220" value="" name="pass"> Insert Password </p>
<p>
<input type="text" maxlength="40" value="" name="email"> Insert Email</p>
<p>
<input type="submit" value="Submit" name="Submit">
<input type="reset" value="Reset" name="Reset"> </p></form><!--p
-->
</body>
</html>

azizny
08-30-2004, 04:00 PM
Use this code:


<html>
<head>
<title>PHP Form Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
//function to connect to database
function connect_me(){
$db = mysql_connect("localhost", "jounin", "b112288")
or die("couldn't connect to server");
mysql_select_db("test")
or die("couldn't connect to database");
}

//function to disconnect from database
function diconnect_me(){
@mysql_close();
}

if(isset($_POST['Submit'])){
connect_me();
$query = @mysql_query("INSERT INTO user_information ('name1', 'name2', 'pass', 'email') VALUES('$_POST[name1]','$_POST[name2]','$_POST[pass]','$_POST[email]')");
if($query){
echo 'Link entered.';
} else {
echo 'error while entering link';
}
diconnect_me();
}

?>
<form name="php form" action="addlink.php" method="post">
<p>
<input type="text" maxlength="20" value="" name="name1"> Insert First Name </p>
<p>
<input type="text" maxlength="20" value="" name="name2"> Insert Last Name </p>
<p>
<input type="password" maxlength="220" value="" name="pass"> Insert Password </p>
<p>
<input type="text" maxlength="40" value="" name="email"> Insert Email</p>
<p>
<input type="submit" value="Submit" name="Submit">
<input type="reset" value="Reset" name="Reset"> </p></form><!--p
-->
</body>


I added the check for making sure the form is submitted before trying to enter the url into the database.

Peace,