Jump to content

Recommended Posts

just an update, this file first does loop through my DB first and grabs some basic data and display it.  So There for I am pretty sure I am not having the issue with the database connection.  It's just not pulling the information when the id is in the URL.  Here is my updated code

 



<html>
<body>

<?php

require_once('./config.php');

$db = mysql_connect($dblocation, $dbname, $dbpw) or die (mysql_error ("Cannot Link"));
mysql_select_db ($dbname, $db) or die (mysql_error ("Cannot Select DB"));

if ($submit) {

  // here if no ID then adding else we're editing

  if ($id) {

    $sql = "UPDATE artistinfo SET artist_realname='$artist_realname',artist_birthday='$artist_birthday',artist_hometown='$artist_hometown',artist_soundclick='$artist_soundclick',artist_myspace='$artist_myspace',artist_email='$artist_email',artist_bio='$artist_bio' WHERE user_id=$id";

  } else {

    $sql = "INSERT INTO artistinfo (artist_realname,artist_birthday,artist_hometown,artist_soundclick,artist_myspace,artist_email,artist_bio) VALUES ('$artist_realname','$artist_birthday','$artist_hometown','$artist_soundclickname','$artist_myspace','$artist_email','$artist_bio')";

  }

  // run SQL against the DB

  $result = mysql_query($sql);

  echo "Record updated/edited!<p>";

} elseif ($delete) {

// delete a record

    $sql = "DELETE FROM artistinfo WHERE user_id=$id";	

    $result = mysql_query($sql);

    echo "$sql Record deleted!<p>";

} else {

  // this part happens if we don't press submit

  if (!$id) {

    // print the list if there is not editing

    $result = mysql_query("SELECT * FROM artistinfo",$db);

    while ($myrow = mysql_fetch_array($result)) {

      printf("<a href=\"%s?id=%s\">%s %s</a> \n", $PHP_SELF, $myrow["user_id"], $myrow["artist_realname"], $myrow["artist_hometown"]);

  printf("<a href=\"%s?id=%s&delete=yes\">(DELETE)</a><br>", $PHP_SELF, $myrow["user_id"]);

    }

  }

  ?>
  
   <P>

  <a href="<?php echo $PHP_SELF?>">ADD A RECORD</a>
<form method="post" action="<?php echo $PHP_SELF?>">

  <p>
    <?php



  if ($id) {

    // editing so select a record

    $sql = "SELECT * FROM artistinfo WHERE user_id=$id";

    $result = mysql_query($sql);

    $myrow = mysql_fetch_array($result);

$id = $myrow["user_id"];
    $artist_realname = $myrow["artist_realname"];
    $artist_birthday = $myrow["artist_birthday"];
    $artist_hometown = $myrow["artist_hometown"];
    $artist_soundclick = $myrow["artist_soundclick"];
    $artist_myspace = $myrow["artist_myspace"];
$artist_email = $myrow["artist_email"];
$artist_bio = $myrow["artist_bio"];

    // print the id for editing

    ?>

    <input type=hidden name="id" value="<?php echo $id ?>">

    <?php

  }



  ?>

  Real Name:
  <input type="Text" name="first" value="<?php echo $artist_realname ?>">
  <br>

  Birthday:
  <input type="Text" name="last" value="<?php echo $artist_birthday ?>">
  <br>

  Hometown:
  <input type="Text" name="address" value="<?php echo $artist_hometown ?>">
  <br>

  Soundclick:
  <input type="Text" name="position" value="<?php echo $artist_soundclick ?>">
  <br>

  Myspace:
  <input type="Text" name="position" value="<?php echo $artist_myspace ?>">
  <br>
  
  Email:
  <input type="Text" name="position" value="<?php echo $artist_email ?>">
  <br>
  
  Bio:
  <textarea name="position" rows="5"><?php echo $artist_bio ?></textarea>
  <br>
  
  <input type="Submit" name="submit" value="Update Information">
  </p>
  </form>



<?php



}



?>



</body>

</html>

 

I'm sure it has to be something real little and stupid.  When the script pulls the info from the DB it should be a link.  Then when you click the name it pulls its supposed to bring up the rest of the mysql information into the form so that I can update it.  However its not pulling into the form and I just can't get why lol.  Thanks for the help again.

Link to comment
https://forums.phpfreaks.com/topic/84094-mysql-edit-help/
Share on other sites

