• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

PHP help

GregT

Waffles!!
NLC
I havent worked in PHP for awhile, so Im rusty at it. heres my code

PHP:
<?php
$submit=$_GET['submit'];
if ($submit){
$host = "localhost";
$user = "zeros_clients";
$pass = "######";
$database = "zeros_clients";

$link = mysql_connect($host,$user,$pass);

mysql_select_db($database, $link);
$username="$_GET['username']";
$email="$_GET['email']";
$paydate="$_GET['month']/$_GET['day']/$_GET['year']";
$result = mysql_query("INSERT INTO clients VALUES('$username','$email','$paydate');");

echo "Client $username added sucessfully !";
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
Add a Client<br>
<br>
<form name="form1" method="post" action="newclient.php">
  <p>Username: 
    <input type="text" name="username">
    <br>
    Email: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    <input type="text" name="email">
    <br>
    Pay Date: &nbsp; 
    <select name="month" id="month">
      <option>01</option>
      <option>02</option>
      <option>03</option>
      <option>04</option>
      <option>05</option>
      <option>06</option>
      <option>07</option>
      <option>08</option>
      <option>09</option>
      <option>10</option>
      <option>11</option>
      <option>12</option>
    </select>
    <select name="day" id="day">
      <option>01</option>
      <option>02</option>
      <option>03</option>
      <option>04</option>
      <option>05</option>
      <option>06</option>
      <option>07</option>
      <option>08</option>
      <option>09</option>
      <option>10</option>
      <option>11</option>
      <option>12</option>
      <option>13</option>
      <option>14</option>
      <option>15</option>
      <option>16</option>
      <option>17</option>
      <option>18</option>
      <option>19</option>
      <option>20</option>
      <option>21</option>
      <option>22</option>
      <option>23</option>
      <option>24</option>
      <option>25</option>
      <option>26</option>
      <option>27</option>
      <option>28</option>
      <option>29</option>
      <option>30</option>
      <option>31</option>
    </select>
    <select name="year" id="year">
      <option>2003</option>
      <option>2004</option>
      <option>2005</option>
    </select>
    <br>
    <br>
    <input type="submit" name="Submit" value="Submit">
    <br>
  </p>
  </form>
</body>
</html>

Heres the error

PHP:
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /home/zeros/public_html/ex/newclient.php on line 12
 
Last edited:
first off, you shouldn't use quotes around $_GET[] variables... and your $result variable's mysql syntax is incorrect. try changing them all to:
PHP:
$username = $_GET['username'];
$email = $_GET['email'];
$paydate = $_GET['month'] . "/" . $_GET['day'] . "/" . $_GET['year'];
$result = mysql_query("INSERT INTO clients VALUES ('" . $username . "','" . $email . "','" . $paydate . "')");
or even quicker:
PHP:
$result = mysql_query("INSERT INTO clients VALUES ('" . $_GET['username'] . "','" . $_GET['email'] . "','" . $_GET['month'] . "/" . $_GET['day'] . "/" . $_GET['year'] . "')");

that may fix your problem. if not, i don't have the time to upload it and create a database just to troubleshoot it for you. :cool:
 
try this:
PHP:
$username = $_GET['username'];
$email = $_GET['email'];
$paydate = $_GET['month'] . "/" . $_GET['day'] . "/" . $_GET['year'];
$result = mysql_query("INSERT INTO clients VALUES ('" . $username . "', '" . $email . "', '" . $paydate . "')");

// now run the mysql_query()
if ($result) echo "Client '" . $username . "' added sucessfully!";
else echo "Client '" . $username . "' could not be added.";
i added an if-else statement to handle the $result variable, which i just noticed you left out, and is definitely the reason it's not working. if that doesn't work now, i don't know what to tell you...
 
i left the $result vaiable because he used it. i'm not going to change his code on him, i'm going to show him how to get his code to work.
 
$result is needed to make sure it's a valid query. Perhaps, there were inconsistency between table field type and its value, so that the query was not executed.

Another way to check whether a statement is a valid query:
mysql_query($pointerToQuery) or die("Wrong query");
 
$username = "$_GET['username']";

this statement is valid only when you rewrite the script as:
set_magic_quotes_runtime(0); //could be ignored
$username = "$_GET[username]";
 
Not sure if you are suggesting he use: $username = "$_GET[username]";, but that's not good either. Do it like keith said:

$username = $_GET['username'];

Also, on error try printing a mysql_error() and seeing what the problem is...
 
Back
Top