GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 13-Aug-2003, 03:34
ukrspp21 ukrspp21 is offline
New Member
 
Join Date: Jul 2003
Location: London
Posts: 17
ukrspp21 is an unknown quantity at this point

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in


Dear All

I am trying to create a form in which users can update their prefrences, Address, Phone no., contact prefrence etc. The code I am using is below. The code is very scrapy but I have been trying many things. I am trying to check whether a field in a form contains any data if so update the db. I am trying to stop the update function from empting my db.

I have a feeling that I am accessing an array variable incorrectly, but am at a lose as to how to fix. Any help would be appreciated.

Best Regards
Phil

Error:
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /home/sites/site112/web/user_prefs9.php on line 66



PHP Code:

<?php

require_once('incl_funs.php');
  session_start();
  do_header('Prefrences Updated', 'Prefs<br/>Updated', 4, 1);
  check_valid_user();
  //create short names
      $username = $HTTP_SESSION_VARS['valid_user'];
    $salutation =$HTTP_POST_VARS['salutation'];
    $cname = $HTTP_POST_VARS['cname'];
    $fname = $HTTP_POST_VARS['fname'];
    $company = $HTTP_POST_VARS['company'];
    $jobtitle = $HTTP_POST_VARS['jobtitle'];
    $phoneno = $HTTP_POST_VARS['phoneno'];
    $mobileno = $HTTP_POST_VARS['mobileno'];
    $faxno = $HTTP_POST_VARS['faxno'];
    $email = $HTTP_POST_VARS['email'];
    $address1 = $HTTP_POST_VARS['address1'];
    $address2 = $HTTP_POST_VARS['address2'];
    $town = $HTTP_POST_VARS['town'];
    $city = $HTTP_POST_VARS['city'];
    $county = $HTTP_POST_VARS['county'];
    $postcode = $HTTP_POST_VARS['postcode'];
    $country = $HTTP_POST_VARS['country'];
    $contact_method = $HTTP_POST_VARS['contact_method'];
    
  function clean(&$value)
 {
 $value=trim($value);
 addslashes($value);
 ucwords($value);
  };
 
 array_walk($_POST, 'clean');
  valid_email($email);
  $details = array(
         'salutation'=>$salutation,
         'cname'=>$cname,
         'fname'=>$fname,
         'company'=>$company,
         'jobtitle'=>$jobtitle,
         'phoneno'=>$phoneno,
         'mobileno'=>$mobileno,
         'faxno'=>$faxno,
         'address1'=>$address1,
         'address2'=>$address2,
         'town'=>$town,
         'city'=>$city,
         'county'=>$county,
         'postcode'=>$postcode,
         'country'=>$country,
         'contact_method'=>$contact_method
 );    
    
   
   do_db_connect();
   $db_conn = mysql_pconnect();
   mysql_select_db('username', $db_conn);
   
   reset($details);
   $no_items = count($details);
   while($element = each($details))
   {
       if(!empty($element['value']))
   {
//error is here   
$result = mysql_query("update userdata set'$element['key']' = '$element['value']' where username = '$username'", $db_conn);
   }
   } 
   
    if(!empty($email))   {
       
$result1 = mysql_query( "update users
                            set email = ('$email')
                            where username = ('$username')", $db_conn);
                            }
                            
    if (!$result && !$result1)
     {echo '<p class="body">Your details could not be updated please try again.</p>';}
    else
     {echo '<p class="body" align="center">Your details were updated</p>';}
    
do_footer();
?>

  #2  
Old 13-Aug-2003, 05:13
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
I didn't go through all your code, so this may eliminate the error or it may not:
PHP Code:

<?php
// replace this:
// $result = mysql_query("update userdata set'$element['key']' = '$element['value']' where username = '$username'", $db_conn);

// with
$result = mysql_query( "update `userdata` set `".$element['key']."` = '".$element['value']."' where username = '$username'", $db_conn );
?>


By the way, didn't you ask something similar a few days ago, or was that someone else? :-)
  #3  
Old 13-Aug-2003, 05:23
ukrspp21 ukrspp21 is offline
New Member
 
Join Date: Jul 2003
Location: London
Posts: 17
ukrspp21 is an unknown quantity at this point
Yeah sorry I did.

Please accept my appolgises I had totally forgotten that I had done. I am kind of getting brain melt down.

Thank you for your help again.
Phil
  #4  
Old 21-Aug-2003, 08:03
dexthageek dexthageek is offline
New Member
 
Join Date: Aug 2003
Posts: 4
dexthageek is an unknown quantity at this point
I am having a similar problem with my code on update.
I am receiving Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' whenever I attempt to execute the script.

PHP Code:

<?php 

include 'accesscontrol.php';
include_once 'common.php'; 
include_once 'db.php';

 dbConnect("test_db"); 
  $sql = "SELECT * FROM auth_users WHERE 
  UserID = '$uid' AND Password = '$pwd'"; 
  $result = mysql_query($sql); 

   if (!$result) 
     { 
      error('A database error occurred while checking your '. 
      'login details.\\n If This error persists, please '. 
      'contact admin@example.com.');
     }


$date = mysql_result($result,0,'Date_Created');
$userid = mysql_result($result,0,'UserID');
$firstname = mysql_result($result,0,'FName');
$lastname = mysql_result($result,0,'LName');
$email = mysql_result($result,0,'email');
$user_rank =  mysql_result($result,0,'rank');

?>

 <form action="<?=$_SERVER['PHP_SELF']?>" method="post">  
       <table width="300" align="center">
        <tr>
         <td width="100" align="right"><div id="storetext">Account Created: </div></td>
         <td width="100" align="left"><div id="storetext"><?=$date?></div></td>
        </tr>
        <tr>
         <td width="100" align="right"><div id="storetext">UserID: </div></td>
         <td width="100" align="left"><input type="text" name="update_userid" size="25" value="<?=$userid?>"></td> 
        </tr>
        <tr>
         <td width="100" align="right"><div id="storetext">First Name: </div></td>
         <td width="100" align="left"><input type="text" value="<? echo "$firstname" ?>" name="update_firstname" size="25"></td> 
        </tr>
        <tr>
         <td width="100" align="right"><div id="storetext">Last Name: </div></td>
         <td width="100" align="left"><input type="text" name="update_lastname" size="25" value="<? echo "$lastname" ?>"></td> 
        </tr>
        <tr>
         <td width="100" align="right"><div id="storetext">Email: </div></td>
         <td width="100" align="left"><input type="text" name="update_email" size="25" value="<? echo "$email" ?>"></td> 
        </tr>
        <tr>
         <td width="100" align="right"><div id="storetext">Rank: </div></td>
         <td width="100" align="left">
           <?
              if ($userpriv == "admin")
               {
                 ?>
                    <input type="text" name="rank" size="25" value="<? echo "$user_rank" ?>">
                 <?
               }
              else
               {
                 ?>
                  <div id="storetext"><? echo "$user_rank" ?></div>
                 <?
               }
           ?>
         </td> 
        </tr>
        <tr>
         <td colspan="2"><hr noshade><input type="Submit" value="Update"><input type="reset" value="Reset"></td>
        </tr>
       </table>
      </form>

<?php

//Assign Values from form to variables


if (isset($_POST['update_userid']))
 {

//Testing to make sure variables are being passed

echo 'Testing to make  sure variables are being passed';
echo '<br>';
echo $_POST['update_userid'];
echo '<br>';
echo $update_userid;
echo '<br>';
echo $update_lastname;
echo '<br>';
echo $update_email;

dbConnect("test_db"); 
  //Error is on the line below
  $sql = "UPDATE auth_users SET UserID = $_POST['update_userid'] Fname = $_POST['update_firstname'] LName = $_POST['update_lastname'] email = $_POST['update_email'] WHERE UserID='$uid' AND Password='$pwd'";
  $result = mysql_query($sql); 

   if (!$result) 
     { 
      error('A database error occurred while checking your '. 
      'login details.\\n If This error persists, please '. 
      'contact [email]admin@example.com[/email].');
     }



 }
else
 {
  echo 'There is still a problem with your script';
 }
 
?>


If I remove my sql statement from my code the rest of the page works fine and it displays all variables they should be.

NOTE: The script is no where near final, there are other things I am gonna change, I just need this error to disappear.

Thanks in Advance

Mike
  #5  
Old 21-Aug-2003, 08:11
ukrspp21 ukrspp21 is offline
New Member
 
Join Date: Jul 2003
Location: London
Posts: 17
ukrspp21 is an unknown quantity at this point
Surround your variables like
PHP Code:

'".$var."' 



it should work.
  #6  
Old 21-Aug-2003, 08:30
dexthageek dexthageek is offline
New Member
 
Join Date: Aug 2003
Posts: 4
dexthageek is an unknown quantity at this point
Thanks, that worked on removing the error.

However now my script is throwing my DB Login Error

Here is the code for the alert its throwing up.

PHP Code:

if (!$result) 
     { 
      error('A database error occurred while checking your '. 
      'login details.\\n If This error persists, please '. 
      'contact [email]example@example.com[/email].');
     } 



So that tells me my script is having a problem writing to my database.

Have any ideas based on the code I posted in my previous post.

Thanks in Advance

Mike
  #7  
Old 21-Aug-2003, 08:36
ukrspp21 ukrspp21 is offline
New Member
 
Join Date: Jul 2003
Location: London
Posts: 17
ukrspp21 is an unknown quantity at this point
Which line? first or second.

Also seperate your field groups with commas
  #8  
Old 21-Aug-2003, 08:38
ukrspp21 ukrspp21 is offline
New Member
 
Join Date: Jul 2003
Location: London
Posts: 17
ukrspp21 is an unknown quantity at this point
Also do you know anything about working with dates with Mysql and Php?
  #9  
Old 21-Aug-2003, 08:46
dexthageek dexthageek is offline
New Member
 
Join Date: Aug 2003
Posts: 4
dexthageek is an unknown quantity at this point
thanks for the help, I think that took care of my problem.

What are you trying to do with dates?

Do you want to manipulate a TimeStamp?

Mike
  #10  
Old 21-Aug-2003, 08:54
ukrspp21 ukrspp21 is offline
New Member
 
Join Date: Jul 2003
Location: London
Posts: 17
ukrspp21 is an unknown quantity at this point
Essentially I am trying to display FTSE 100 Stock prices on my page.

I have decided to create a Mysql table which I will update daily. The primary key for this table is the date, currently a datetime field.

So I want to take todays date in php and pass it to Mysql in the form of a Sql query to return the prices.

I also what to select the previous days values to perform a change calculation.

I have a test page I am playing with at the mo, I just can't get it to return values, no errors just no matches. Thus I must assume that date format is incorrect!!

PHP Code:

$day2 = date('j m Y');
$day1 = date('Y').' '.date('m').' '.(date('j')-1);

echo $day2;
echo $day1;

$q1 = ("select * from stock where (date = '".$day1."')");
$db_conn = mysql_pconnect('localhost', , );
mysql_select_db('username', $db_conn);
$r1 = mysql_query($q1, $db_conn);
$date1 = mysql_fetch_array($r1);

echo $date1['ftse']; 



Any suggestions?
 
 

Recent GIDBlogFirst week of IA training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 02:03.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.