you have Register Globals Off (which is a good thing) but means a little more work..

you could add

 

extract($_GET);

extract($_POST);

to the start..

or do it correctly (see snip below)

 

<html>
<body>

<?php
//************ you could add
//extact($_GET);
//extract($_POST);
//commented out coz i dislike it 

require_once('./config.php');

$db = mysql_connect($dblocation, $dbname, $dbpw) or die (mysql_error ("Cannot Link"));
mysql_select_db ($dbname, $db) or die (mysql_error ("Cannot Select DB"));

if ($submit) {

  // here if no ID then adding else we're editing
//************ $id isn't set.. so Set it
$id = $_GET['id'];
  if ($id) {

//************ $artist_realname isn't set
$artist_realname = $_POST['artist_realname'];
//************ $artist_birthdayisn't set
$artist_birthday= $_POST['artist_birthday'];
//************ ETC ETC

    $sql = "UPDATE artistinfo SET artist_realname='$artist_realname',artist_birthday='$artist_birthday',artist_hometown='$artist_hometown',artist_soundclick='$artist_soundclick',artist_myspace='$artist_myspace',artist_email='$artist_email',artist_bio='$artist_bio' WHERE user_id=$id";

  } else {

    $sql = "INSERT INTO artistinfo (artist_realname,artist_birthday,artist_hometown,artist_soundclick,artist_myspace,artist_email,artist_bio) VALUES ('$artist_realname','$artist_birthday','$artist_hometown','$artist_soundclickname','$artist_myspace','$artist_email','$artist_bio')";

  }
?>

 

Used ************  to highlight my comments

 

 

EDIT: i mean extract not extact LOL

Link to comment
https://forums.phpfreaks.com/topic/84094-mysql-edit-help/#findComment-428062
Share on other sites

Well your form use POST.. in truth i assumed your ID was Via Get but it also looks like a POST but i don't know your site as well as you would..

 

  <a href="<?php echo $PHP_SELF?>">ADD A RECORD</a>
<form method="post" action="<?php echo $PHP_SELF?>">

Link to comment
https://forums.phpfreaks.com/topic/84094-mysql-edit-help/#findComment-428069
Share on other sites

Yea, the way I did it was for the form to be blank and give me a list of the users already in the db.  Then when I click on the user it brings up I want it to populate the data into the form so that I can update.  I followed a tutorial I had found online and tried adapting it to my database and use and I must of completely missed something.  What else could it be?

Link to comment
https://forums.phpfreaks.com/topic/84094-mysql-edit-help/#findComment-428073
Share on other sites

Ok so I set the id using the get and I also did the declaring of the variables.  Here is the code now.  Still not working.

 


<html>
<body>

<?php

require_once('./config.php');

$db = mysql_connect($dblocation, $dbname, $dbpw) or die (mysql_error ("Cannot Link"));
mysql_select_db ($dbname, $db) or die (mysql_error ("Cannot Select DB"));

if ($submit) {

  // here if no ID then adding else we're 
$id = $_GET['id'];

  if ($id) {

$artist_realname = $_POST['artist_realname'];
$artist_birthday = $_POST['artist_birthday'];
$artist_hometown = $_POST['artist_hometown'];
$artist_soundclick = $_POST['artist_soundclick'];
$artist_myspace = $_POST['artist_myspace'];
$artist_email = $_POST['artist_email'];
$artist_bio = $_POST['artist_bio'];

    $sql = "UPDATE artistinfo SET artist_realname='$artist_realname',artist_birthday='$artist_birthday',artist_hometown='$artist_hometown',artist_soundclick='$artist_soundclick',artist_myspace='$artist_myspace',artist_email='$artist_email',artist_bio='$artist_bio' WHERE user_id=$id";

  } else {

    $sql = "INSERT INTO artistinfo (artist_realname,artist_birthday,artist_hometown,artist_soundclick,artist_myspace,artist_email,artist_bio) VALUES ('$artist_realname','$artist_birthday','$artist_hometown','$artist_soundclickname','$artist_myspace','$artist_email','$artist_bio')";

  }

  // run SQL against the DB

  $result = mysql_query($sql);

  echo "Record updated/edited!<p>";

} elseif ($delete) {

// delete a record

    $sql = "DELETE FROM artistinfo WHERE user_id=$id";	

    $result = mysql_query($sql);

    echo "$sql Record deleted!<p>";

} else {

  // this part happens if we don't press submit

  if (!$id) {

    // print the list if there is not editing

    $result = mysql_query("SELECT * FROM artistinfo",$db);

    while ($myrow = mysql_fetch_array($result)) {

      printf("<a href=\"%s?id=%s\">%s %s</a> \n", $PHP_SELF, $myrow["user_id"], $myrow["artist_realname"], $myrow["artist_hometown"]);

  printf("<a href=\"%s?id=%s&delete=yes\">(DELETE)</a><br>", $PHP_SELF, $myrow["user_id"]);

    }

  }

  ?>
  
   <P>

  <a href="<?php echo $PHP_SELF?>">ADD A RECORD</a>
<form method="post" action="<?php echo $PHP_SELF?>">

  <p>
    <?php



  if ($id) {

    // editing so select a record

    $sql = "SELECT * FROM artistinfo WHERE user_id=$id";

    $result = mysql_query($sql);

    $myrow = mysql_fetch_array($result);

$id = $myrow["user_id"];
    $artist_realname = $myrow["artist_realname"];
    $artist_birthday = $myrow["artist_birthday"];
    $artist_hometown = $myrow["artist_hometown"];
    $artist_soundclick = $myrow["artist_soundclick"];
    $artist_myspace = $myrow["artist_myspace"];
$artist_email = $myrow["artist_email"];
$artist_bio = $myrow["artist_bio"];

    // print the id for editing

    ?>

    <input type=hidden name="user_id" value="<?php echo $id ?>">

    <?php

  }



  ?>

  Real Name:
  <input type="Text" name="first" value="<?php echo $artist_realname ?>">
  <br>

  Birthday:
  <input type="Text" name="last" value="<?php echo $artist_birthday ?>">
  <br>

  Hometown:
  <input type="Text" name="address" value="<?php echo $artist_hometown ?>">
  <br>

  Soundclick:
  <input type="Text" name="position" value="<?php echo $artist_soundclick ?>">
  <br>

  Myspace:
  <input type="Text" name="position" value="<?php echo $artist_myspace ?>">
  <br>
  
  Email:
  <input type="Text" name="position" value="<?php echo $artist_email ?>">
  <br>
  
  Bio:
  <textarea name="position" rows="5"><?php echo $artist_bio ?></textarea>
  <br>
  
  <input type="Submit" name="submit" value="Update Information">
  </p>
  </form>



<?php



}



?>



</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/84094-mysql-edit-help/#findComment-428142
Share on other sites

Well your form use POST.. in truth i assumed your ID was Via Get but it also looks like a POST but i don't know your site as well as you would..

 

Still not working.

 

Need more info !!

 

as a guess try

changing

$id = $_GET['id'];

 

 

to

$id = $_POST['id'];

Link to comment
https://forums.phpfreaks.com/topic/84094-mysql-edit-help/#findComment-428152
Share on other sites

Ok i changed it still no go.  I already created a php page that will pull the information from the site.  That page is here http://deathentertainment.com/artist.php?user_id=1 and it pulls all the information.  Basically i'm trying to create this kinda product type thing. Basically its a artist database for indie labels. The artist can log in and change there BIO, there myspace links, soundclick links, upload cd images and mp3s. I already have it where its pulling the bio from a mysql database and the cd images from a folder.  The edit page can be found at http://deathentertainment.com/edit.php if you would like to see.  I'm guessing I don't need it to be pulling all that other information that it does right now but it was in the tutorial and I was using it to make sure I was connecting to my DB.  Once I get this working I wanna create a login page for it so they can log in.  Thanks for your help its greatly appreciated.

Link to comment
https://forums.phpfreaks.com/topic/84094-mysql-edit-help/#findComment-428161
Share on other sites

Okay i had a closer look and theirs a few problems

 

try this a few bug fixes

<html>
<body>

<?php

require_once('./config.php');

$db = mysql_connect($dblocation, $dbname, $dbpw) or die (mysql_error ("Cannot Link"));
mysql_select_db ($dbname, $db) or die (mysql_error ("Cannot Select DB"));

$id = (int)$_GET['ID'];

if (isset($_POST['submit']))
{
// here if no ID then adding else we're 
if ($_POST['id'] > 0)
{
	$id = (int)$_POST['id'];
	$artist_realname = $_POST['artist_realname'];
	$artist_birthday = $_POST['artist_birthday'];
	$artist_hometown = $_POST['artist_hometown'];
	$artist_soundclick = $_POST['artist_soundclick'];
	$artist_myspace = $_POST['artist_myspace'];
	$artist_email = $_POST['artist_email'];
	$artist_bio = $_POST['artist_bio'];

    $sql = "UPDATE artistinfo SET artist_realname='$artist_realname',artist_birthday='$artist_birthday',artist_hometown='$artist_hometown',artist_soundclick='$artist_soundclick',artist_myspace='$artist_myspace',artist_email='$artist_email',artist_bio='$artist_bio' WHERE user_id=$id";
}else{
    $sql = "INSERT INTO artistinfo (artist_realname,artist_birthday,artist_hometown,artist_soundclick,artist_myspace,artist_email,artist_bio) VALUES ('$artist_realname','$artist_birthday','$artist_hometown','$artist_soundclickname','$artist_myspace','$artist_email','$artist_bio')";
}

  // run SQL against the DB

  $result = mysql_query($sql);

  echo "Record updated/edited!<p>";

} elseif ($_GET['delete']) {

// delete a record

    $sql = "DELETE FROM artistinfo WHERE user_id=$id";	

    $result = mysql_query($sql);

    echo "$sql Record deleted!<p>";

} else {

  // this part happens if we don't press submit

  if ($id == 0) {

    // print the list if there is not editing

    $result = mysql_query("SELECT * FROM artistinfo",$db);

    while ($myrow = mysql_fetch_array($result)) {

      printf("<a href=\"%s?id=%s\">%s %s</a> \n", $PHP_SELF, $myrow["user_id"], $myrow["artist_realname"], $myrow["artist_hometown"]);

  printf("<a href=\"%s?id=%s&delete=yes\">(DELETE)</a><br>", $PHP_SELF, $myrow["user_id"]);

    }

  }

  ?>
  
   <P>

  <a href="<?php echo $PHP_SELF?>">ADD A RECORD</a>
<form method="post" action="<?php echo $PHP_SELF?>">

  <p>
    <?php



  if ($id > 0)
  {

    // editing so select a record

    $sql = "SELECT * FROM artistinfo WHERE user_id=$id";

    $result = mysql_query($sql);

    $myrow = mysql_fetch_array($result);

$id = $myrow["user_id"];
    $artist_realname = $myrow["artist_realname"];
    $artist_birthday = $myrow["artist_birthday"];
    $artist_hometown = $myrow["artist_hometown"];
    $artist_soundclick = $myrow["artist_soundclick"];
    $artist_myspace = $myrow["artist_myspace"];
$artist_email = $myrow["artist_email"];
$artist_bio = $myrow["artist_bio"];

    // print the id for editing

    ?>

    <input type=hidden name="id" value="<?php echo $id ?>">

    <?php

  }



  ?>

  Real Name:
  <input type="Text" name="first" value="<?php echo $artist_realname ?>">
  <br>

  Birthday:
  <input type="Text" name="last" value="<?php echo $artist_birthday ?>">
  <br>

  Hometown:
  <input type="Text" name="address" value="<?php echo $artist_hometown ?>">
  <br>

  Soundclick:
  <input type="Text" name="position" value="<?php echo $artist_soundclick ?>">
  <br>

  Myspace:
  <input type="Text" name="position" value="<?php echo $artist_myspace ?>">
  <br>
  
  Email:
  <input type="Text" name="position" value="<?php echo $artist_email ?>">
  <br>
  
  Bio:
  <textarea name="position" rows="5"><?php echo $artist_bio ?></textarea>
  <br>
  
  <input type="Submit" name="submit" value="Update Information">
  </p>
  </form>



<?php



}



?>



</body>

</html>

 

**untested

Link to comment
https://forums.phpfreaks.com/topic/84094-mysql-edit-help/#findComment-428186
Share on other sites

Hey, still unfortunately didnt work.  Question is most of this file just extra work seeing as this is going to be a page that will have to be logged in and depending on who logs in the id will then be placed into the URL?  Like no need for this deleting and showing the users that are in the DB.  I think if so this could be a lot easier.  and for right now just manually type in the URL

Link to comment
https://forums.phpfreaks.com/topic/84094-mysql-edit-help/#findComment-428753
Share on other sites

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.