Jump to content

Two queries on a page


cavey5

Recommended Posts

I have an INSERT that puts values into mt database, and a variable, a userid, is created by auto increment. Is it possible to do the insert, and then immediatly do a SELECT on the same page, to pull that userid out? What I have is echoing an empty variable, any advise? Why does this echo to getsubscriber_script.php?cm_id=

 

with no value?

 

 

 

[pre]

// Aquires data source from form

$cm_company = mysql_real_escape_string($_POST['cm_company']);

$cm_email = mysql_real_escape_string($_POST['cm_email']);

 

// Inserts data into database

$addSubscriber = "INSERT INTO subscriber_data (company, email) VALUES ('$company', '$email')";

   

  $addSubscriber_result= mysql_query($addSubscriber)

  OR die('QUERY ERROR:<br />' .$addSubscriber. '<br />' .mysql_error()); 

 

// Retreives data from database

  $getDetails = "(SELECT userid FROM subscriber_data WHERE email = '$cm_email')";

 

  $getDetails_result = mysql_query($getDetails)

    OR die(mysql_error());

 

    while ($row = mysql_fetch_array($getDetails)) {

  $userid = $row["userid"];

  }

   

 

// Routes user to details

header("Location: getsubscriber_script.php?cm_id=$cm_id");

 

exit;

?>

[/pre]

Link to comment
https://forums.phpfreaks.com/topic/48370-two-queries-on-a-page/
Share on other sites

Now, how would you pass the value to the header redirect after an UPDATE, because that does not generate an auto-increment value, thus results in a value of 0. I need to redirect the user back to the Customer Details page using $_GET and the userid in the URL... but once the UPDATE has been ran, the $_GET value of $_GET['$cm_id']; seems to go null. See code and note in red.

 

[pre]

<?php

 

 

// Makes initial connection to database

 

define ('DB_USER', '***********');

define ('DB_PASSWORD', '******');

define ('DB_HOST', 'localhost');

define ('DB_NAME', '***********);

 

$connect = @mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)

  or die('215 Our database is currently down for updates, please check back later.');

// or die(mysql_error());

 

$db = @mysql_select_db(DB_NAME, $connect)

or die('216 Our database is currently down for updates, please check back later.');

 

// Aquires data source from form

 

$cm_id = mysql_real_escape_string($_POST['cm_id']);

$cm_company = mysql_real_escape_string($_POST['cm_company']);

$cm_phone = mysql_real_escape_string($_POST['cm_phone']);

$cm_email = mysql_real_escape_string($_POST['cm_email']);

$cm_firstname = mysql_real_escape_string($_POST['cm_firstname']);

$cm_lastname = mysql_real_escape_string($_POST['cm_lastname']);

$cm_address1 = mysql_real_escape_string($_POST['cm_address1']);

$cm_address2 = mysql_real_escape_string($_POST['cm_address2']);

$cm_city = mysql_real_escape_string($_POST['cm_city']);

$cm_state = mysql_real_escape_string($_POST['cm_state']);

$cm_zipcode = mysql_real_escape_string($_POST['cm_zipcode']);

$cm_country = mysql_real_escape_string($_POST['cm_country']);

$cm_subtype = mysql_real_escape_string($_POST['cm_subtype']);

$cm_source = mysql_real_escape_string($_POST['cm_source']);

$cm_payment = mysql_real_escape_string($_POST['cm_payment']);

$cm_code = mysql_real_escape_string($_POST['cm_code']);

$cm_startissue = mysql_real_escape_string($_POST['cm_startissue']);

$cm_endissue = mysql_real_escape_string($_POST['cm_endissue']);

$cm_status = mysql_real_escape_string($_POST['cm_status']);

$cm_notes = mysql_real_escape_string($_POST['cm_notes']);

 

// Updates database

 

$updateSubscriber = "UPDATE subscriber_data SET cm_company = '$cm_company', cm_phone = '$cm_phone', cm_email = '$cm_email',

cm_firstname = '$cm_firstname', cm_lastname = '$cm_lastname', cm_address1 = '$cm_address1', cm_address2 = '$cm_address2', cm_city = '$cm_city', cm_state = '$cm_state', cm_zipcode = '$cm_zipcode', cm_country = '$cm_country', cm_subtype = '$cm_subtype', cm_source = '$cm_source', cm_payment = '$cm_payment', cm_code = '$cm_code', cm_startissue = '$cm_startissue',

cm_endissue = '$cm_endissue', cm_status = '$cm_status' WHERE cm_id = '$cm_id'";

   

  $updateSubscriber_result= mysql_query($updateSubscriber)

  OR die('QUERY ERROR:<br />' .$updateSubscriber. '<br />' .mysql_error()); 

 

 

header("Location: cm_subscriber_detail.php?cm_id=$cm_id"); <-- How do I get the value of $cm_id into this string?

 

exit;

?>

 

[/pre]

Link to comment
https://forums.phpfreaks.com/topic/48370-two-queries-on-a-page/#findComment-236651
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.