Quick Search
Sunbelthost Hosting - Colocation and Dedicated Servers

Threads: 21,763
Posts: 83,205
Members: 24,315
Newest member: joemccue

Web Hosting


 
  #1  
Old 20 Oct 2009, 03:27 PM
silverglade silverglade is offline
Established Member
 
Join Date: Sep 2009
Posts: 25
cant update my table in the DB

hi, i have the following script which is supposed to update the table in the database, and output the results of the newly inserted data to the same page. it doesnt work. please if anyone can tell me why, id greatly appreciate it. here is the code.


PHP Code:
 <?php 
 
include("connect1.php");
 
 
////////////////////////////////////////
////////////////////////////////////////

/// query db and loop through rows example

$field2 $_POST['username'];
$field3    $_POST['password'];
$field4    $_POST['Name'];
 
if(isset(
$_POST['Submit'])){ //if submit has been set, or clicked.
if($field2 && $field3 && $field4){

    
mysql_query("INSERT INTO table2 (username,password,name)VALUES('$field2','$field3','$field4')");

}else{


echo 
"error";

}
}
//isset
//////////////////////////////////////////////////////////output data into a table///////////////////////////////



$query     mysql_query("SELECT * FROM table2");

    
$table "<table width=\"40%\" border=\"1\">
                  <tr>
                        <td>ID</td>
                        <td>username</td>
                        <td>password</td>
                        <td>Name</td>
                        
                  </tr>"
;

while(
$row mysql_fetch_array($query)){

    
$table .= "    <tr>
                    <td>"
.$row['record_id']."</td>
                    <td>"
.$row['username']."</td>
                    <td>"
.$row['password']."</td>
                    <td>"
.$row['Name']."</td>
                    
                </tr>"
;

}

$table .= "</table>";

echo 
$table;
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Derek's secret account updater</title>
</head>

<body>




<form id="form1" name="form1" method="post" action="secret_updater.php">
  <table width="31%" border="0">
    <tr>
      <td colspan="31%">Derek's secret Account updater</td>
    
    </tr>
    <tr>
      <td width="32%">username:</td>
      <td width="68%"><input name="username" type="text" id="username" /></td>
    </tr>
    <tr>
      <td>password:</td>
      <td><input name="password" type="text" id="password" /></td>
    </tr>
    <tr>
      <td>Name:</td>
      <td><input name="Name" type="text" id="Name" /></td>
    </tr>
     <tr>
       
      <td><input type="submit" value="Submit" /></td>
    </tr>
  </table>
</form>

</body>
</html>

Last edited by Alan; 20 Oct 2009 at 03:31 PM. Reason: Changed bbcode
Reply With Quote
  #2  
Old 20 Oct 2009, 03:34 PM
Alan's Avatar
Alan Alan is offline
Moderator
 
Join Date: Feb 2007
Location: Ireland
Posts: 843
PHP Code:
if(isset($_POST['Submit'])){ //if submit has been set, or clicked.
if($field2 && $field3 && $field4){ 
You have not set the "Submit" field in the form. You need to add name="Submit" to the submit input field.

As for the second line... what exactly are you testing for? It's very vague. Don't get me wrong, it should work... but you should be more specific, such as if(isset($field2) && !empty($field2)).
__________________
“The best thing about a boolean is even if you are wrong, you are only off by a bit.”
Reply With Quote
  #3  
Old 20 Oct 2009, 03:40 PM
silverglade silverglade is offline
Established Member
 
Join Date: Sep 2009
Posts: 25
AWESOME thank you very much!!! i spent over an hour staring at this problem. so thank you. derek
Reply With Quote
  #4  
Old 20 Oct 2009, 04:21 PM
Alan's Avatar
Alan Alan is offline
Moderator
 
Join Date: Feb 2007
Location: Ireland
Posts: 843
Quote:
Originally Posted by silverglade View Post
AWESOME thank you very much!!! i spent over an hour staring at this problem. so thank you. derek
No problem. Your very welcome.
__________________
“The best thing about a boolean is even if you are wrong, you are only off by a bit.”
Reply With Quote
  #5  
Old 20 Oct 2009, 09:44 PM
silverglade silverglade is offline
Established Member
 
Join Date: Sep 2009
Posts: 25
my code isnt working again, it wont update the table, nor display the results, any help greatly appreciated. heres the code.

Code:
  <?php 
 
include("connect1.php");
 
 
////////////////////////////////////////
////////////////////////////////////////

/// query db and loop through rows example

$field2 = $_POST['username'];
$field3	= $_POST['password'];
$field4	= $_POST['Name'];
 

if($field2 && $field3 && $field4){

	mysql_query("INSERT INTO table2 (username,password,Name)VALUES('$field2','$field3','$field4')");

}else{


echo "error";

}

//////////////////////////////////////////////////////////output data into a table///////////////////////////////



$query 	= mysql_query("SELECT * FROM table1");

	$table = "<table width=\"40%\" border=\"1\">
				  <tr>
						<td>ID</td>
						<td>username</td>
						<td>password</td>
						<td>Name</td>
						
				  </tr>";

while($row = mysql_fetch_array($query)){

	$table .= "	<tr>
					<td>".$row['record_id']."</td>
					<td>".$row['username']."</td>
					<td>".$row['password']."</td>
					<td>".$row['Name']."</td>
					
				</tr>";

}

$table .= "</table>";

echo $table;
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Derek's secret account updater</title>
</head>

<body>




<form id="form1" name="form1" method="post" action="secret_updater.php">
  <table width="31%" border="0">
    <tr>
      <td colspan="31%">Derek's secret Account updater</td>
    
    </tr>
    <tr>
      <td width="32%">username:</td>
      <td width="68%"><input name="username" type="text" id="username" /></td>
    </tr>
    <tr>
      <td>password:</td>
      <td><input name="password" type="text" id="password" /></td>
    </tr>
    <tr>
      <td>Name:</td>
      <td><input name="Name" type="text" id="Name" /></td>
    </tr>
     <tr>
       
      <td><input name="Submit"  type="submit" value="Submit" /></td>
    </tr>
  </table>
</form>

</body>
</html>

Last edited by silverglade; 20 Oct 2009 at 10:07 PM.
Reply With Quote
  #6  
Old 20 Oct 2009, 10:14 PM
silverglade silverglade is offline
Established Member
 
Join Date: Sep 2009
Posts: 25
nevermind i copied my old posts code and redid the submit code. it works now. newbie lesson learned. IF IT AINT BROKE DONT FIX IT.
Reply With Quote
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Quick fix centering my entire css myspace layout - link & code included Dennis Web Design, HTML Reference and CSS 7 29 Aug 2009 06:15 AM
How to constrain table height in a dynamic table? MrQuestions Web Design, HTML Reference and CSS 4 16 Mar 2008 09:31 AM
Div Table inside a Div Table, Possible? publikdesign Web Design, HTML Reference and CSS 2 13 Jan 2008 09:46 PM
Easiest way to update a table... richard_ray Web Design, HTML Reference and CSS 3 31 Mar 2006 02:44 AM


All times are GMT -5. The time now is 01:22 PM.


 

Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Forums Copyright © 2004-2010, WebDevForums.com. Web design by Miami Web Design. All Rights Reserved.