More PHP Processing...

CannonBallGuyCannonBallGuy ModeratorShared Hoster
lol. Okay... this time I tried to make something myself... just by editing daboss's script in my other topic... Should have been easy... but somehow I still messed it up. :(

I want someone to fill in the name of a product twice, once with capital letters and spaces (like "Big Bad Footy 2005") and once without spaces and caps (like "bigbadfooty2005" -- This field is called "codename"...)
then pick a category from a list, type in a price (like "£27.97") and a password.

Then, if all fields are filled in and the password is correct, the user is taken to a confirmation page showing all the info except the password. If it's all ok, they click Submit and the info is saved to a file called "catall.txt" and a file with the whatever was in the field "codename" with a .txt on the end. So in the Big Bad Footy example the info would write to catall.txt and "bigbadfooty2005.txt"...

Here is what I have done:


The Form "addagame.php"
<html><head><title>PS2 Mall - Admin: Add A Game</title></head><body>

<?php

$form1 = "
<form name=\"addgame\" action=\"addprocess.php\" method=\"post\">

Please choose the category the game best fits into: <br />
<select name=\"category\">
<option value=\"catactionadventure.txt\">Action & Adventure</option>
<option value=\"catarcadeplatform.txt\">Arcade & Platform</option>
<option value=\"catclassicretro.txt\">Classic & Retro</option>
<option value=\"catdrivingracing.txt\">Driving & Racing</option>
<option value=\"catfamily.txt\">Family</option>
<option value=\"catfighting.txt\">Fighting</option>
<option value=\"catroleplaying.txt\">Role playing</option>
<option value=\"catsport.txt\">Sport</option>
<option value=\"catstrategysimulation.txt\">Strategy & Simulation</option>
<option value=\"catwarmilitary.txt\">War & Military</option>
</select>
<br /><br />

Please enter the game name WITH capital letters, spaces, etc: <br />
<input type=\"text\" name=\"fullname\" value=\"\" size=\"40\" maxlength=\"40\" />
<br /><br />

Please enter the game name WITHOUT capital letters, or spaces...: <br />
<input type=\"text\" name=\"codename\" value=\"\" size=\"40\" maxlength=\"40\" />
<br /><br />

Please enter the price of the game (eg \"&pound;39.99\"): <br />
<input type=\"text\" name=\"price\" value=\"\" size=\"6\" maxlength=\"6\"/>
<br /><br />

Please enter the PASSWORD: <br />
<input type=\"text\" name=\"password\" value=\"\" size=\"40\" maxlength=\"62\"/>
<br /><br />

<input type=\"submit\" value=\"Submit\" />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<input type=\"reset\" value=\"Reset\" />
</form>";


$form2 = "
<form name=\"confirm\" action=\"process.php\" method=\"post\">

<b>Thanks<br>
Is this info Correct???</b><br><br>

Category: $category<br>
Full Name: $fullname<br>
Name without spaces and capitals etc: $codename<br>
Price: $price<br>

<input type=\"hidden\" name=\"category\" value=\"$category\">
<input type=\"hidden\" name=\"fullname\" value=\"$fullname\">
<input type=\"hidden\" name=\"codename\" value=\"$codename\">
<input type=\"hidden\" name=\"price\" value=\"$price\">
<input type=\"hidden\" name=\"password\" value=\"$password\">

</form>";


$form3 = "
<form name=\"error\" action=\"form.php\" method=\"post\">

<input type=\"hidden\" name=\"category\" value=\"$category\">
<input type=\"hidden\" name=\"fullname\" value=\"$fullname\">
<input type=\"hidden\" name=\"codename\" value=\"$codename\">
<input type=\"hidden\" name=\"price\" value=\"$price\">

</form>";

/// LOGIG BIT:

if($password!=poo){
print "ACCESS DENIED!<br>";
}
      
if($fullname==""){
print "Full Name field cannot be blank!<br>";
}
      
if($codetname==""){
print "Name without capitals etc field cannot be blank!<br>";
}
      
if($price==""){
print "Email field cannot be blank!<br>";
}
      
if($category==""){
print "Category field cannot be blank!<br>";
}
      
if($firstname=="" || $lastname=="" || $email1!=$email2 || $payment=="" || $terms!="agree"){
print "<br><br><br>$form3";
}

// everything OK - display details using $form2
// $form2 will call process.php through the post method
else{
print "$form2";

// comment the following line if you not want to provide the user a way out
print "<a href=\"avascript:history.back(1)\">Click here to modify...</a><br>";
}
}
}

