sandbudd Posted April 25, 2009 Share Posted April 25, 2009 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> Quote Link to comment Share on other sites More sharing options...
sandbudd Posted April 25, 2009 Author Share Posted April 25, 2009 What I am wondering is there are other fields in the database but this is the only one that I want to update? Quote Link to comment Share on other sites More sharing options...
ialsoagree Posted April 25, 2009 Share Posted April 25, 2009 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. Quote Link to comment Share on other sites More sharing options...
teynon Posted April 25, 2009 Share Posted April 25, 2009 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> Quote Link to comment Share on other sites More sharing options...
sandbudd Posted April 25, 2009 Author Share Posted April 25, 2009 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 Quote Link to comment Share on other sites More sharing options...
teynon Posted April 25, 2009 Share Posted April 25, 2009 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. Quote Link to comment Share on other sites More sharing options...
sandbudd Posted April 25, 2009 Author Share Posted April 25, 2009 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 Quote Link to comment Share on other sites More sharing options...
sandbudd Posted April 25, 2009 Author Share Posted April 25, 2009 in addition I want the first page to populate the database to capture the first page info in case they stop filling out the form that is why I am doing the update? Quote Link to comment Share on other sites More sharing options...
ialsoagree Posted April 25, 2009 Share Posted April 25, 2009 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. Quote Link to comment Share on other sites More sharing options...
sandbudd Posted April 25, 2009 Author Share Posted April 25, 2009 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(); ?> Quote Link to comment Share on other sites More sharing options...
ialsoagree Posted April 26, 2009 Share Posted April 26, 2009 Is the id column in your table a string? If not, try this: $sql1="UPDATE $tbl_name SET employer='$_POST[employer][$i]' WHERE id=$id[$i]"; Quote Link to comment Share on other sites More sharing options...
sandbudd Posted April 26, 2009 Author Share Posted April 26, 2009 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(); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.