Jump to content

[SOLVED] Notice: Undefined variable:


sandbudd

Recommended Posts

I am getting there errors and it is not editing the database

 

Notice: Undefined variable: Submit in /home/content/n/f/l/nflcars/html/flashmarquee/application10.php on line 59

 

Notice: Undefined variable: result1 in /home/content/n/f/l/nflcars/html/flashmarquee/application10.php on line 66

 

<?php session_name('application');
session_start(); ?>
<?php error_reporting(E_ALL);
?>
<?php
$host=""; // Host name 
$username=""; // Mysql username 
$password=""; // Mysql password 
$db_name=""; // Database name 
$tbl_name=""; // 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);
?>
</p>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="">
<tr> 
<td>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1">


<tr>
<td colspan="5" align="left" valign="top"><br />
  <br /></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
  <td width="25%" align="left" valign="top">Employer</td>
  <td width="34%" align="left" valign="top"><input name="employer[]" type="text" id="employer" value="<? echo $rows['employer']; ?>"></td>
  <td colspan="3" align="left" valign="top"> </td>
</tr>
<tr>
  <td colspan="5" align="left" valign="top"><hr /></td>
  </tr>
<?php
}
?>
<tr align="left" valign="top">
<td colspan="3"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<div align="center">
<?php
// Check if button name "Submit" is active, do this 
if($Submit){
for($i=0;$i<$count;$i++){
$sql1="UPDATE $tbl_name SET employer='$employer[$i]' WHERE id='$id[$i]'";
$result1=mysql_query($sql1);
}
}

if($result1){
header("location:application10.php");
}
mysql_close();
?>
  
  
</div>

 

Link to comment
Share on other sites

You're getting those notices because the variables you've used ("$Submit" and "$result1") are undefined.

 

It seems you've copied this code from somewhere else. This code appears to be created before a major change in PHP, the register_globals directive was defaulted from "on" to "off".

 

In PHP 4.1.0 and up you can refer to data submitted via a post request with:

$_POST['html_name_attribute']

 

Whenever data isn't submitted, $result1 is not defined and thus will throw this notice. A solution would be to initialize it to false before you check if data was submitted.

Link to comment
Share on other sites

The below would work, but your $id variable is coming from no where. I'm assuming that you think the "Id" part of the form field will transfer, but it wont.

 

<?php session_name('application');
session_start(); ?>
<?php error_reporting(E_ALL);
?>
<?php
$host=""; // Host name 
$username=""; // Mysql username 
$password=""; // Mysql password 
$db_name=""; // Database name 
$tbl_name=""; // 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);
?>
</p>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="">
<tr> 
<td>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1">


<tr>
<td colspan="5" align="left" valign="top"><br />
  <br /></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
  <td width="25%" align="left" valign="top">Employer</td>
  <td width="34%" align="left" valign="top"><input name="employer[]" type="text" id="employer" value="<? echo $rows['employer']; ?>"></td>
  <td colspan="3" align="left" valign="top"> </td>
</tr>
<tr>
  <td colspan="5" align="left" valign="top"><hr /></td>
  </tr>
<?php
}
?>
<tr align="left" valign="top">
<td colspan="3"><input type="submit" name="Submit" value="Submit"><input type="hidden" name="send" value="1"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<div align="center">
<?php
// Check if button name "Submit" is active, do this 
if(isset($_POST['send'])){
for($i=0;$i<$count;$i++){
$sql1="UPDATE $tbl_name SET employer='{$_POST['employer'][$i]}' WHERE id='$id[$i]'";
$result1=mysql_query($sql1);
}
}

if(isset($result1)){
header("location:application10.php");
}
mysql_close();
?>
  
  
</div>

Link to comment
Share on other sites

Teynon now I am getting this error

 

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/content/n/f/l/nflcars/html/flashmarquee/application10.php on line 20

 

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/content/n/f/l/nflcars/html/flashmarquee/application10.php on line 35

Link to comment
Share on other sites

If you are just trying to inject the script without knowing what your doing, your not going to get it. You have to have database login information in those variables and you have to have values in the database. If you don't know that stuff, then you're not going to be able to get it yourself. I'm sure someone here will do it for a small fee.

Link to comment
Share on other sites

Okay here is what I am doing... This is part of a three page form that I am passing by sessions... It is displaying the field to update and wouldn't pass the id from the previous page?  I removed the id field and this is the error that I am getting now.  Oh and by the way on the last post I had mispelled the table.

 

Warning: Cannot modify header information - headers already sent by (output started at /home/content/n/f/l/nflcars/html/flashmarquee/application10.php:34) in /home/content/n/f/l/nflcars/html/flashmarquee/application10.php on line 67

Link to comment
Share on other sites

As for this warning: "Warning: Cannot modify header information - headers already sent by (output started at /home/content/n/f/l/nflcars/html/flashmarquee/application10.php:34) in /home/content/n/f/l/nflcars/html/flashmarquee/application10.php on line 67"

 

You're outputting data:

?>
</p>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="">
<tr>
<td>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1">


<tr>
<td colspan="5" align="left" valign="top"><br />
  <br /></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
  <td width="25%" align="left" valign="top">Employer</td>
  <td width="34%" align="left" valign="top"><input name="employer[]" type="text" id="employer" value="<? echo $rows['employer']; ?>"></td>
  <td colspan="3" align="left" valign="top"> </td>
</tr>
<tr>
  <td colspan="5" align="left" valign="top"><hr /></td>
  </tr>
<?php
}
?>
<tr align="left" valign="top">
<td colspan="3"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<div align="center">
<?php

 

Then trying to change a header:

 

if(isset($result1)){
header("location:application10.php");
}

 

Header's must be edited BEFORE anything is sent to the browser.

Link to comment
Share on other sites

okay I changed to this and get no errors but it does not populate or update the database

 

<?php
if(isset($result1)){
header("location:application10.php");
}
// Check if button name "Submit" is active, do this 
if(isset($_POST['send'])){
for($i=0;$i<$count;$i++){
$sql1="UPDATE $tbl_name SET employer='{$_POST['employer'][$i]}' WHERE id='$id[$i]'";
$result1=mysql_query($sql1);
}
}


mysql_close();
?>

Link to comment
Share on other sites

got it working had to do this and thanks guys

[coe]
<?php
if(isset($result1)){
header("location:application10.php");
}
// Check if button name "Submit" is active, do this 
if(isset($_POST['send'])){
for($i=0;$i<$count;$i++){
$sql1="UPDATE $tbl_name SET employer='{$_POST['employer'][$i]}'";
$result1=mysql_query($sql1);
}
}


mysql_close();
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.