Jump to content

[SOLVED] Is it possible to insert values into a single column?


Recommended Posts

i want to insert values into a single column of a a table. ive attempted it with this;

<?php


$db = @mysql_connect("localhost","root","");

if (!$db)
{
do_error("Could not connect to the server");
}

// Connect to the database
@mysql_select_db("Rufus" ,$db)or do_error("Could not connect to the database");
// Run query
$name=$_POST["secondtxt"];
$name2=$_POST["thirdtxt"]; 
$result = mysql_query("INSERT INTO project WHERE project_id='$name' (user_id)
					VALUE ('$name2)",$db);
?>

 

however the column doesnt appear changed in the database.

Are you wanting to make changes to an existing record in the table? if so you'll want to run an UPDATE query. INSERT INTO is for creating new records only.

 

$sql = "UPDATE project SET user_id='$name2' WHERE project_id='$name'";

Did you just add that line, then tested your code immediately after? If you noticed I assigned the query to a variable called $sql. You'll need pass this variable to mysql_query() in order for the query to execute.

i changed my code to this, it didnt work. anything else you can do for me?

<?php


$db = @mysql_connect("localhost","root","");
$sql = "UPDATE project SET user_id='$name2' WHERE project_id='$name'";
if (!$db)
{
do_error("Could not connect to the server");
}

// Connect to the database
@mysql_select_db("Rufus" ,$db)or do_error("Could not connect to the database");
// Run query
$name=$_POST["secondtxt"];
$name2=$_POST["thirdtxt"]; 
$result = mysql_query("$sql,VALUE ('$name2)",$db);
?>

 

and i tried this

<?php


$db = @mysql_connect("localhost","root","");
$sql = mysql_query;
if (!$db)
{
do_error("Could not connect to the server");
}

// Connect to the database
@mysql_select_db("Rufus" ,$db)or do_error("Could not connect to the database");
// Run query
$name=$_POST["secondtxt"];
$name2=$_POST["thirdtxt"]; 
$sql = "UPDATE project SET user_id='$name2' WHERE project_id='$name'";
?>

I think this is what you mean. but i now get this error in the browser

ERROR!

Query:

Query was empty

 

<?php
$db = @mysql_connect("localhost","root","");

if (!$db)
{
do_error("Could not connect to the server");
}

// Connect to the database
@mysql_select_db("Rufus" ,$db)or do_error("Could not connect to the database");
// Run query
$name=$_POST["secondtxt"];
$name2=$_POST["thirdtxt"]; 
mysql_query($sql, $db) or die('ERROR!<br />Query: '.$sql.'<br />'.mysql_error());
$sql = "UPDATE project SET user_id='$name2' WHERE project_id='$name'";
?>

 

i do appreciate your help alot, i know im very difficult sometimes

thanks it does work. the post with the hyperlink in wasnt very clear, maybe its my eyes only been working on the site for 12 hours. perhaps it would have been easier to say swap the lines over, not imply that i dont understand the syntax. i did memtion i was php inept earlier, and wouldnt be on this forum if i did.

thanks again, especially for your time.

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.