Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

code broken when host withdrew support for php4

Codes here !

Moderators: macek, egami, gesf

code broken when host withdrew support for php4

Postby gilk » Fri Aug 31, 2012 6:30 am

Hi,
this code worked for 4 years until host stopped supporting php4...... :-x
This script follows a login script which sets session and checks to see if the user is valid.
If valid the following script is run and now shows the error....
Couldn't execute query because: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 2

I'm afraid it has me beat! not that I am an experienced programmer, but I would appreciate anyone being able to point out why the query fails to execute.
Thanks in anticipation.

Code: Select all
<?php
/*  Program name: upd_user_details.php
 *  Description:  Script displays a form with address
 *                information obtained from the database.
 */
 
 session_start();
 //set session variables  for students id number
   $_SESSION['studentid'] = "$studentid";
        $studentid = $_SESSION['studentid'];
          $_SESSION['f_name'] = "$f_name";
        $f_name = $_SESSION['f_name'];
         $_SESSION['l_name'] = "$l_name";
       $l_name = $_SESSION['l_name']; 
       $_SESSION['email'] = "$email";
       $email = $_SESSION['email']; 
 
 echo "<html>
        <head><title>Student Details</title></head>
        <body>";
  // create an array that contains the labels used in the form     
  // the keys are the field names.
  $labels = array( "f_name"=>"First  Name:",
                   "l_name"=>"Last Name (Surname/Family):",
                   "salutation"=>"Dr/Mr/Mrs/Ms:",
                   "gender"=>"Gender (m or f) :",
                   "birthdate"=>"Date of Birth (yyyy-mm-dd):",
                   "email"=>"Email Address:",
                   "address1"=>"Street Address 1:",
                   "address2"=>"Street Address 2:",
                   "address3"=>"City or Town:",
                   "state"=>"State:",
                   "zip"=>"Zipcode or Postcode:",
                   "country"=>"Country:",
                   "occupation"=>"Occupation: ");
  $user="distanceed";
  $host="mysql39.secureserver.net";
  $password="not shown";
  $database = "distanceed";


  $conn = mysql_connect($host,$user,$password)
       or die ("couldn't connect to server");
  $db = mysql_select_db($database,$conn)
       or die ("Couldn't select database");
  $query = "SELECT * FROM auth_users
                     WHERE id = $studentid ";
  $result = mysql_query($query) or die("Couldn't execute query because: ".mysql_error());
  $row = mysql_fetch_array($result);

  echo "<p align='center'>
        <h1 align='center'>Details for $f_name  $l_name </h1>\n";
  echo "<br><p align='center'>
        <font size='+1'><b>Please check the information below
     and change any information that is incorrect.
      </b></font>";
 echo "<br><p align='center'>
        <font size='+1'><b>DO NOT LEAVE ANY FIELDS BLANK
      </b></font>
        <hr>";
 echo "<form action=process_changes.php method='POST'> 
     <table width='95%' border='0' cellspacing='0'
           cellpadding='2'>\n";
  foreach($labels as $field=>$label)
  {
    echo "<tr>
          <td align='right'> <B>{$labels[$field]} </br></td>
          <td><input type='text' name='$field'
               value='$row[$field]' size='65' maxlength='65'>
          </td>
          </tr>";
  }

  echo "</table>
        <div align='center'><p><input type='submit' value='Update Correct Details'> </p></div>
        </form>";
       


       
?>
</body></html>
gilk
New php-forum User
New php-forum User
 
Posts: 2
Joined: Fri Aug 31, 2012 6:10 am

Re: code broken when host withdrew support for php4

Postby johnj » Fri Aug 31, 2012 7:10 am

looks like $studentid is empty. check this variable.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: code broken when host withdrew support for php4

Postby gilk » Sun Sep 02, 2012 8:01 pm

johnj wrote:looks like $studentid is empty. check this variable.


Yep it sure is empty...looks like a problem with losing session variables between scripts.
This problem was aired on this forum 2 years ago but didnt seem to reach any conclusion.

PHP4 to PHP5 session variable is lost

Postby devo19 » Fri Nov 05, 2010 12:54 am


My host insists that they have tested "sessions" and it works for them :-x

There are a few other references on various forums which also seem to leave the question unresolved....
ie why should an upgrade from php4 to php5 break the session variables coding?
Any further help would be appreciated
gilk
New php-forum User
New php-forum User
 
Posts: 2
Joined: Fri Aug 31, 2012 6:10 am

Re: code broken when host withdrew support for php4

Postby johnj » Sun Sep 02, 2012 10:29 pm

An upgrade is usually backward compatible. You need to investigate why session variables are messed up.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm


Return to mySQL & php coding

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron