Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9257081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:07:00+00:00 2026-06-18T12:07:00+00:00

I have a simple form that I am passing data from to a php

  • 0

I have a simple form that I am passing data from to a php page using session variables. I have two functions in an external function page, but I cannot get the variables in each function to work globally unless I name the variable in each particular function.

Here is an example that I am hoping someone can help with.

$dbName = $_SESSION['dataBaseName'];    
$tableName = $_SESSION['tableName'];
$artistName = $_SESSION['artistName'];
$songName = $_SESSION['songName']; 

function table_exists($tableName)
{

if(mysql_num_rows(mysql_query("SHOW TABLES LIKE '".$tableName."'"))==1) 
{
echo "Table exists <br />";
}
else
{
$sql = "CREATE TABLE songList (songId int NOT NULL AUTO_INCREMENT PRIMARY KEY, artistName varchar(60), songName varchar(25))";
$result= mysql_query($sql) or die(mysql_error());
return $result;
}   
}

In my OTHER function I put the variables INSIDE the function. Doesnt seem to matter what combo I use, my variables have to be REDECLARED every function I use. I tried using GLOBAL in front but that just causes an error. Here is the other function:

function tableWrite() 

{

$dbName = $_SESSION['dataBaseName'];    
$tableName = $_SESSION['tableName'];
$artist = $_SESSION['artist'];
$song = $_SESSION['song']; 


 if(!empty($_REQUEST['insert']))
 {
  $sql = "INSERT INTO $tableName (artistName, songName) values ('$artist', '$song')";
  $result = mysql_query($sql) or die(mysql_error());
  $showaresult = mysql_query("SELECT * from $tableName where artistName = '$artist' AND songName= '$song' ") or die("Invalid query: " . mysql_error());
  echo ("New entry added"); 

  $row = mysql_fetch_array($showaresult);
  echo ("<br> Catalog Number = ". $row["songId"] . "<br> Artist Name =  " . $row["artistName"] . "<br>");
  echo("Song Name = " . $row["songName"] . "<br>");

  echo ("<h1> Current Catalog </h1>");

  $showresult = mysql_query("SELECT * from $tableName") or die("Invalid query: " . mysql_error());
  while ($row = mysql_fetch_array($showresult))
  {
   echo ("<br> Catalog Number = ". $row["songId"] . "<br> Artist Name =  " .    $row["artistName"] . "<br>");
  echo("Song Name = " . $row["songName"] . "<br>");

  }

  }
  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:07:00+00:00Added an answer on June 18, 2026 at 12:07 pm

    You should put those database access variables in a different php file (maybe db_config.php?). You can then use a require directive in files where you need the values of said variables.

    Also, don’t use mysql_* functions. They have been deprecated in favor of PDO or MySQLi. This will help you write better code and prevent SQL injection vunerabilities.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So i have a simple form that takes a few inputs (two text and
I have simple php validation form that is halfway working. If you leave the
I have a simple html form that looks like the following <form action=search.php method=get>
I have a simple feedback form PHP script that I would like to enhance
I have an html/jsp form that I am serializing(using jquery) and passing to a
I have a simple form that looks like this: <%= simple_form_for @study,:url => studies_path,
I have a simple form that looks like so <% remote_form_for post, :url =>
I have a simple form that searches through the 2000+ issues of a 3rd
I currently have a simple form that when you click the save button will
I'm creating a form. As of right now I have simple MAILTO form that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.