Script Not Working Grrrr

Web page creation, programs, scripts, PHP, SQL?

Moderator: Moderators

Postby darenwilko » Sun Sep 12, 2004 11:54 am

hey all,
sorry to annoy u again but i have this code and i can't seem to get it to work all it says is
Parse error: parse error, unexpected $ in /home/p/ppp/public_html/register.php on line 198


but i dont have a $ on line 198

anyway here it is... Hope it nutting stupid lol

Code: Select all
<?php

include("config.php");

// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());

// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());

// check if the username is taken
$check = "select id from $table where username = '".$_POST['username']."';";
$qry = mysql_query($check)
or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry);
if ($num_rows != 0) {
echo "<html>
<head>
<title>:: Peer Pressure Possie ::</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">
</head>
<body bgcolor=\"#000000\" text=\"#FFFFFF\" link=\"#FFFFFF\" vlink=\"#FFFFFF\" alink=\"#FFFFFF\" leftmargin=\"0\" topmargin=\"0\">

<!-- ImageReady Slices (layout.psd) -->
<!-- End ImageReady Slices -->
<div align=\"center\">
  <center>
  <table border=\"0\" width=\"100%\" height=\"100%\" cellspacing=\"0\" cellpadding=\"0\">
    <tr>
      <td width=\"100%\"><div align=\"center\">
  <center>
<table width=\"700\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
   <tr>
  <td colspan=\"4\">
     <img src=\"images/index_01.gif\" width=\"700\" height=\"14\"></td>
   </tr>
   <tr>
  <td rowspan=\"4\">
     <img src=\"images/index_02.gif\" width=\"36\" height=\"486\"></td>
  <td colspan=\"2\" background=\"images/index_03.gif\" width=\"635\" height=\"333\" valign=\"top\">
  </center>
  </center>
    <table border=\"0\" width=\"100%\" height=\"100%\" cellspacing=\"0\" cellpadding=\"14\">
      <tr>
        <td width=\"100%\" valign=\"top\">
  <p align=\"center\"><font size=\"6\" face=\"Impact\">Error<br></font><font size=\"2\" face=\"Arial\">Okay...
  The username you have choosen has already been taken... But dont cry just choose another. <a href=\"javascript:history.go(-1)\">Click here to go back</a></font></p>
        </td>
      </tr>
    </table>
</td>
  <center>
  <center>
  <td rowspan=\"4\">
     <img src=\"images/index_04.gif\" width=\"29\" height=\"486\"></td>
   </tr>
   <tr>
  <td colspan=\"2\">
     <img src=\"images/index_05.gif\" width=\"635\" height=\"24\"></td>
   </tr>
   <tr>
  <td rowspan=\"2\">
     <img src=\"images/index_06.gif\" width=\"177\" height=\"129\"></td>
  <td background=\"images/index_07.gif\" width=\"458\" height=\"109\">
            <table border=\"0\" width=\"100%\" height=\"100\" cellspacing=\"0\" cellpadding=\"10\">
              <tr>
                <td width=\"92%\" valign=\"top\">
                <iframe src=\"menu.html\" name=\"menu\" width=\"408\"
                height=\"86\" frameBorder=\"0\" scrolling=\"no\"></iframe>
                </td>
                <td width=\"8%\"></td>
              </tr>
            </table>
        </td>
   </tr>
   <tr>
  <td>
     <img src=\"images/index_08.gif\" width=\"458\" height=\"20\"></td>
   </tr>
</table>
  </center>
<font face=\"Arial\" size=\"1\">Site made by Daren Wilkinson
</div>
        </font></center>
</td>
    </tr>
  </table>
</div>

</body>
</html>";
exit;
}
else {


// insert the data
$insert = mysql_query("INSERT INTO users (
     username,
     password,
     regdate,
     email,
     website,
     location,
     show_email,
     last_login)
     VALUES (
     '".$_POST['username']."',
     '".$_POST['password']."',
     '".$today = date("j d, Y")."',
     '".$_POST['email']."',
     '".$_POST['website']."',
     '".$_POST['location']."',
     '".$_POST['show_email']."',
     'Never')")

or die("Could not insert data because ".mysql_error());

// print a success message
echo "<html>
<head>
<title>User Registration</title>
</head>

<body>
<div align=\"center\">
  <center>
  <table border=\"0\" width=\"100%\" height=\"100%\" cellspacing=\"0\" cellpadding=\"0\">
    <tr>
      <td width=\"100%\"><div align=\"center\">
  <center>
<table width=\"700\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
   <tr>
  <td colspan=\"4\">
     <img src=\"images/index_01.gif\" width=\"700\" height=\"14\"></td>
   </tr>
   <tr>
  <td rowspan=\"4\">
     <img src=\"images/index_02.gif\" width=\"36\" height=\"486\"></td>
  <td colspan=\"2\" background=\"images/index_03.gif\" width=\"635\" height=\"333\" valign=\"top\">
  </center>
  </center>
    <table border=\"0\" width=\"100%\" height=\"100%\" cellspacing=\"0\" cellpadding=\"14\">
      <tr>
        <td width=\"100%\" valign=\"top\">
  <p align=\"center\"><font size=\"6\" face=\"Impact\">Sucess!!!<br></font><font size=\"2\" face=\"Arial\">Done!...
  You are now registered to the PPP website.<br>
 Oh... btw you will notice a Public Pic's Section in the Gallery, this section is for you! Go crazy add lots ov pics, remember it is up to you to keep that part of the site exciting! Here is the link to the Upload Page <a href=\"http://mandrake.polarhome.com/~galleryp/gallery/The_Publics_Pics/addphoto.php\">Upload Pictures Now</a></font></p>
        </td>
      </tr>
    </table>
</td>
  <center>
  <center>
  <td rowspan=\"4\">
     <img src=\"images/index_04.gif\" width=\"29\" height=\"486\"></td>
   </tr>
   <tr>
  <td colspan=\"2\">
     <img src=\"images/index_05.gif\" width=\"635\" height=\"24\"></td>
   </tr>
   <tr>
  <td rowspan=\"2\">
     <img src=\"images/index_06.gif\" width=\"177\" height=\"129\"></td>
  <td background=\"images/index_07.gif\" width=\"458\" height=\"109\">
            <table border=\"0\" width=\"100%\" height=\"100\" cellspacing=\"0\" cellpadding=\"10\">
              <tr>
                <td width=\"92%\" valign=\"top\">
                <iframe src=\"menu.html\" name=\"menu\" width=\"408\"
                height=\"86\" frameBorder=\"0\" scrolling=\"no\"></iframe>
                </td>
                <td width=\"8%\"></td>
              </tr>
            </table>
        </td>
   </tr>
   <tr>
  <td>
     <img src=\"images/index_08.gif\" width=\"458\" height=\"20\"></td>
   </tr>
</table>
  </center>
<font face=\"Arial\" size=\"1\">Site made by Daren Wilkinson -
There is
</div>
        </font></center>
</td>
    </tr>
  </table>
</div>

</body>
</html>";

 ?>
darenwilko
 

Postby miker_alpha » Sun Sep 12, 2004 6:22 pm

to save us having to select, copy and paste into a file, and then count 198 lines down: where (approximately) is line 198?

:shock:
MikeR
Look for OpenVMS help on my webpage
Check for QOTD here.
Image
User avatar
miker_alpha
Moderator
Moderator
 
Posts: 256
Joined: Sat May 08, 2004 9:20 am
Location: Kibbutz Tzora, Israel

Postby DenisF » Sun Sep 12, 2004 6:29 pm

He doesn't even have a line 198 to begin with, cause the final ?> is line 197
Image
[ FAQ ] :: [ Policy ] :: [ Port Forwarding Guide ] :: [ Search ]
User avatar
DenisF
Forum Admin
Forum Admin
 
Posts: 679
Joined: Mon Dec 16, 2002 9:09 pm
Location: Israhell

Postby darenwilko » Mon Sep 13, 2004 12:53 am

thats what is confusing me... ever seen this before?
darenwilko
 

Postby DenisF » Mon Sep 13, 2004 8:44 am

Nope, never.

btw, echoing full chunks of HTML code is a very ugly method to build pages,
calling php where you need it, is a much faster and cleaner solution, in my opinion.
Image
[ FAQ ] :: [ Policy ] :: [ Port Forwarding Guide ] :: [ Search ]
User avatar
DenisF
Forum Admin
Forum Admin
 
Posts: 679
Joined: Mon Dec 16, 2002 9:09 pm
Location: Israhell

Postby miker_alpha » Mon Sep 13, 2004 10:34 am

offhand I would guess at an unmatched "something": unescaped quote, curly-bracket, if/endif.

Try debugging by splitting into parts: e.g. cut the routine that sends a success message (can't it be in pure HTML? at least for debugging...)

If you can, try running PHP online. I know more/less how to do that on my own system; I'm sure you can on yours too. Its makes debugging in sections easier. (just what's easier for me; it may not suit you.)

Good luck!

MikeR
Look for OpenVMS help on my webpage
Check for QOTD here.
Image
User avatar
miker_alpha
Moderator
Moderator
 
Posts: 256
Joined: Sat May 08, 2004 9:20 am
Location: Kibbutz Tzora, Israel

Postby bbs » Mon Sep 13, 2004 4:13 pm

you get an error on line 198 , the code is 197 lines long.
so the error must be in the output.
i suggest u code it in blocks (or more clearly).
dont output all in once, that might cause errors.
bbs
 

Postby afonic » Mon Sep 13, 2004 5:07 pm

Why don't you just add two <?php include(); ?> and add the pages instead of writing the whole HTML code? It must be much better to maintain the code that way.
User avatar
afonic
Forum Admin
Forum Admin
 
Posts: 686
Joined: Tue Oct 14, 2003 11:11 pm
Location: Salonica, Greece

Postby bbs » Mon Sep 13, 2004 10:19 pm

afonic is right, since your html but is not dynamic and doesnt use any php theres no need at all to echo it.

using includes might be an idea.
if ($var) { include ('GOOD.html'); }
else { include ('BAD.html') }

saves you alot of trouble
bbs
 

Postby DenisF » Mon Sep 13, 2004 11:45 pm

Aren't you guys repeating what i just said? :blink:
Image
[ FAQ ] :: [ Policy ] :: [ Port Forwarding Guide ] :: [ Search ]
User avatar
DenisF
Forum Admin
Forum Admin
 
Posts: 679
Joined: Mon Dec 16, 2002 9:09 pm
Location: Israhell

Postby miker_alpha » Tue Sep 14, 2004 7:47 am

Aren't you guys repeating what i just said?


Yes, but we're only emphasizing how correct you are/were... ;)

MikeR
Look for OpenVMS help on my webpage
Check for QOTD here.
Image
User avatar
miker_alpha
Moderator
Moderator
 
Posts: 256
Joined: Sat May 08, 2004 9:20 am
Location: Kibbutz Tzora, Israel

Postby DenisF » Tue Sep 14, 2004 9:02 am

lol
Image
[ FAQ ] :: [ Policy ] :: [ Port Forwarding Guide ] :: [ Search ]
User avatar
DenisF
Forum Admin
Forum Admin
 
Posts: 679
Joined: Mon Dec 16, 2002 9:09 pm
Location: Israhell

Postby afonic » Tue Sep 14, 2004 10:44 am

I *thought* you said that he should use an HTML page which should call the php script, while I just said to replace the echo with include().

But I'm always drunk lately anyway, so I don't read posts very good (see an example in the IRC board!) :)
User avatar
afonic
Forum Admin
Forum Admin
 
