Help with insert and select

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kingd3112
Forum Newbie
Posts: 1
Joined: Thu Aug 12, 2010 5:51 pm

Help with insert and select

Post by kingd3112 »

I am trying to do this add function. Where when you click the add link it saves a few fields of the product information(Set Database info) as well as the username and date(New Info).

This is what I have so far. The issue is that mysql_query posts two different rows in the table. I want it to just be one row. Any thoughts on how to link INSERT with a value and INSERT with SELECT.

Heres my code:
<? include("include/session.php"); ?>

<div id="popcontainer">
<div id="popupbox">
<div id="popdealbox">


<?
if ($a == add) {
$usel = mysql_query("select * from restaurant where id='$i'");
while ($upd = mysql_fetch_array($usel)) {
print "<br><br><br><br><br><center><h2> Would you like to add dash? <a href=add.php?a=adash&i=$upd[id]>Yes</a></h2></center>";
}

}


if ($a == adash) {
$userdining = $session->username;
$validfor = date("F j, Y");
mysql_query("INSERT INTO `mydash` (username, validfor) values ('$userding','$validfor')") or die("<center>Sorry Could Not Add Dash.</center>");
mysql_query("INSERT INTO `mydash` (name, linkpic) SELECT `name`, `linkpic` FROM `restaurant` where id='$i'") or die("<center>Sorry Could Not Add Dash.</center>");
print "<br><br><br><br><br><center><h2>Dash has been added!</h2> <a href=>View Deal</a></center>";
}

?>


</div>
</div>
</div>
Post Reply