Solved

Page not working on internal server

Posted on 2014-07-28
32
324 Views
Last Modified: 2014-07-29
I created a few pages on an external server and got everything working great. I copied the files to our internal server at work and I can view records, but nothing updates.

What do I look at for what is different between the servers?

Outside server is UNIX Socket server version 5.5.37-35.1 with MySQL version 5.0.96
•cpsrvd 11.42.1.24
•MySQL client version: 5.0.96
•PHP extension: mysqli Documentation
phpMyAdmin is 3.4.11.1

Internal server is Localhost via TCP/IP
•Microsoft-IIS/8.5
•Database client version: libmysql - mysqlnd 5.0.11-dev - 20120503 - $Id: bf9ad53b11c9a57efdb1057292d73b928b8c5c77 $
•PHP extension: mysql Documentation

phpMyAdmin version is 4.1.12
0
Comment
Question by:BHUC
  • 17
  • 15
32 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40225684
What do I look at for what is different between the servers?
Apart from the pink elephant in the room that is telling you one is Linux and one is Windows?
0
 

Author Comment

by:BHUC
ID: 40225688
Gary, so sorry. I know nothing about configuration of servers. First time I have ever worked on an internal server. is there different code I need to do for the update part? If so - can you direct me to a place that I can learn the difference?
0
 
LVL 58

Expert Comment

by:Gary
ID: 40225691
What is the php version on the two servers?
Have you get error reporting turned on - this will likely tell you the problem
Both servers can operate exactly the same in an indentical setup but cannot really tell you anything without seeing the code and/or knowing what the error is.
0
 

Author Comment

by:BHUC
ID: 40225699
On the internal server, it won't show what variables are already in the database and it won't update the database on submit. The code is here:

error shows
Notice: Undefined variable: Submit in C:\inetpub\RCCInfo\update_multiple.php on line 70 which is the if ($Submit) line at the end... I'll start reading..

<?php

$host = "localhost";
$username = "***********";
$password = "*************";
$db_name="test"; // Database name 
 $tbl_name="test_mysql"; // Table name 

// Connect to server and select databse.
 mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
 mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name";
 $result=mysql_query($sql);

// Count table rows 
 $count=mysql_num_rows($result);
ini_set('display_errors',1); 
 error_reporting(E_ALL);
 ?>

<table width="500" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="">
 <tr> 
 <td>
 <table width="500" border="0" cellspacing="1" cellpadding="0">

 <tr>
 <td align="center"><strong>id</strong></td>
 <td align="center"><strong>Name</strong></td>
 <td align="center"><strong>Lastname</strong></td>
 <td align="center"><strong>Email</strong></td>
 </tr>

<?php
 while($rows=mysql_fetch_array($result)){
 ?>

<tr>
 <td align="center">
<? $id[]=$rows['id']; ?><? echo $rows['id']; ?>
</td>
<td align="center">
<input name="name[]" type="text" id="name" value="<? echo $rows['name']; ?>">
 </td>
<td align="center">
<input name="lastname[]" type="text" id="lastname" value="<? echo $rows['lastname']; ?>">
 </td>
<td align="center">
<input name="email[]" type="text" id="email" value="<? echo $rows['email']; ?>">
 </td>
</tr>

<?php
 }
 ?>

<tr>
 <td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td>
 </tr>
 </table>
 </td>
 </tr>
</form>
 </table>

<?php

// Check if button name "Submit" is active, do this 
 if($Submit){
 for($i=0;$i<$count;$i++){
 $sql1="UPDATE $tbl_name SET name='$name[$i]', lastname='$lastname[$i]', email='$email[$i]' WHERE id='$id[$i]'";
 $result1=mysql_query($sql1);
 }
 }
 mysql_close();
 ?>

Open in new window

0
 
LVL 58

Expert Comment

by:Gary
ID: 40225703
Well from that code $Submit does not exist anywhere except where you are checking it and there are no includes in the page.
Are you trying to check if the page was posted?

p.s.
Use the code tags in the future when you are posting code.
0
 

Author Comment

by:BHUC
ID: 40225710
Yes  - I am trying to learn how to update multiple rows of the same database with one submit button and found this code as a tutorial. I copied and pasted over onto the external server and it worked great, so moved it to the internal.
0
 
