
garrickplaisted
Members-
Posts
17 -
Joined
-
Last visited
Profile Information
-
Gender
Not Telling
garrickplaisted's Achievements

Newbie (1/5)
0
Reputation
-
Here it is, thanks! $leadSQL="INSERT INTO $leadsTable (leadName, leadStatus, leadDescription, leadOpportunity, leadSource, leadSourceDescription, id, leadSince, contactID) VALUES ('$_POST[leadName]', '$_POST[leadStatus]', '$_POST[leadDescription]', '$_POST[leadOpportunity]', '$_POST[leadSource]', '$_POST[leadSourceDescription]','$_POST[id]','$leadSince','$_POST[contactID]')"; $leadQuery = mysql_query($leadSQL); $lastLeadID = mysql_insert_id(); $updateContactSQL = "UPDATE $contactsTable SET leadID = $lastLeadID WHERE contactID = $_POST[contactID]"; $updateContactQuery = mysql_query($updateContactSQL);
-
I need to insert a new row in to a table, then grab the ID of taht row and update another table. What I have is something like this: $sql="INSERT INTO leads (field1, field2) VALUES('$value1','$value2')"; $query = mysql_query($sql); $lastID = mysql_insert_id(); $update = "UPDATE contacts SET leadID = $lastID WHERE contactID = $contactID"; $updateQuery = mysql_query($update); Everything works fine.. except that it inserts duplicate rows into the leads table. I have tried putting the update query into an if statement and it did the samething(this was just to try "something"). If I remove $lastID = mysql_insert_id(); it inserts just one row but obviously does not update the contacts table. So I am pretty sure it has to to with mysql_insert_id(). I need it to update the contacts table with the new id of the row inserted into the leads table. Any ideas would be greatly appreciated.
-
Need help with displaying data from an array.
garrickplaisted replied to garrickplaisted's topic in PHP Coding Help
Thank you Thorpe. I will look into that, I have no idea what a result resource is or should be. -
Need help with displaying data from an array.
garrickplaisted replied to garrickplaisted's topic in PHP Coding Help
Thanks for that, I appreciate it. Still trying to figure out what Thorpe sent me. Trying to research it a little more. I am fairly new to PHP and just starting to work with arrays. -
First I would like to thank anyone who takes the time to help me with this!! Ok so I have an inventory.php page that has two drops downs. The first one is Products and the Second one is Events. When you chose a selection is will display any product still in inventory along with other information specific to the transaction. So for example if I choose socks in the Products drop down, it will show me all socks still in inventory. If I choose Event 1 from the Events drop down, it will show me all products purchased at that event. When it displays the results it will also display a check mark with each set of results and the transaction id as the value of the checkbox. It also displays a Sell button, Check All and Uncheck All buttons. When the Sell button is click it the form action sends you to sell_inventory.php page. This is the page I really need help with. So on this page I need to somehow display information based on the results of the previous page. Here is the code I have for that thus far: Here is the code that echos the results for the drop down selection. This is where the checkbox is. echo "<div class='span2 well-inner'>"; echo "<input type='checkbox' class='checkbox float-right' name='sell_inv[]' value='" . $inventoryRow['transactionID'] . "'>"; echo "<strong>Product: </strong>" . $inventoryRow['product'] . "<br/>"; echo "<strong>Price: </strong>" . $inventoryRow['productPrice'] . "<br/>"; echo "<strong>Weight: </strong>" . $inventoryRow['metalWeight'] . "<br/>"; echo "<strong>Cost: </strong>$" . $inventoryRow['transactionTotal']; echo "</div>"; Here is the query that am using. $transactionsTable = "transactions"; $sell_inv = implode(',',$_POST['sell_inv']); $inventorySQL="SELECT * FROM $transactionsTable WHERE transactionID IN('$sell_inv')"; $info = array(); Here is where I am stuck. I am able to print the array out and it displays the Key with the id, but I am not sure how to display specific data tied to the id. Like the Product name. I have tried so many different things and nothing seems to work. I am going crazy!! Here is what I have currently: <?php <!--- This prints the array just fine --> echo "<pre>"; print_r ($_POST['sell_inv']); echo "</pre>"; <!-- This throws and error --> while($row=mysql_fetch_array($inventorySQL, MYSQL_ASSOC)) $info[] = $row; foreach ($info as $data){ echo $data['product']; } ?> Here is the error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /sell_inventory.php on line 78 Line 78 is: while($row=mysql_fetch_array($inventorySQL, MYSQL_ASSOC)) I need to be able to display any and all information from the database table tied to the transaction id for each transaction selected on the precious page. I hope all this makes sense and again any help would be greatly appreciated.
-
Deleting rows from MySQL using php
garrickplaisted replied to garrickplaisted's topic in PHP Coding Help
that would look something like this right $id=$_GET['id']; if(!ctype_digit($id)){ echo "It's not a digit"; } -
Deleting rows from MySQL using php
garrickplaisted replied to garrickplaisted's topic in PHP Coding Help
Thanks again. -
Deleting rows from MySQL using php
garrickplaisted replied to garrickplaisted's topic in PHP Coding Help
Thanks for that helpful tip. I guess I should validate it even though there is no input box, they could use the browser it self to inject malicious code right? -
Deleting rows from MySQL using php
garrickplaisted replied to garrickplaisted's topic in PHP Coding Help
I see it now, it wasn't so evident to me before that is why I posted the questions. Thank you all very much for your help especially mikosiko. The delete function is now working for me. -
Deleting rows from MySQL using php
garrickplaisted replied to garrickplaisted's topic in PHP Coding Help
I tried removing the die; code and received the following message: Deleted Successfully Back to Results SELECT * FROM ContactFormLog WHERE id='' Resource id #3 I used the following code: $tbl_name="ContactFormLog"; // Table name // get value of id that sent from address bar $id=$_GET['id']; // Delete data in mysql from row that has this id $query="SELECT * FROM $tbl_name WHERE id='$id'"; $result=mysql_query($query); $row = mysql_fetch_array($result); print_r($row); // if successfully deleted if($result){ echo "Deleted Successfully"; echo "<BR>"; echo "<a href='leads3.php'>Back to Results</a><br />"; echo $query . "<br />"; echo $result . "<br />"; echo $row; } else { echo "ERROR"; } -
Deleting rows from MySQL using php
garrickplaisted replied to garrickplaisted's topic in PHP Coding Help
I tried the both suggestions and on the first suggestion on the first one I used the following code: $tbl_name="ContactFormLog"; // Table name // get value of id that sent from address bar $id=$_GET['id']; // Delete data in mysql from row that has this id $query="SELECT * FROM $tbl_name WHERE id='$id'"; $result=mysql_query($query); $row = mysql_fetch_array($result); print_r($row); die; // if successfully deleted if($result){ echo "Deleted Successfully"; echo "<BR>"; echo "<a href='leads3.php'>Back to Results</a>"; } else { echo "ERROR"; } and received received no error or successfully deleted message and the rows were not deleted. On the second suggestion I used the following code: $tbl_name="ContactFormLog"; // Table name // get value of id that sent from address bar $id=$_GET['id']; // Delete data in mysql from row that has this id $query="SELECT * FROM $tbl_name WHERE id=$id"; $result=mysql_query($query); $row = mysql_fetch_array($result); print_r($row); die; // if successfully deleted if($result){ echo "Deleted Successfully"; echo "<BR>"; echo "<a href='leads3.php'>Back to Results</a>"; } else { echo "ERROR"; } and I received the following message: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /homepages/2/d208592347/htdocs/websitemorph/LGF/admin/remove_rec2.php on line 64. Again I appreciate everyone's help on this, it's driving me crazy trying to figure this out. -
Deleting rows from MySQL using php
garrickplaisted replied to garrickplaisted's topic in PHP Coding Help
Thank you so much for your time on this. Ok so I did as you suggessted and it still didn't work. On the database I made the "id field" with lowercase letters. Below is my current code with the changes I made. Code for the Query to get the data from the database and for displaying the results in a table: //GET DATA $sql = "SELECT * FROM `".$tblname."` ORDER BY $orderby $sort LIMIT $startrow,$limit"; $result = mysql_query($sql) or die(mysql_error()); $count=mysql_num_rows($result); //START TABLE AND TABLE HEADER echo "<table style='font-size:9.5px;'>\n<tr><th>Delete</th>"; $array = mysql_fetch_assoc($result); foreach ($array as $key=>$value) { if($config['nicefields']){ $field = str_replace("_"," ",$key); $field = ucwords($field); } $field = columnSortArrows($key,$field,$orderby,$sort); echo "<th>" . $field . "</th>\n"; } echo "</tr>\n"; //reset result pointer mysql_data_seek($result,0); //start first row style $tr_class = "class='odd'"; //LOOP TABLE ROWS while($row = mysql_fetch_assoc($result)){ $id = $row['id']; echo "<tr ".$tr_class.">\n<td><a href='remove_rec2.php?id=". $rows['id'] . "'><p>Delete</p></a>"; echo "</td>"; foreach ($row as $field=>$value) { echo "<td>" . $value . "</td>\n"; } echo "</tr>\n"; //switch row style if($tr_class == "class='odd'"){ $tr_class = "class='even'"; }else{ $tr_class = "class='odd'"; } } //END TABLE echo "</table>\n"; Here is the code that should delete the row: $tbl_name="ContactFormLog"; // Table name // get value of id that sent from address bar $id=$_GET['id']; // Delete data in mysql from row that has this id $sql=sprintf("DELETE FROM $tbl_name WHERE id='$id'"); $result=mysql_query($sql); // if successfully deleted if($result){ echo "Deleted Successfully"; echo "<BR>"; echo "<a href='leads3.php'>Back to Results</a>"; } else { echo "ERROR"; } I am not sure if having to echo it out is what is causing the issue or not. Again I really appreciate anyone and everyone's help on this. -
Deleting rows from MySQL using php
garrickplaisted replied to garrickplaisted's topic in PHP Coding Help
When I echo $result I receive the following message: DELETE FROM ContactFormLog WHERE ID=''1 So it is getting the right ID number but why is the other " not there? I'm so cunfused, lol Ok regarless of which one I choose to delete is gives me the same ID="1. I also used the following for the query thinking that it would help : $sql=sprintf("DELETE FROM $tblname WHERE ID='$id'"); -
Deleting rows from MySQL using php
garrickplaisted replied to garrickplaisted's topic in PHP Coding Help
When I echo $result I receive the following message: DELETE FROM ContactFormLog WHERE ID=''1 So it is getting the right ID number but why is the other " not there? I'm so cunfused, lol -
Deleting rows from MySQL using php
garrickplaisted replied to garrickplaisted's topic in PHP Coding Help
First off thanks for the reply. Here is what I did. I echoed $sql ( the Query ) and recieved the following message: DELETE FROM ContactFormLog WHERE ID='' I assume that it's not pulling the ID number as I hoped it would, any ideas?