?>

</body>
</html>

The Process page "addprocess.php":
<?php

// modify these variables if the data files need to be kept in different locations
$datafilespath="./";
$generalfilepath=$datafilespath."catall.txt";
$productfilepath=$datafilespath.$category;

$row=
"<table style=/"position:relative;top:0px;left:0px;height:auto;width:500px;margin:0px 50px 5px 50px;border-style:none;border-width:1px;border-color:#AA0000;text-align:center;/">
<tr style=/"width:500px;border-style:solid;border-width:1px;border-color:#AA0000;/">
<td colspan=/"2/" style=/"width:500px;border-style:solid;border-width:1px;border-color:#AA0000;/">".$fullname."
</a></td>
</tr>
<tr>
<td style=/"width:500px;border-style:solid;border-width:1px;border-color:#AA0000;/">
".$price."
</td>
<td style=/"width:500px;border-style:solid;border-width:1px;border-color:#AA0000;/"><a href=/"/form.php?p=
".$codename."
/">Buy Now!</a></td>
</tr>
</table>"

// write to general file
// the a+ option will append new records to the end of the file and create a file if the file does not exist
$file=fopen($generalfilepath, "a+");
fwrite($file, $row);
fclose($file);

// write to product file
// the a+ option will append new records to the end of the file and create a file if the file does not exist
$file=fopen($productfilepath, "a+");
fwrite($file, $row);
fclose($file);

// send email
$to="webmaster@ps2mall.co.uk";
$subject="Game Added: ".$fullname.;
$header="From:you@yourdomain.com (HEADER?)";
//uncomment this line to activate email sending :)
mail($to, $subject, $row, $header);

// inform user
print "The Game Has Been Added!!<br><br><br>";
print "<a href=\"http://www.ps2mall.co.uk/all.html">See it here!!</a><br>";

?>

When I try to show "addagame.php it says:
Parse error: parse error, unexpected '}' in /home/matsim68/public_html/PS2mall/addagame.php on line 74


Any help is greatly appreciated! :)

Thanks - CBG