Posts: 686
Joined: Tue Oct 14, 2003 11:11 pm
Location: Salonica, Greece

Postby darenwilko » Tue Sep 14, 2004 11:51 am

Hey thanks guys, im not very good at php but i try lol, dont mean to cause arguements lol...

Do you reckon this work??? :unsure:

Code: Select all
<?php

include("config.php");

// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());

// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());

// check if the username is taken
$check = "select id from $table where username = '".$_POST['username']."';";
$qry = mysql_query($check)
or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry);
if ($num_rows != 0) {
echo "include ('error.php');";
exit;
}
else {


// insert the data
$insert = mysql_query("INSERT INTO users (
     username,
     password,
     regdate,
     email,
     website,
     location,
     show_email,
     last_login)
     VALUES (
     '".$_POST['username']."',
     '".$_POST['password']."',
     '".$today = date("j d, Y")."',
     '".$_POST['email']."',
     '".$_POST['website']."',
     '".$_POST['location']."',
     '".$_POST['show_email']."',
     'Never')")

or die("Could not insert data because ".mysql_error());

// print a success message
echo "include ('sucess.php');";
 ?>
darenwilko
 

Postby afonic » Tue Sep 14, 2004 2:18 pm

I *think* that this one:

Code: Select all
if ($num_rows != 0) {
echo "include ('error.php');";


should be like this:

Code: Select all
if ($num_rows != 0) { include ('error.php'); };


But of course I may be wrong! :P

Edit: Missed a [/CODE] tag. :(
User avatar
afonic
Forum Admin
Forum Admin
 
Posts: 686
Joined: Tue Oct 14, 2003 11:11 pm
Location: Salonica, Greece

Postby darenwilko » Tue Sep 14, 2004 11:53 pm

kool thanks,
and i take it is like that for the other one aswell?
darenwilko
 

Postby darenwilko » Wed Sep 15, 2004 7:27 am

thanks guys you have been a great help...
I have come up with this lol

Code: Select all
<?php

include("config.php");

// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());

// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());

// check if the username is taken
$check = "select id from $table where username = '".$_POST['username']."';";
$qry = mysql_query($check)
or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry);
if ($num_rows != 0) { include ('error.php'); };



// insert the data
$insert = mysql_query("INSERT INTO users (
     username,
     password,
     regdate,
     email,
     website,
     location,
     show_email,
     last_login)
     VALUES (
     '".$_POST['username']."',
     '".$_POST['password']."',
     '".$today = date("j d, Y")."',
     '".$_POST['email']."',
     '".$_POST['website']."',
     '".$_POST['location']."',
     '".$_POST['show_email']."',
     'Never')")

or die("Could not insert data because ".mysql_error());


// print a success message
include ('sucess.php');
?>


but it always shows both sucess and error when there is an error i need like

Code: Select all
<?php

include("config.php");

// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());

// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());

// check if the username is taken
$check = "select id from $table where username = '".$_POST['username']."';";
$qry = mysql_query($check)
or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry);
if ($num_rows != 0) { include ('error.php'); };

else {

// insert the data
$insert = mysql_query("INSERT INTO users (
     username,
     password,
     regdate,
     email,
     website,
     location,
     show_email,
     last_login)
     VALUES (
     '".$_POST['username']."',
     '".$_POST['password']."',
     '".$today = date("j d, Y")."',
     '".$_POST['email']."',
     '".$_POST['website']."',
     '".$_POST['location']."',
     '".$_POST['show_email']."',
     'Never')")

or die("Could not insert data because ".mysql_error());


// print a success message
include ('sucess.php');};
?>

so it only does one... but my example dont work lol as usual... what do you guys reckon?
darenwilko
 

Postby DenisF » Wed Sep 15, 2004 7:56 am

urm i think that this is your problem;
Code: Select all
$num_rows = mysql_num_rows($qry);
if ($num_rows != 0) { include ('error.php'); };


So you query the DB and if the returned number of rows is above 0, you display an error messege. [which seems odd, cause a number that is higher than 0 would mean success in your script, no?]
Image
[ FAQ ] :: [ Policy ] :: [ Port Forwarding Guide ] :: [ Search ]
User avatar
DenisF
Forum Admin
Forum Admin
 
Posts: 679
Joined: Mon Dec 16, 2002 9:09 pm
Location: Israhell

Postby demondev_redhat » Mon May 30, 2005 3:50 pm

well the code stops at line 197 because he didnt give us the code from config.php, his codes is longer when viewed because the script includes config.php

Code: Select all
include("config.php");
demondev_redhat
Newbie
 
Posts: 5
Joined: Fri Apr 08, 2005 9:49 pm
Location: ny

Postby hu8_debian » Wed May 24, 2006 10:27 pm

Is the '{' in line 96 (after the else) closed somewhere?


@demondev_redhat: No, I don't think that the line numbers change with require/include ;-) If there'd be an error in config.php he would show the error message with "in file ..../.../config.php"

Correct me if I'm wrong... :?
hu8_debian
Newbie
 
Posts: 9
Joined: Tue May 23, 2006 6:18 pm
Location: Wien

Next

Return to Web development

Who is online

Users browsing this forum: No registered users and 0 guests

cron