Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
cant update my table in the DB
Old 10-20-2009, 05:31 PM cant update my table in the DB
Webmaster Talker

Posts: 611
Trades: 0
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


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>
silverglade is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-20-2009, 07:37 PM Re: cant update my table in the DB
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Does the data show up when you hit "refresh", or is it not being inserted at all?

Put a debugging line into your code to see if things are working as planned. Here is one way to do it:

PHP Code:
$sql "INSERT INTO table2 (username,password,name)VALUES('$field2','$field3','$field4')";
$result mysql_query($sql);
if(!
$result) {
     echo 
mysql_error();
     exit;

__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Reply     « Reply to cant update my table in the DB
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.29359 seconds with 12 queries