Jump to content

MySQL UPDATE


ChompGator

Recommended Posts

Real Simple...I have a form...handle.php is the script that handles the data from profile.php

 

Users fill in their information, click "update" - getting parse errors like you wouldnt believe.

Now I just have the script using 'insert' but I will change it to update after I figure out what is wrong with this script...Any help would be great

 

submit.php

<form method="post" action="handle.php"<br>
<td style="width: 175px;" valign="top"><font face="Verdana" size="2">
	<strong>Company Name:<br><input type=""text" AutoFill" tabindex="1" maxlength="25" size="20" name="company">
	</strong></font></td><br>
<td style="width: 175px;" valign="top"><font face="Verdana" size="2">
	<strong>Company Address:<Br><input type="text" tabindex="1" maxlength="25" size="20" name="address">
	</strong></font></td><br>
<td style="width: 175px;" valign="top"><font face="Verdana" size="2">
	<strong>Phone Number:<br><input type="text" tabindex="1" maxlength="25" size="20" name="phone">
	</strong></font></td><br>
<input type="submit" value="Change Profile" />
</form>

 

 

handle.php

<?php
$host="***"; // Host name 
$username="***"; // Mysql username 
$password="***"; // Mysql password 
$db_name="***"; // Database name

  
// Step 1  
$company = $_POST['company'];  
$address = $_POST['address'];  
$phone = $_POST['phone'];   
  
// Step 2  
$sql = "insert into general (company, address, phone) VALUES ('$company', '$address', '$phone')";  
  
// Step 3  
$result = mysql_query($sql) or die ( mysql_error() );  
?>

 

Link to comment
https://forums.phpfreaks.com/topic/118313-mysql-update/
Share on other sites

well, i cant see that you are connecting to your DB,

 

here it is:

<?php
$host="***"; // Host name 
$username="***"; // Mysql username 
$password="***"; // Mysql password 
$db_name="***"; // Database name

// Connect to DB
$db = mysql_connect ($host, $username, $password) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ($db_name);


// Step 1  
$company = $_POST['company'];  
$address = $_POST['address'];  
$phone = $_POST['phone'];   
  
// Step 2  
$sql = "insert into general (company, address, phone) VALUES ('$company', '$address', '$phone')";  
  
// Step 3  
$result = mysql_query($sql) or die ( mysql_error() );  
?>

Link to comment
https://forums.phpfreaks.com/topic/118313-mysql-update/#findComment-608838
Share on other sites

Now, what I would like to do is this...Each user has a profile, (those  fields earlier I was testing out to see if I could get them to insert into the db, they do infact insert so that works)...However when Jeff goes and logs-in and clicks "My Profile" and decides he wants to update his `company` and he fills out his new company name in the text box and clicks "submit" - -Here I want the script to just update "Jeff's" company name...

 

Right now say you are Jim and you click "My Profile" when you update your company name, its inserting an entire new row into the database. So in order to verify each user is updating only their profile - does my codelook right?

 

<?php

$host="**"; // Host name 
$username="**"; // Mysql username 
$password="**"; // Mysql password 
$db_name="**"; // Database name

  
// Connect to DB
$db = mysql_connect ($host, $username, $password) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ($db_name);


// Step 1  
$company = $_POST['company'];  
$address = $_POST['address'];  
$phone = $_POST['phone'];   
  
// Step 2  
$query = "UPDATE general (company, address, phone) VALUES ('$company', '$address', '$phone')" "WHERE uid = 'first'";   //This is where Im making sure the uid (user id) matches the users first name

  
// Step 3  
$result = mysql_query($sql) or die ( mysql_error() );  
?>

Link to comment
https://forums.phpfreaks.com/topic/118313-mysql-update/#findComment-608867
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.