/    Sign up×
Community /Pin to ProfileBookmark

insert two texts in same row

I want to insert two texts from a form in two seperate fields on a table in mysql in the same row.
I managed to insert them successfully but there is a problem.They have been submitted on database in different rows(IDs).How can i make them appeared in the same row?I have the following code:

[code=html]<form action=”insert.php” method=”POST”>
Title<br>
<input name=”titles” style=” width:596px;” type=”text” /><br><br>
Text<br>
<textarea style=”width:594px;” rows=”10″ cols=”20″ wrap=”physical” name=”text”>

</textarea><br><br>
<input type=”submit” style=”float:right;” value=”Submit Log” />
</form>[/code]

[code=php]<?php
// Connects to your Database
mysql_connect(“localhost”, “root”, “”) or die(mysql_error());
mysql_select_db(“project”) or die(mysql_error());

//This code runs if the form has been submitted
if (isset($_POST)) {

// now we insert it into the database
$insert = “INSERT INTO submit (titles)
VALUES (‘”.$_POST[‘titles’].”‘)”;
$add_link = mysql_query($insert);
$insert = “INSERT INTO submit (text)
VALUES (‘”.$_POST[‘text’].”‘)”;
$add_link = mysql_query($insert);
}

{ header(“Location:index.html”);
}

?>[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@ralphchadkirkSep 10.2011 — It's because you're running two INSERT queries, so the database will work correctly and create two rows.

This is how your code should look:
[code=php]<?php
// Connects to your Database
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("project") or die(mysql_error());




//This code runs if the form has been submitted
if (isset($_POST))
{
// now we insert it into the database
$insert = "INSERT INTO submit (titles,text)
VALUES ('".$_POST['titles']."','" . $_POST['text'] . "')";
$add_link = mysql_query($insert);
}
{

header("Location:index.html");
}


?>[/code]


You are also using very insecure code.
Copy linkTweet thisAlerts:
@jojo13authorSep 10.2011 — It's because you're running two INSERT queries, so the database will work correctly and create two rows.

This is how your code should look:
[code=php]<?php
// Connects to your Database
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("project") or die(mysql_error());




//This code runs if the form has been submitted
if (isset($_POST))
{
// now we insert it into the database
$insert = "INSERT INTO submit (titles,text)
VALUES ('".$_POST['titles']."','" . $_POST['text'] . "')";
$add_link = mysql_query($insert);
}
{

header("Location:index.html");
}


?>[/code]


You are also using very insecure code.[/QUOTE]



Thanks.It worked!

I know it is very insecure.I am not an expert at php at the moment and i learn now to do the basic things.
×

Success!

Help @jojo13 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...