Comments

  • dabossdaboss WP V.I.P. ''The Boss'' Administrator
    1. It would be helpful if you can post what line 74 is (your code, as it appears in your post has been wrapped).
    2. From a quick glance in your code, your password is "poo" and it is hardcoded in your code? This may be seen by your customers :)
    3. In any event, I'll get a working package up for you by tomorrow. I'll also put some thought into the password thing.

    I'm stuck with reading my vBulletin manual now :) It's a headace reading...
  • CannonBallGuyCannonBallGuy Moderator Shared Hoster
    I wasn't asking for you to do it... but it would be good, if it's not too much bother.

    As for the password: I didnt know of any other way of doing it...
    If you can do it another way that would be ace!


    Line 74 is a blank line.

    Line 73:
    /// LOGIG BIT:
    

    Line 75:
    if($password!=poo){
    

    Thanks :)
  • dabossdaboss WP V.I.P. ''The Boss'' Administrator
  • ForgeForge Senior Member The Royal RAM
    Maybe your missing a ' } ' somewhere above 74, check for that. I do that all the time.
    Can fat people Go skinny Dipping?
  • CannonBallGuyCannonBallGuy Moderator Shared Hoster
    I tried editing the password line but It didnt do anything...
    Then I saw this:
    /// LOGIG BIT:
    
    and changed it to this:
    /// LOGIG BIT ///
    

    And then I got a different erro about an unexpected "}" on line 107...
    So I took it out and voila.

    This is the new code for addagame.php:
    <html><head><title>PS2 Mall - Admin: Add A Game</title></head><body>
    
    <?php
    
    $form1 = "
    <form name=\"addgame\" action=\"addprocess.php\" method=\"post\">
    
    Please choose the category the game best fits into: <br />
    <select name=\"category\">
    <option value=\"catactionadventure.txt\">Action & Adventure</option>
    <option value=\"catarcadeplatform.txt\">Arcade & Platform</option>
    <option value=\"catclassicretro.txt\">Classic & Retro</option>
    <option value=\"catdrivingracing.txt\">Driving & Racing</option>
    <option value=\"catfamily.txt\">Family</option>
    <option value=\"catfighting.txt\">Fighting</option>
    <option value=\"catroleplaying.txt\">Role playing</option>
    <option value=\"catsport.txt\">Sport</option>
    <option value=\"catstrategysimulation.txt\">Strategy & Simulation</option>
    <option value=\"catwarmilitary.txt\">War & Military</option>
    </select>
    <br /><br />
    
    Please enter the game name WITH capital letters, spaces, etc: <br />
    <input type=\"text\" name=\"fullname\" value=\"\" size=\"40\" maxlength=\"40\" />
    <br /><br />
    
    Please enter the game name WITHOUT capital letters, or spaces...: <br />
    <input type=\"text\" name=\"codename\" value=\"\" size=\"40\" maxlength=\"40\" />
    <br /><br />
    
    Please enter the price of the game (eg \"&pound;39.99\"): <br />
    <input type=\"text\" name=\"price\" value=\"\" size=\"6\" maxlength=\"6\"/>
    <br /><br />
    
    Please enter the PASSWORD: <br />
    <input type=\"text\" name=\"password\" value=\"\" size=\"40\" maxlength=\"62\"/>
    <br /><br />
    
    <input type=\"submit\" value=\"Submit\" />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<input type=\"reset\" value=\"Reset\" />
    </form>";
    
    
    $form2 = "
    <form name=\"confirm\" action=\"process.php\" method=\"post\">
    
    <b>Thanks<br>
    Is this info Correct???</b><br><br>
    
    Category: $category<br>
    Full Name: $fullname<br>
    Name without spaces and capitals etc: $codename<br>
    Price: $price<br>
    
    <input type=\"hidden\" name=\"category\" value=\"$category\">
    <input type=\"hidden\" name=\"fullname\" value=\"$fullname\">
    <input type=\"hidden\" name=\"codename\" value=\"$codename\">
    <input type=\"hidden\" name=\"price\" value=\"$price\">
    <input type=\"hidden\" name=\"password\" value=\"$password\">
    
    </form>";
    
    
    $form3 = "
    <form name=\"error\" action=\"form.php\" method=\"post\">
    
    <input type=\"hidden\" name=\"category\" value=\"$category\">
    <input type=\"hidden\" name=\"fullname\" value=\"$fullname\">
    <input type=\"hidden\" name=\"codename\" value=\"$codename\">
    <input type=\"hidden\" name=\"price\" value=\"$price\">
    
    </form>";
    
    /// LOGIG BIT ///
    
    if($password!="poo"){
    print "ACCESS DENIED!<br>";
    }
          
    if($fullname==""){
    print "Full Name field cannot be blank!<br>";
    }
          
    if($codetname==""){
    print "Name without capitals etc field cannot be blank!<br>";
    }
          
    if($price==""){
    print "Email field cannot be blank!<br>";
    }
          
    if($category==""){
    print "Category field cannot be blank!<br>";
    }
          
    if($firstname=="" || $lastname=="" || $email1!=$email2 || $payment=="" || $terms!="agree"){
    print "<br><br><br>$form3";
    }
    
    // everything OK - display details using $form2
    // $form2 will call process.php through the post method
    else{
    print "$form2";
    
    // comment the following line if you not want to provide the user a way out
    print "<a href=\"avascript:history.back(1)\">Click here to modify...</a><br>";
    }
    
    ?>
    
    </body>
    </html>
    

    The problem now is that when I go to that page, I don't see the form... It just gives me all the error messages... lol...

    What have I dont wrong now?
  • dabossdaboss WP V.I.P. ''The Boss'' Administrator
    Done, tested and working... (I have commented the sending of email though - please uncomment before loading to the server).

    Didn't have time to think about the password thingy - it can easily be solved if you've got a database though...

    You've got to be more careful when you code - you got lots of syntax problems - e.g. missing " ; { etc :)

    Anyway, try it out and tell me if you need any more changes.
  • CannonBallGuyCannonBallGuy Moderator Shared Hoster
    Thabks ever so much (again!)... It works perfectly!!!

    I think this will ahve to do for now but I promise to try to learn sql etc soon.

    As for my syntax - yeah. I know. I'm new to PHP and I understand most of the logic... it's the syntax I don't like :)

    Thank again, daboss.
Sign In or Register to comment.