LVL 58

Expert Comment

by:Gary
ID: 40225717
I don't know how it can work on the external server without some other code there.
At the very least I would expect

if($Submit){

to be
if(isset($_POST['submit'])){
0
 

Author Comment

by:BHUC
ID: 40225729
That got rid of the submit error but it still isn't submitting.

attached is a screenshot of what it looks like on the internal server vs external

Values aren't pulling in
screenshot.jpg
0
 
LVL 58

Expert Comment

by:Gary
ID: 40225734
Have you actually installed PHP on IIS - looks like you haven't - refer the pink elephant in the room.

http://php.iis.net/
0
 
LVL 58

Expert Comment

by:Gary
ID: 40225740
Do you use IIS for anything else?
If not It may be beneficial to use XAMPP so you can get an environment as close to the Linux server as possible
0
 

Author Comment

by:BHUC
ID: 40225747
I added this to the top of the page on the internal server and all information displays:

<?PHP

$dept_query = "SELECT * FROM $tbl_name ";

$dept_query_result = mysql_query($dept_query);
while ($dept_row = mysql_fetch_assoc($dept_query_result))
{
$firstname = $dept_row['name'];
$lastname = $dept_row['lastname'];


echo "$firstname $lastname<br />\n";            
      
}

?>
0
 
LVL 58

Expert Comment

by:Gary
ID: 40225751
Ah ha - looking thru your code again
PHP short open tags is not enabled on your local php installation so
<?
will not work
You need to use
<?php

Or enable it in php.ini
short_open_tag=On
0
 

Author Comment

by:BHUC
ID: 40225758
One more step done - the information now shows up in the fields to edit, but submit doesn't save the changes.
0
 
LVL 58

Expert Comment

by:Gary
ID: 40225764
Something is missing because this
 if($Submit){
 for($i=0;$i<$count;$i++){
 $sql1="UPDATE $tbl_name SET name='$name[$i]', lastname='$lastname[$i]', email='$email[$i]' WHERE id='$id[$i]'";
 $result1=mysql_query($sql1);
 }
 }

Open in new window

...has no relation to anything else in the code you posted, where is
$name[$i]
...coming from?
0
 
LVL 58

Expert Comment

by:Gary
ID: 40225769
What is the link to the tutorial you followed?
0
 

Author Comment

by:BHUC
ID: 40225776
I got it from another expert-exchange thread.

The link is here..  http://www.phpeasystep.com/mysql/10.html

If there is another way I should be learning - please let me know.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 58

Expert Comment

by:Gary
ID: 40225807
phpeasystep.com my arse - how can a (supposedly tutorial) website do something so wrong.
That site is so bad!
Error reporting should be the first line, what's the point of it being halfway down the page lol

This is an example Form - but you should not be using the old MySQL extension for DB queries
It's untested so there maybe some syntax errors

<?php
ini_set('display_errors',1); 
error_reporting(E_ALL);

$host = "localhost";
$username = "***********";
$password = "*************";
$db_name="test"; // Database name 
 $tbl_name="test_mysql"; // Table name 

// Connect to server and select databse.
 mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
 mysql_select_db("$db_name")or die("cannot select DB");


if(isset($_POST['submit'])){
	$name=$_POST['name'];
	$lastname=$_POST['lastname'];
	$email=$_POST['email'];
	$id=$_POST['id'];

	foreach($name as $key => $value) {
		$sql1="UPDATE $tbl_name SET name='$name[$key]', lastname='$lastname[$key]', email='$email[$key]' WHERE id='$id[$key]'";
		$result1=mysql_query($sql1);
	}
}



$sql="SELECT * FROM $tbl_name";
 $result=mysql_query($sql);

// Count table rows 
 $count=mysql_num_rows($result);

 ?>

<table width="500" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="">
 <tr> 
 <td>
 <table width="500" border="0" cellspacing="1" cellpadding="0">

 <tr>
 <td align="center"><strong>id</strong></td>
 <td align="center"><strong>Name</strong></td>
 <td align="center"><strong>Lastname</strong></td>
 <td align="center"><strong>Email</strong></td>
 </tr>

<?php
 while($rows=mysql_fetch_array($result)){
 ?>

<tr>
 <td align="center">
<input type="text" name="id[]" value="<?=$rows['id']; ?>">
</td>
<td align="center">
<input name="name[]" type="text" id="name" value="<? echo $rows['name']; ?>">
 </td>
<td align="center">
<input name="lastname[]" type="text" id="lastname" value="<? echo $rows['lastname']; ?>">
 </td>
<td align="center">
<input name="email[]" type="text" id="email" value="<? echo $rows['email']; ?>">
 </td>
</tr>

<?php
 }
 ?>

<tr>
 <td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td>
 </tr>
 </table>
 </td>
 </tr>
</form>
 </table>

Open in new window

0
 

Author Comment

by:BHUC
ID: 40225828
I get this error and it still doesn't update:

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\inetpub\RCCInfo\update_multiple.php
0
 
LVL 58

Expert Comment

by:Gary
ID: 40225831
Thats just a warning - did you put your username/password back in?
0
 

Author Comment

by:BHUC
ID: 40225834
Yes - the data pulls in, but it won't update.
0
 

Author Comment

by:BHUC
ID: 40227375
Gary or ANYONE who can help.

I changed it to just a basic update script with one field.

This works:
$sql = "UPDATE providers SET ImageFileName='$Image1' WHERE ID='$event_id'";
                                                                $update_result = mysql_query($sql);

This script clears the column in the database
$sql = "UPDATE providers SET FName='$FName' WHERE ID='$event_id'";
                        $update_result = mysql_query($sql);

But this doesn’t on the same page
$sql = "UPDATE providers SET Haines='$Haines' WHERE ID='$event_id'";
                                                                $update_result = mysql_query($sql);

Image is an upload file, name is a text field and Haines is a checkbox


Here are the variables:
 $FName = $_POST['FName'];
 $FName = mysql_real_escape_string($FName, $link);

$Haines = $_POST['Haines'];
$Haines = mysql_real_escape_string($Haines, $link);

            $Image1 = '';

            if (isset($_FILES['image1']))
            {
                  $imagename = basename($_FILES['image1']['name']);
                  if (!(empty($imagename)))
                  {
                        $newimage = "providers/" . $imagename;



                        $result = @move_uploaded_file($_FILES['image1']['tmp_name'], $newimage);

            $Image1 = $imagename;
                  }
            }

Can anyone help me with what I am missing?
0
 
LVL 58

Expert Comment

by:Gary
ID: 40227516
After this line
$sql = "UPDATE providers SET Haines='$Haines' WHERE ID='$event_id'";

add
echo $sql

and post the result here
0
 

Author Comment

by:BHUC
ID: 40227552
Nothing posts...

I have it like this:

$sql = "UPDATE providers SET Haines='$Haines' WHERE ID='$$event_id'";
                        $update_result = mysql_query($sql);
                        echo $sql;
0
 
LVL 58

Expert Comment

by:Gary
ID: 40227569
Hold on a minute, this is nothing like your original question.
Post your whole code as you have it now.
0
 

Author Comment

by:BHUC
ID: 40227580
Thanks Gary.. I'll get that. It is the same issue as the form isn't updating.  It's just a smaller form that I was stuck on before and remembered that the photo updated, but nothing else would.

Let me get rid of all the extra stuff and I'll upload the file. If I should open another question, let me know, but the original question still hasn't been solved.
0
 
LVL 58

Expert Comment

by:Gary
ID: 40227588
Just post your real code, no need for a new question.
0
 

Author Comment

by:BHUC
ID: 40227601
Here is the file... insert and update don't work.  I commented out the main update code to work with just the smaller one that works for an image, but not the others.
edit-nurses.php
0
 
LVL 58

Expert Comment

by:Gary
ID: 40227667
Can you do a dump of your providers table and attach it here
0
 

Author Comment

by:BHUC
ID: 40227669
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40227779
Replace all instances of $link with $dbhandle
0
 

Author Comment

by:BHUC
ID: 40227788
OMG - that worked.... now can you explain why I need to do that? is it a windows thing?

I am heading back to PHP school to learn all the new stuff. I can't thank you enough.
0
 
LVL 58

Expert Comment

by:Gary
ID: 40227800
No, you were referencing a db connection ($link) that didn't exist - your connection is called $dbhandle
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now